edit to cursor adjustment, use int rather then short to store the cursor position.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 7 Mar 2012 16:24:25 +0000 (16:24 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 7 Mar 2012 16:24:25 +0000 (16:24 +0000)
source/blender/blenkernel/intern/text.c
source/blender/blenlib/BLI_string_cursor_utf8.h
source/blender/blenlib/intern/string_cursor_utf8.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/space_console/console_ops.c

index 61c69d94d262731789187978e268b2c7fd09d8d8..6cd900c9ed20eca9744706a6ca2aff50a6c57ef2 100644 (file)
@@ -955,7 +955,7 @@ void txt_jump_left(Text *text, short sel)
        TextLine **linep, *oldl;
        int *charp, oldc, oldflags, i;
        unsigned char oldu;
-       short pos;
+       int pos;
 
        if (!text) return;
        if(sel) txt_curs_sel(text, &linep, &charp);
@@ -989,7 +989,7 @@ void txt_jump_right(Text *text, short sel)
        TextLine **linep, *oldl;
        int *charp, oldc, oldflags, i;
        unsigned char oldu;
-       short pos;
+       int pos;
 
        if (!text) return;
        if(sel) txt_curs_sel(text, &linep, &charp);
index 4bdc7f612c665ff5208af59453dd303e68cb2653..11c91aac6ac4a9abaa8170e6c2cc5d16ada5f7ca 100644 (file)
  *  \ingroup bli
  */
 
-typedef enum strCursorDelimType {
-       STRCUR_DELIM_NONE,
-       STRCUR_DELIM_ALPHA,
-       STRCUR_DELIM_PUNCT,
-       STRCUR_DELIM_BRACE,
-       STRCUR_DELIM_OPERATOR,
-       STRCUR_DELIM_QUOTE,
-       STRCUR_DELIM_WHITESPACE,
-       STRCUR_DELIM_OTHER
-} strCursorDelimType;
-
 typedef enum strCursorJumpType {
        STRCUR_JUMP_NONE,
        STRCUR_JUMP_DELIM,
@@ -52,11 +41,11 @@ typedef enum strCursorJumpDirection {
        STRCUR_DIR_NEXT
 } strCursorJumpDirection;
 
-int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, short *pos);
-int BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, short *pos);
+int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos);
+int BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, int *pos);
 
 void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
-                              short *pos, strCursorJumpDirection direction,
+                              int *pos, strCursorJumpDirection direction,
                               strCursorJumpType jump);
 
 #endif /* __BLI_STRING_CURSOR_UTF8_H__ */
index 6dc88ec00a457e57d64d48fad7b78d0c0ca0dc28..7fdeaf355145c45b05392affaf6bd2def0b8326d 100644 (file)
 
 #include "BLI_string_cursor_utf8.h" /* own include */
 
+typedef enum strCursorDelimType {
+       STRCUR_DELIM_NONE,
+       STRCUR_DELIM_ALPHA,
+       STRCUR_DELIM_PUNCT,
+       STRCUR_DELIM_BRACE,
+       STRCUR_DELIM_OPERATOR,
+       STRCUR_DELIM_QUOTE,
+       STRCUR_DELIM_WHITESPACE,
+       STRCUR_DELIM_OTHER
+} strCursorDelimType;
 
 /* return 1 if char ch is special character, otherwise return 0 */
 static strCursorDelimType test_special_char(const char ch)
@@ -100,7 +110,7 @@ static strCursorDelimType test_special_char(const char ch)
        return STRCUR_DELIM_NONE;
 }
 
-int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, short *pos)
+int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos)
 {
        const char *str_end= str + (maxlen + 1);
        const char *str_pos= str + (*pos);
@@ -114,7 +124,7 @@ int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, short *pos)
        return FALSE;
 }
 
-int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), short *pos)
+int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), int *pos)
 {
        if((*pos) > 0) {
                const char *str_pos= str + (*pos);
@@ -129,7 +139,7 @@ int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), short
 }
 
 void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
-                              short *pos, strCursorJumpDirection direction,
+                              int *pos, strCursorJumpDirection direction,
                               strCursorJumpType jump)
 {
        const short pos_prev= *pos;
index 8504677ce569a45179a463117379c0c5b8ee3974..b7c250743a940efaf4da222ebe95c24d5c5048b3 100644 (file)
@@ -1265,7 +1265,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
        
        /* mouse dragged outside the widget to the left */
        if (x < startx && but->ofs > 0) {       
-               short i= but->ofs;
+               int i = but->ofs;
 
                origstr[but->ofs] = 0;
                
@@ -1288,9 +1288,11 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
                
                /* XXX does not take zoom level into account */
                while (startx + aspect_sqrt * BLF_width(fstyle->uifont_id, origstr+but->ofs) > x) {
+                       int pos_i = but->pos;
                        if (but->pos <= 0) break;
-                       if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &but->pos)) {
-                               origstr[but->pos+but->ofs] = 0;
+                       if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &pos_i)) {
+                               but->pos = pos_i;
+                               origstr[but->pos + but->ofs] = 0;
                        }
                        else {
                                break; /* unlikely but possible */
@@ -1391,7 +1393,9 @@ static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJump
                data->selextend = 0;
        }
        else {
-               BLI_str_cursor_step_utf8(str, len, &but->pos, direction, jump);
+               int pos_i = but->pos;
+               BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump);
+               but->pos = pos_i;
 
                if(select) {
                        /* existing selection */
@@ -1457,10 +1461,10 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio
                        changed= ui_textedit_delete_selection(but, data);
                }
                else if (but->pos>=0 && but->pos<len) {
-                       short pos= but->pos;
+                       int pos = but->pos;
                        int step;
                        BLI_str_cursor_step_utf8(str, len, &pos, direction, jump);
-                       step= pos - but->pos;
+                       step = pos - but->pos;
                        memmove(&str[but->pos], &str[but->pos + step], (len + 1) - but->pos);
                        changed= 1;
                }
@@ -1471,7 +1475,7 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio
                                changed= ui_textedit_delete_selection(but, data);
                        }
                        else if(but->pos>0) {
-                               short pos= but->pos;
+                               int pos = but->pos;
                                int step;
 
                                BLI_str_cursor_step_utf8(str, len, &pos, direction, jump);
index ab1cada8f0c480d55939363cc74363419f708e84..b52bc75eac871d8fb6e7ecf7a7ddba5ad26fcdf9 100644 (file)
@@ -276,9 +276,9 @@ static int console_move_exec(bContext *C, wmOperator *op)
        
        int type= RNA_enum_get(op->ptr, "type");
        int done= 0;
-       short pos;
+       int pos;
        
-       switch(type) {
+       switch (type) {
        case LINE_BEGIN:
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,