fix for double clicking in the text editor not working usefully (double clicking...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 14 Feb 2013 03:03:12 +0000 (03:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 14 Feb 2013 03:03:12 +0000 (03:03 +0000)
source/blender/blenkernel/BKE_text.h
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
source/blender/editors/space_text/text_ops.c

index dc84bc67647f38b7627a7caf915d5cfd3c395f9f..3e882a048eb82bc11633bef27d8d8b3688754f58 100644 (file)
@@ -66,8 +66,8 @@ void  txt_move_up                     (struct Text *text, short sel);
 void   txt_move_down           (struct Text *text, short sel);
 void   txt_move_left           (struct Text *text, short sel);
 void   txt_move_right          (struct Text *text, short sel);
-void   txt_jump_left           (struct Text *text, short sel);
-void   txt_jump_right          (struct Text *text, short sel);
+void   txt_jump_left           (struct Text *text, bool sel, bool use_init_step);
+void   txt_jump_right          (struct Text *text, bool sel, bool use_init_step);
 void   txt_move_bof            (struct Text *text, short sel);
 void   txt_move_eof            (struct Text *text, short sel);
 void   txt_move_bol            (struct Text *text, short sel);
index 3be9097ce82db6a2f118c7c5c4180b57f2832e3b..86e7a152a4ad6b1a70043de28a57e796ea0ee7dd 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 #include "BLI_string_cursor_utf8.h"
 #include "BLI_string_utf8.h"
 #include "BLI_listbase.h"
-#include "BLI_utildefines.h"
 #include "BLI_fileops.h"
 
 #include "DNA_constraint_types.h"
@@ -936,7 +936,7 @@ void txt_move_right(Text *text, short sel)
        if (!sel) txt_pop_sel(text);
 }
 
-void txt_jump_left(Text *text, short sel)
+void txt_jump_left(Text *text, bool sel, bool use_init_step)
 {
        TextLine **linep;
        int *charp;
@@ -948,12 +948,12 @@ void txt_jump_left(Text *text, short sel)
 
        BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
                                 charp, STRCUR_DIR_PREV,
-                                STRCUR_JUMP_DELIM);
+                                STRCUR_JUMP_DELIM, use_init_step);
        
        if (!sel) txt_pop_sel(text);
 }
 
-void txt_jump_right(Text *text, short sel)
+void txt_jump_right(Text *text, bool sel, bool use_init_step)
 {
        TextLine **linep;
        int *charp;
@@ -965,7 +965,7 @@ void txt_jump_right(Text *text, short sel)
        
        BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
                                 charp, STRCUR_DIR_NEXT,
-                                STRCUR_JUMP_DELIM);
+                                STRCUR_JUMP_DELIM, use_init_step);
        
        if (!sel) txt_pop_sel(text);
 }
@@ -2402,7 +2402,7 @@ void txt_delete_char(Text *text)
 
 void txt_delete_word(Text *text)
 {
-       txt_jump_right(text, 1);
+       txt_jump_right(text, true, true);
        txt_delete_sel(text);
 }
 
@@ -2451,7 +2451,7 @@ void txt_backspace_char(Text *text)
 
 void txt_backspace_word(Text *text)
 {
-       txt_jump_left(text, 1);
+       txt_jump_left(text, true, true);
        txt_delete_sel(text);
 }
 
index 3c38c0380e05297defea9254432bd4a121013bcf..04d9df2abda9b8db5a9c81d0427ae3a2329a70df 100644 (file)
@@ -46,6 +46,6 @@ 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,
                               int *pos, strCursorJumpDirection direction,
-                              strCursorJumpType jump);
+                              strCursorJumpType jump, bool use_init_step);
 
 #endif /* __BLI_STRING_CURSOR_UTF8_H__ */
index 65763f21b0f228f7168a7908ac317c50d89dc9a7..b8797855f17a3b2e955d22e4863b747bd2330780 100644 (file)
@@ -139,12 +139,15 @@ int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), int *p
 
 void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
                               int *pos, strCursorJumpDirection direction,
