Fix for moving caret to the line beginning/ending when word-wrapping is enabled
[blender.git] / source / blender / editors / space_text / text_ops.c
index c594fa7acc0b2eeb055d2f6878890168b8d9d181..bcfcfd09fed720919edd5ab7740d6106f423be6a 100644 (file)
@@ -1541,6 +1541,7 @@ static void wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
                                *charp= endj;
 
                                if(j>=oldc) {
+                                       if(ch=='\0') *charp= start;
                                        loop= 0;
                                        break;
                                }
@@ -1549,10 +1550,11 @@ static void wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
 
                                start= end;
                                end += max;
-                               chop= 0;
+                               chop= 1;
                        }
                        else if(ch==' ' || ch=='-' || ch=='\0') {
                                if(j>=oldc) {
+                                       *charp= start;
                                        loop= 0;
                                        break;
                                }
@@ -1603,17 +1605,18 @@ static void wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
 
                while(chars--) {
                        if(i-start>=max) {
+                               if(chop) endj= j-1;
+
                                if(endj>=oldc) {
-                                       *charp= endj;
+                                       if(ch=='\0') *charp= (*linep)->len;
+                                       else *charp= endj;
                                        loop= 0;
                                        break;
                                }
 
-                               if(chop) endj= j;
-
                                start= end;
                                end += max;
-                               chop= 0;
+                               chop= 1;
                        } else if(ch=='\0') {
                                *charp= (*linep)->len;
                                loop= 0;