Page MenuHome

text selection on large files
Closed, ResolvedPublic

Description

System Information
win7x64 gtx660m

Blender Version
Broken: 2.72rc

Short description of error
if you try to select some portion via mouse drag on large file (4000lines) and you want to scroll a little when you got to the edge of text editor the scrolling speed is too fast

Exact steps for others to reproduce the error

  1. open large file in blender text editor ( for example scene_amaranth_toolset.py about 4000lines)
  2. in my case text editor shows around 40 lines
  3. try to select text around 100-200 lines via mouse ( basically more lines that can be shown so you need to scroll)

its almost imposible to scrolling while mouse drag selection

Details

Type
To Do

Event Timeline

Czarek Kopias (kopias) set Type to Bug.
Czarek Kopias (kopias) created this task.
Czarek Kopias (kopias) raised the priority of this task from to Needs Triage by Developer.
Campbell Barton (campbellbarton) triaged this task as Needs Information from User priority.Sep 23 2014, 2:16 PM

Are any of these settings enabled? - and does changing them make any difference?

  • Word wrap.
  • Syntax highlighting.
  • Draw line numbers.

tryed any combination of those settings its always the same

Bastien Montagne (mont29) raised the priority of this task from Needs Information from User to Normal.
Campbell Barton (campbellbarton) lowered the priority of this task from Normal to Confirmed, Low.Nov 10 2014, 4:31 PM

Looked into this, its infact a bit of a hassle to fix since the cursor centers in the middle of the editor because of the NC_TEXT | ND_CURSOR listener.

This fix works nicely with vertical scrolling, but not horizontal. but in general I think this could be made to work differently so its not such a hack to have it working nicely.

1diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
2index 3b3c86d..4ad10f4 100644
3--- a/source/blender/editors/space_text/text_ops.c
4+++ b/source/blender/editors/space_text/text_ops.c
5@@ -2415,6 +2415,7 @@ typedef struct SetSelection {
6 int selecting;
7 int selc, sell;
8 short old[2];
9+ wmTimer *timer; /* needed for dragging outside the text area */
10 } SetSelection;
11
12 static int flatten_width(SpaceText *st, const char *str)
13@@ -2634,25 +2635,57 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
14 SpaceText *st = CTX_wm_space_text(C);
15 ARegion *ar = CTX_wm_region(C);
16 SetSelection *ssel = op->customdata;
17+ int delta;
18+ const int line_step = (st->lheight_dpi + TXT_LINE_SPACING);
19
20- if (event->mval[1] < 0 || event->mval[1] > ar->winy) {
21- int d = (ssel->old[1] - event->mval[1]) * st->pix_per_line;
22- if (d) txt_screen_skip(st, ar, d);
23+ if (((delta = (event->mval[1] - line_step)) < 0) ||
24+ ((delta = (event->mval[1] - ar->winy)) > 0))
25+ {
26
27- text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1] < 0 ? 0 : ar->winy, 1);
28+ if (abs(delta) > st->pix_per_line) {
29+ delta /= st->pix_per_line;
30+ }
31+ else {
32+ delta = (delta > 0) ? 1 : -1;
33+ }
34
35- text_update_cursor_moved(C);
36- WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
37+ if (ssel->timer == NULL) {
38+ wmWindowManager *wm = CTX_wm_manager(C);
39+ wmWindow *win = CTX_wm_window(C);
40+
41+ ssel->timer = WM_event_add_timer(wm, win, TIMER, 0.05f);
42+ }
43+
44+ if (event->type == TIMER) {
45+ /* so wiggling the mouse doesn't speedup scrolling */
46+ txt_screen_skip(st, ar, -delta);
47+
48+ text_cursor_set_to_pos(st, ar, event->mval[0], (delta < 0) ?
49+ line_step :
50+ ar->winy - line_step, 1);
51+
52+ text_update_cursor_moved(C);
53+ WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
54+ }
55 }
56 else if (!st->wordwrap && (event->mval[0] < 0 || event->mval[0] > ar->winx)) {
57- if (event->mval[0] > ar->winx) st->left++;
58- else if (event->mval[0] < 0 && st->left > 0) st->left--;
59
60- text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1);
61-
62- text_update_cursor_moved(C);
63- WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
64- // XXX PIL_sleep_ms(10);
65+ if (ssel->timer == NULL) {
66+ wmWindowManager *wm = CTX_wm_manager(C);
67+ wmWindow *win = CTX_wm_window(C);
68+
69+ ssel->timer = WM_event_add_timer(wm, win, TIMER, 0.05f);
70+ }
71+
72+ if (event->type == TIMER) {
73+ if (event->mval[0] > ar->winx) st->left++;
74+ else if (event->mval[0] < 0 && st->left > 0) st->left--;
75+
76+ text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1);
77+
78+ text_update_cursor_moved(C);
79+ WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
80+ }
81 }
82 else {
83 text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1);
84@@ -2667,6 +2700,8 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
85
86 static void text_cursor_set_exit(bContext *C, wmOperator *op)
87 {
88+ wmWindowManager *wm = CTX_wm_manager(C);
89+ wmWindow *win = CTX_wm_window(C);
90 SpaceText *st = CTX_wm_space_text(C);
91 Text *text = st->text;
92 SetSelection *ssel = op->customdata;
93@@ -2678,6 +2713,10 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
94 MEM_freeN(buffer);
95 }
96
97+ if (ssel->timer) {
98+ WM_event_remove_timer(wm, win, ssel->timer);
99+ }
100+
101 text_update_cursor_moved(C);
102 WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
103
104@@ -2718,6 +2757,7 @@ static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent *
105 text_cursor_set_exit(C, op);
106 return OPERATOR_FINISHED;
107 case MOUSEMOVE:
108+ case TIMER:
109 text_cursor_set_apply(C, op, event);
110 break;
111 }