aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-07-18 14:59:30 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2024-09-27 20:14:04 +0200
commit26895db35d4b9160ff5f2fe1f942e1ddbf58747d (patch)
tree54a821f6771edcb2de66869fb75c6eceba79cfea /editors
parent480a07bd6828285628abbbe3fe8e5e3b25ce1a92 (diff)
downloadbusybox-w32-26895db35d4b9160ff5f2fe1f942e1ddbf58747d.tar.gz
busybox-w32-26895db35d4b9160ff5f2fe1f942e1ddbf58747d.tar.bz2
busybox-w32-26895db35d4b9160ff5f2fe1f942e1ddbf58747d.zip
ed: fix line insertion before current line. Closes 15081
When text is inserted by insertLine() the lines following the insertion are moved down and the insertion point is made the new current line. To avoid too much scanning of the linked list of lines setCurNum() may use the position of the old current line to determine the location of the new current line. If the insertion point is before the old current line in the file the latter will have been moved down, so its line pointer needs to be adjusted. function old new delta insertLine 162 180 +18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 18/0) Total: 18 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/ed.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/editors/ed.c b/editors/ed.c
index 8ec23d07f..a02634ec7 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -345,6 +345,8 @@ static int insertLine(int num, const char *data, int len)
345 lp->prev->next = newLp; 345 lp->prev->next = newLp;
346 lp->prev = newLp; 346 lp->prev = newLp;
347 347
348 if (num <= curNum)
349 curLine = curLine->prev;
348 lastNum++; 350 lastNum++;
349 dirty = TRUE; 351 dirty = TRUE;
350 return setCurNum(num); 352 return setCurNum(num);