Text space fixes:
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 18 Feb 2011 14:55:42 +0000 (14:55 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 18 Feb 2011 14:55:42 +0000 (14:55 +0000)
- Bring back cursor set to PRESS event - block selection wouldn't
  have correct start position;
- Undo stack push was missed in cursor_set operator;
- Remove unneeded cursor moving at set_selection operator;
- Fixed bug with scroll bar - it shouldn't use EVT_TWEAK;

There could be still small issues with selecting single character by
mouse (due to EVT_TWEAK threashold), but this operator is for block
selection, not single char. So shouldn't be big pain here.

source/blender/editors/space_text/space_text.c
source/blender/editors/space_text/text_ops.c

index 3a9b8924eed9c2803050df525dbbcd941f758d12..6607a4019190b8043f6750de87593771b5a81aef 100644 (file)
@@ -344,9 +344,9 @@ static void text_keymap(struct wmKeyConfig *keyconf)
 
        WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", EVT_TWEAK_L, KM_ANY, 0, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "TEXT_OT_selection_set", EVT_TWEAK_L, KM_ANY, 0, 0);
-       WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_CLICK, 0, 0);
+       WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
        RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
        RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
        RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
index 55f560e6b3d896030b0c46aa81df41bb7cc91a3d..d8cbe93012dd33ddd5a9e13fd14b3600bc89fd5a 100644 (file)
@@ -2546,7 +2546,6 @@ static void set_cursor_exit(bContext *C, wmOperator *op)
 static int set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        SpaceText *st= CTX_wm_space_text(C);
-       ARegion *ar= CTX_wm_region(C);
        SetSelection *ssel;
 
        op->customdata= MEM_callocN(sizeof(SetSelection), "SetCursor");
@@ -2556,20 +2555,6 @@ static int set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event)
        ssel->old[0]= event->mval[0];
        ssel->old[1]= event->mval[1];
 
-       if(!ssel->selecting) {
-               int curl= txt_get_span(st->text->lines.first, st->text->curl);
-               int curc= st->text->curc;                       
-               int linep2, charp2;
-                                       
-               set_cursor_to_pos(st, ar, event->mval[0], event->mval[1], 0);
-
-               linep2= txt_get_span(st->text->lines.first, st->text->curl);
-               charp2= st->text->selc;
-                               
-               if(curl!=linep2 || curc!=charp2)
-                       txt_undo_add_toop(st->text, UNDO_CTO, curl, curc, linep2, charp2);
-       }
-
        ssel->sell= txt_get_span(st->text->lines.first, st->text->sell);
        ssel->selc= st->text->selc;
 
@@ -2624,20 +2609,32 @@ void TEXT_OT_selection_set(wmOperatorType *ot)
 static int set_cursor_exec(bContext *C, wmOperator *op)
 {
        SpaceText *st= CTX_wm_space_text(C);
+       Text *text= st->text;
        ARegion *ar= CTX_wm_region(C);
        int x= RNA_int_get(op->ptr, "x");
        int y= RNA_int_get(op->ptr, "y");
+       int oldl, oldc;
+
+       oldl= txt_get_span(text->lines.first, text->curl);
+       oldc= text->curc;
 
        set_cursor_to_pos(st, ar, x, y, 0);
 
+       txt_undo_add_toop(text, UNDO_CTO, oldl, oldc, txt_get_span(text->lines.first, text->curl), text->curc);
+
        text_update_cursor_moved(C);
        WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
 
-       return OPERATOR_FINISHED;
+       return OPERATOR_PASS_THROUGH;
 }
 
 static int set_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       SpaceText *st= CTX_wm_space_text(C);
+
+       if(event->mval[0]>=st->txtbar.xmin)
+               return OPERATOR_PASS_THROUGH;
+
        RNA_int_set(op->ptr, "x", event->mval[0]);
        RNA_int_set(op->ptr, "y", event->mval[1]);