comment reduxed MultipleAssignment
[nedit-bw.git] / textDisp-cursor-position.patch
blob29801158796a7c539c62d551c5c68d49fbc25306
1 From: John Ferrier <john_j_ferrier@yahoo.com>
2 Subject: [PATCH] textDisp: cursor position correction
4 One missing patch is a correction for the cursor display. Maybe it is
5 originally from Thorsten Haude or Tony, which I am not sure now. However,
6 the difference is as follows:
8 ---
10 source/textDisp.c | 37 +++++++++++++++++++++++++++++--------
11 1 file changed, 29 insertions(+), 8 deletions(-)
13 diff --quilt old/source/textDisp.c new/source/textDisp.c
14 --- old/source/textDisp.c
15 +++ new/source/textDisp.c
16 @@ -1427,7 +1427,7 @@ int TextDMoveLeft(textDisp *textD)
18 int TextDMoveUp(textDisp *textD, int absolute)
20 - int lineStartPos, column, prevLineStartPos, newPos, visLineNum;
21 + int lineStartPos, column, prevLineStartPos, newPos, visLineNum, offset = 1;
23 /* Find the position of the start of the line. Use the line starts array
24 if possible, to avoid unbounded line-counting in continuous wrap mode */
25 @@ -1448,13 +1448,24 @@ int TextDMoveUp(textDisp *textD, int abs
26 ? textD->cursorPreferredCol
27 : BufCountDispChars(textD->buffer, lineStartPos, textD->cursorPos);
29 + /* In continuous mode if the wrapping occurs at a non-whitespace character,
30 + the cursor is moved to the start of the next line, cf. TextDEndOfLine.
31 + Therefore in this rare special case the previous line is two(!) displayed
32 + lines away. */
33 + if (textD->continuousWrap) {
34 + if (column > 0 && lineStartPos == textD->cursorPos) {
35 + if (lineStartPos == TextDEndOfLine(textD, lineStartPos - 1, False))
36 + offset = 2;
37 + }
38 + }
40 /* count forward from the start of the previous line to reach the column */
41 if (absolute) {
42 prevLineStartPos = BufCountBackwardNLines(textD->buffer, lineStartPos, 1);
43 - } else if (visLineNum != -1 && visLineNum != 0) {
44 - prevLineStartPos = textD->lineStarts[visLineNum-1];
45 + } else if (visLineNum >= offset) {
46 + prevLineStartPos = textD->lineStarts[visLineNum - offset];
47 } else {
48 - prevLineStartPos = TextDCountBackwardNLines(textD, lineStartPos, 1);
49 + prevLineStartPos = TextDCountBackwardNLines(textD, lineStartPos, offset);
52 newPos = BufCountForwardDispChars(textD->buffer, prevLineStartPos, column);
53 @@ -1472,7 +1483,7 @@ int TextDMoveUp(textDisp *textD, int abs
55 int TextDMoveDown(textDisp *textD, int absolute)
57 - int lineStartPos, column, nextLineStartPos, newPos, visLineNum;
58 + int lineStartPos, column, nextLineStartPos, newPos, visLineNum, offset = 1;
60 if (textD->cursorPos == textD->buffer->length) {
61 return False;
62 @@ -1492,10 +1503,20 @@ int TextDMoveDown(textDisp *textD, int a
63 ? textD->cursorPreferredCol
64 : BufCountDispChars(textD->buffer, lineStartPos, textD->cursorPos);
66 + /* In continuous mode if the wrapping occurs at a non-whitespace character,
67 + the cursor is moved to the start of the next line, cf. TextDEndOfLine.
68 + Therefore in this rare special case we are already on the next line! */
69 + if (textD->continuousWrap) {
70 + if (column > 0 && lineStartPos == textD->cursorPos) {
71 + if (lineStartPos == TextDEndOfLine(textD, lineStartPos - 1, False))
72 + offset = 0;
73 + }
74 + }
76 if (absolute)
77 nextLineStartPos = BufCountForwardNLines(textD->buffer, lineStartPos, 1);
78 else
79 - nextLineStartPos = TextDCountForwardNLines(textD, lineStartPos, 1, True);
80 + nextLineStartPos = TextDCountForwardNLines(textD, lineStartPos, offset, True);
82 newPos = BufCountForwardDispChars(textD->buffer, nextLineStartPos, column);
84 @@ -1759,7 +1780,7 @@ static void bufModifiedCB(int pos, int n
85 endDispPos = textD->continuousWrap ? wrapModEnd :
86 BufEndOfLine(buf, pos + nInserted) + 1;
87 if (origCursorPos >= startDispPos &&
88 - (origCursorPos <= endDispPos || endDispPos == buf->length))
89 + (origCursorPos <= endDispPos || endDispPos >= buf->length))
90 blankCursorProtrusions(textD);
92 /* If more than one line is inserted/deleted, a line break may have
93 @@ -3314,7 +3335,7 @@ static void blankCursorProtrusions(textD
94 width = left - x;
95 } else if (cursorX >= right - cursorWidth/2 && cursorX <= right) {
96 x = right;
97 - width = cursorX + cursorWidth/2 + 2 - right;
98 + width = cursorX + cursorWidth/2 + cursorWidth - right;
99 } else
100 return;