-                              strCursorJumpType jump)
+                              strCursorJumpType jump, bool use_init_step)
 {
        const int pos_prev = *pos;
 
        if (direction == STRCUR_DIR_NEXT) {
-               BLI_str_cursor_step_next_utf8(str, maxlen, pos);
+               if (use_init_step) {
+                       BLI_assert(jump == STRCUR_JUMP_DELIM);
+                       BLI_str_cursor_step_next_utf8(str, maxlen, pos);
+               }
 
                if (jump != STRCUR_JUMP_NONE) {
                        const strCursorDelimType delim_type = (*pos) < maxlen ? cursor_delim_type(&str[*pos]) : STRCUR_DELIM_NONE;
@@ -163,7 +166,10 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
                }
        }
        else if (direction == STRCUR_DIR_PREV) {
-               BLI_str_cursor_step_prev_utf8(str, maxlen, pos);
+               if (use_init_step) {
+                       BLI_assert(jump == STRCUR_JUMP_DELIM);
+                       BLI_str_cursor_step_prev_utf8(str, maxlen, pos);
+               }
 
                if (jump != STRCUR_JUMP_NONE) {
                        const strCursorDelimType delim_type = (*pos) > 1 ? cursor_delim_type(&str[(*pos) - 1]) : STRCUR_DELIM_NONE;
index edd5b901ca1802cf0b70278e06839eccf90bcf57..b166e532f844f7347fab212364ab4a27b437b0d4 100644 (file)
@@ -1610,7 +1610,7 @@ static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJump
        }
        else {
                int pos_i = but->pos;
-               BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump);
+               BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump, true);
                but->pos = pos_i;
 
                if (select) {
@@ -1679,7 +1679,7 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio
                else if (but->pos >= 0 && but->pos < len) {
                        int pos = but->pos;
                        int step;
-                       BLI_str_cursor_step_utf8(str, len, &pos, direction, jump);
+                       BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true);
                        step = pos - but->pos;
                        memmove(&str[but->pos], &str[but->pos + step], (len + 1) - but->pos);
                        changed = 1;
@@ -1694,7 +1694,7 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio
                                int pos = but->pos;
                                int step;
 
-                               BLI_str_cursor_step_utf8(str, len, &pos, direction, jump);
+                               BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true);
                                step = but->pos - pos;
                                memmove(&str[but->pos - step], &str[but->pos], (len + 1) - but->pos);
                                but->pos -= step;
index 5eed39a120e63f677038bda4ab5e6f30b668abd0..1242d123a41fe0d6d789ca5c79c2fb98bc545d60 100644 (file)
 
 #include "DNA_userdef_types.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_listbase.h"
 #include "BLI_string_cursor_utf8.h"
 #include "BLI_string_utf8.h"
 #include "BLI_string.h"
 #include "BLI_dynstr.h"
-#include "BLI_utildefines.h"
 #include "BLI_math.h"
 
 #include "BKE_context.h"
@@ -284,28 +284,28 @@ static int console_move_exec(bContext *C, wmOperator *op)
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                 &pos, STRCUR_DIR_PREV,
-                                                STRCUR_JUMP_ALL);
+                                                STRCUR_JUMP_ALL, true);
                        done = console_line_cursor_set(ci, pos);
                        break;
                case LINE_END:
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                 &pos, STRCUR_DIR_NEXT,
-                                                STRCUR_JUMP_ALL);
+                                                STRCUR_JUMP_ALL, true);
                        done = console_line_cursor_set(ci, pos);
                        break;
                case PREV_CHAR:
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                 &pos, STRCUR_DIR_PREV,
-                                                STRCUR_JUMP_NONE);
+                                                STRCUR_JUMP_NONE, true);
                        done = console_line_cursor_set(ci, pos);
                        break;
                case NEXT_CHAR:
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                 &pos, STRCUR_DIR_NEXT,
-                                                STRCUR_JUMP_NONE);
+                                                STRCUR_JUMP_NONE, true);
                        done = console_line_cursor_set(ci, pos);
                        break;
 
@@ -315,14 +315,14 @@ static int console_move_exec(bContext *C, wmOperator *op)
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                 &pos, STRCUR_DIR_PREV,
-                                                STRCUR_JUMP_DELIM);
+                                                STRCUR_JUMP_DELIM, true);
                        done = console_line_cursor_set(ci, pos);
                        break;
                case NEXT_WORD:
                        pos = ci->cursor;
                        BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                 &pos, STRCUR_DIR_NEXT,
-                                                STRCUR_JUMP_DELIM);
+                                                STRCUR_JUMP_DELIM, true);
                        done = console_line_cursor_set(ci, pos);
                        break;
        }
@@ -562,7 +562,7 @@ static int console_delete_exec(bContext *C, wmOperator *op)
                                pos = ci->cursor;
                                BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                         &pos, STRCUR_DIR_NEXT,
-                                                        (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM);
+                                                        (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
                                stride = pos - ci->cursor;
                                if (stride) {
                                        memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - ci->cursor) + 1);
@@ -578,7 +578,7 @@ static int console_delete_exec(bContext *C, wmOperator *op)
                                pos = ci->cursor;
                                BLI_str_cursor_step_utf8(ci->line, ci->len,
                                                         &pos, STRCUR_DIR_PREV,
-                                                        (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM);
+                                                        (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
                                stride = ci->cursor - pos;
                                if (stride) {
                                        ci->cursor -= stride; /* same as above */
index 1f209f90007ef9924050d38ee3834cd37822240f..b60528bcee88b1613c3a924af0751c7d63fda073 100644 (file)
@@ -1312,9 +1312,11 @@ void TEXT_OT_select_line(wmOperatorType *ot)
 static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Text *text = CTX_data_edit_text(C);
+       /* don't advance cursor before stepping */
+       const bool use_init_step = false;
 
-       txt_jump_left(text, 0);
-       txt_jump_right(text, 1);
+       txt_jump_left(text, false, use_init_step);
+       txt_jump_right(text, true, use_init_step);
 
        text_update_cursor_moved(C);
        WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@@ -1816,11 +1818,11 @@ static int text_move_cursor(bContext *C, int type, int select)
                        break;
 
                case PREV_WORD:
-                       txt_jump_left(text, select);
+                       txt_jump_left(text, select, true);
                        break;
 
                case NEXT_WORD:
-                       txt_jump_right(text, select);
+                       txt_jump_right(text, select, true);
                        break;
 
                case PREV_CHAR: