3 source/text.c | 146 +++++++++++++++++++++++++++++++++++++++++-----------------
4 1 files changed, 105 insertions(+), 41 deletions(-)
6 diff --quilt old/source/text.c new/source/text.c
9 @@ -222,14 +222,14 @@ static void simpleInsertAtCursor(Widget
10 int allowPendingDelete);
11 static int pendingSelection(Widget w);
12 static int deletePendingSelection(Widget w, XEvent *event);
13 static int deleteEmulatedTab(Widget w, XEvent *event);
14 static void selectWord(Widget w, int pointerX);
15 -static int spanForward(textBuffer *buf, int startPos, char *searchChars,
16 - int ignoreSpace, int *foundPos);
17 -static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int
18 - ignoreSpace, int *foundPos);
19 +static int spanForward(textBuffer *buf, int startPos, const char *searchChars,
20 + int ignoreSpace, int *foundPos);
21 +static int spanBackward(textBuffer *buf, int startPos, const char *searchChars,
22 + int ignoreSpace, int *foundPos);
23 static void selectLine(Widget w);
24 static int startOfWord(TextWidget w, int pos);
25 static int endOfWord(TextWidget w, int pos);
26 static void checkAutoScroll(TextWidget w, int x, int y);
27 static void endDrag(Widget w);
28 @@ -2713,69 +2713,133 @@ static void backwardWordAP(Widget w, XEv
29 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
30 checkAutoShowInsertPos(w);
31 callCursorMovementCBs(w, event);
34 +static Boolean lineIsBlank(textBuffer *buf, int pos, int *start)
36 + static const char whiteChars[] = " \t";
39 + pos = BufStartOfLine(buf, pos);
42 + while (pos < buf->length) {
43 + c = BufGetCharacter(buf, pos);
45 + /* we reached the end of a blank line */
50 + /* check for any blank character */
51 + if (NULL != strchr(whiteChars, c)) {
54 + /* this line is a not a blank line */
59 + /* no end of line and no non blank character */
63 +static Boolean nextLineIsBlank(textBuffer *buf, int pos, int *next)
65 + /* get start of next line */
66 + pos = min(BufEndOfLine(buf, pos) + 1, buf->length);
68 + if (pos == buf->length) {
69 + /* buffer without last end-of-line */
73 + return lineIsBlank(buf, pos, next);
77 +static Boolean prevLineIsBlank(textBuffer *buf, int pos, int *prev)
79 + /* get end of prev line */
80 + pos = max(BufStartOfLine(buf, pos) - 1, 0);
82 + return lineIsBlank(buf, pos, prev);
85 static void forwardParagraphAP(Widget w, XEvent *event, String *args,
89 textDisp *textD = ((TextWidget)w)->text.textD;
90 int pos, insertPos = TextDGetInsertPosition(textD);
91 textBuffer *buf = textD->buffer;
93 - static char whiteChars[] = " \t";
94 int silent = hasKey("nobell", args, nArgs);
98 + /* check if we are at the end of the file, than return */
99 if (insertPos == buf->length) {
100 ringIfNecessary(silent, w);
104 - pos = min(BufEndOfLine(buf, insertPos)+1, buf->length);
106 + /* need to skip current paragraph? */
107 + if (!lineIsBlank(buf, insertPos, &pos)) {
108 + while (pos < buf->length) {
109 + if (nextLineIsBlank(buf, pos, &pos)) {
115 + /* skip all blank lines */
116 while (pos < buf->length) {
117 - c = BufGetCharacter(buf, pos);
120 - if (strchr(whiteChars, c) != NULL)
123 - pos = min(BufEndOfLine(buf, pos)+1, buf->length);
124 + if (!nextLineIsBlank(buf, pos, &pos)) {
128 - TextDSetInsertPosition(textD, min(pos+1, buf->length));
130 + TextDSetInsertPosition(textD, min(pos, buf->length));
131 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
132 checkAutoShowInsertPos(w);
133 callCursorMovementCBs(w, event);
136 static void backwardParagraphAP(Widget w, XEvent *event, String *args,
140 textDisp *textD = ((TextWidget)w)->text.textD;
141 int parStart, pos, insertPos = TextDGetInsertPosition(textD);
142 textBuffer *buf = textD->buffer;
144 - static char whiteChars[] = " \t";
145 int silent = hasKey("nobell", args, nArgs);
149 - if (insertPos == 0) {
151 + /* check if we are at the beginning of the file, than return */
152 + if (0 == insertPos) {
153 ringIfNecessary(silent, w);
157 - parStart = BufStartOfLine(buf, max(insertPos-1, 0));
158 - pos = max(parStart - 2, 0);
160 - c = BufGetCharacter(buf, pos);
163 - if (strchr(whiteChars, c) != NULL)
166 - parStart = BufStartOfLine(buf, pos);
167 - pos = max(parStart - 2, 0);
170 + if (lineIsBlank(buf, insertPos, &parStart)
171 + || (insertPos == parStart
172 + && prevLineIsBlank(buf, parStart, &parStart))) {
173 + while (parStart > 0) {
174 + if (!prevLineIsBlank(buf, parStart, &pos)) {
181 + while (parStart > 0) {
182 + if (prevLineIsBlank(buf, parStart, &pos)) {
188 TextDSetInsertPosition(textD, parStart);
189 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
190 checkAutoShowInsertPos(w);
191 callCursorMovementCBs(w, event);
193 @@ -3695,15 +3759,15 @@ static int endOfWord(TextWidget w, int p
194 ** Search forwards in buffer "buf" for the first character NOT in
195 ** "searchChars", starting with the character "startPos", and returning the
196 ** result in "foundPos" returns True if found, False if not. If ignoreSpace
197 ** is set, then Space, Tab, and Newlines are ignored in searchChars.
199 -static int spanForward(textBuffer *buf, int startPos, char *searchChars,
200 - int ignoreSpace, int *foundPos)
201 +static int spanForward(textBuffer *buf, int startPos, const char *searchChars,
202 + int ignoreSpace, int *foundPos)
209 while (pos < buf->length) {
210 for (c=searchChars; *c!='\0'; c++)
211 if(!(ignoreSpace && (*c==' ' || *c=='\t' || *c=='\n')))
212 @@ -3723,15 +3787,15 @@ static int spanForward(textBuffer *buf,
213 ** Search backwards in buffer "buf" for the first character NOT in
214 ** "searchChars", starting with the character BEFORE "startPos", returning the
215 ** result in "foundPos" returns True if found, False if not. If ignoreSpace is
216 ** set, then Space, Tab, and Newlines are ignored in searchChars.
218 -static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int
219 - ignoreSpace, int *foundPos)
220 +static int spanBackward(textBuffer *buf, int startPos, const char *searchChars,
221 + int ignoreSpace, int *foundPos)