diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-11-10 22:56:17 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-11-10 22:59:59 +0300 |
commit | 2b107beffd9b408ac1464288d07ee96214c09a30 (patch) | |
tree | 45feac6e7021cfb5db1f173b04c6cd3a86ed20e0 /source/blender/editors/space_text/text_ops.c | |
parent | bd401d9517ff32b29a807143ab2b5cf89fcb286e (diff) |
Fix T39144: text-select scrolling too fast
Use a timer to get predictable speed.
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 3b3c86d6c06..5bf0100d785 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2415,6 +2415,7 @@ typedef struct SetSelection { int selecting; int selc, sell; short old[2]; + wmTimer *timer; /* needed for scrolling when mouse at region bounds */ } SetSelection; static int flatten_width(SpaceText *st, const char *str) @@ -2629,6 +2630,29 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, con if (!sel) txt_pop_sel(text); } +static void text_cursor_timer_ensure(bContext *C, SetSelection *ssel) +{ + if (ssel->timer == NULL) { + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); + + ssel->timer = WM_event_add_timer(wm, win, TIMER, 0.02f); + } +} + +static void text_cursor_timer_remove(bContext *C, SetSelection *ssel) +{ + if (ssel->timer) { + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); + + WM_event_remove_timer(wm, win, ssel->timer); + } + ssel->timer = NULL; +} + + + static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event) { SpaceText *st = CTX_wm_space_text(C); @@ -2636,32 +2660,34 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev SetSelection *ssel = op->customdata; if (event->mval[1] < 0 || event->mval[1] > ar->winy) { - int d = (ssel->old[1] - event->mval[1]) * st->pix_per_line; - if (d) txt_screen_skip(st, ar, d); + text_cursor_timer_ensure(C, ssel); - text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1] < 0 ? 0 : ar->winy, 1); - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + if (event->type == TIMER) { + text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1); + text_scroll_to_cursor(st, ar, false); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + } } else if (!st->wordwrap && (event->mval[0] < 0 || event->mval[0] > ar->winx)) { - if (event->mval[0] > ar->winx) st->left++; - else if (event->mval[0] < 0 && st->left > 0) st->left--; - - text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1); + text_cursor_timer_ensure(C, ssel); - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); - // XXX PIL_sleep_ms(10); + if (event->type == TIMER) { + text_cursor_set_to_pos(st, ar, CLAMPIS(event->mval[0], 0, ar->winx), event->mval[1], 1); + text_scroll_to_cursor(st, ar, false); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + } } else { - text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1); + text_cursor_timer_remove(C, ssel); - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + if (event->type != TIMER) { + text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1); + text_scroll_to_cursor(st, ar, false); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); - ssel->old[0] = event->mval[0]; - ssel->old[1] = event->mval[1]; + ssel->old[0] = event->mval[0]; + ssel->old[1] = event->mval[1]; + } } } @@ -2681,6 +2707,7 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op) text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + text_cursor_timer_remove(C, ssel); MEM_freeN(ssel); } @@ -2717,6 +2744,7 @@ static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent * case RIGHTMOUSE: text_cursor_set_exit(C, op); return OPERATOR_FINISHED; + case TIMER: case MOUSEMOVE: text_cursor_set_apply(C, op, event); break; |