text selection on large files #41919

Closed
opened 2014-09-23 13:50:45 +02:00 by Cezary Kopias · 9 comments

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

**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
Author

Changed status to: 'Open'

Changed status to: 'Open'
Campbell Barton was assigned by Cezary Kopias 2014-09-23 13:50:45 +02:00
Author

Added subscriber: @kopias

Added subscriber: @kopias

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

  • Word wrap.
  • Syntax highlighting.
  • Draw line numbers.
Are any of these settings enabled? - and does changing them make any difference? - Word wrap. - Syntax highlighting. - Draw line numbers.
Author

tryed any combination of those settings its always the same

tryed any combination of those settings its always the same

Added subscriber: @mont29

Added subscriber: @mont29

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.

P163: possible fix for #4191

diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 3b3c86d..4ad10f4 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 dragging outside the text area */
 } SetSelection;
 
 static int flatten_width(SpaceText *st, const char *str)
@@ -2634,25 +2635,57 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
 	SpaceText *st = CTX_wm_space_text(C);
 	ARegion *ar = CTX_wm_region(C);
 	SetSelection *ssel = op->customdata;
+	int delta;
+	const int line_step = (st->lheight_dpi + TXT_LINE_SPACING);
 
-	if (event->mval- [x] < 0 || event->mval- [x] > ar->winy) {
-		int d = (ssel->old- [x] - event->mval- [x]) * st->pix_per_line;
-		if (d) txt_screen_skip(st, ar, d);
+	if (((delta = (event->mval- [x] - line_step)) < 0) ||
+	    ((delta = (event->mval- [x] - ar->winy))  > 0))
+	{
 
-		text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x] < 0 ? 0 : ar->winy, 1);
+		if (abs(delta) > st->pix_per_line) {
+			delta /= st->pix_per_line;
+		}
+		else {
+			delta = (delta > 0) ? 1 : -1;
+		}
 
-		text_update_cursor_moved(C);
-		WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
+		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.05f);
+		}
+
+		if (event->type == TIMER) {
+			/* so wiggling the mouse doesn't speedup scrolling */
+			txt_screen_skip(st, ar, -delta);
+
+			text_cursor_set_to_pos(st, ar, event->mval- [x], (delta < 0) ?
+			                       line_step :
+			                       ar->winy - line_step, 1);
+
+			text_update_cursor_moved(C);
+			WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
+		}
 	}
 	else if (!st->wordwrap && (event->mval- [x] < 0 || event->mval- [x] > ar->winx)) {
-		if (event->mval- [x] > ar->winx) st->left++;
-		else if (event->mval- [x] < 0 && st->left > 0) st->left--;
 		
-		text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x], 1);
-		
-		text_update_cursor_moved(C);
-		WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
-		// XXX PIL_sleep_ms(10);
+		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.05f);
+		}
+
+		if (event->type == TIMER) {
+			if (event->mval- [x] > ar->winx) st->left++;
+			else if (event->mval- [x] < 0 && st->left > 0) st->left--;
+
+			text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x], 1);
+
+			text_update_cursor_moved(C);
+			WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
+		}
 	}
 	else {
 		text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x], 1);
@@ -2667,6 +2700,8 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
 
 static void text_cursor_set_exit(bContext *C, wmOperator *op)
 {
+	wmWindowManager *wm = CTX_wm_manager(C);
+	wmWindow *win = CTX_wm_window(C);
 	SpaceText *st = CTX_wm_space_text(C);
 	Text *text = st->text;
 	SetSelection *ssel = op->customdata;
@@ -2678,6 +2713,10 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
 		MEM_freeN(buffer);
 	}
 
+	if (ssel->timer) {
+		WM_event_remove_timer(wm, win, ssel->timer);
+	}
+
 	text_update_cursor_moved(C);
 	WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
 
@@ -2718,6 +2757,7 @@ static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent *
 			text_cursor_set_exit(C, op);
 			return OPERATOR_FINISHED;
 		case MOUSEMOVE:
+		case TIMER:
 			text_cursor_set_apply(C, op, event);
 			break;
 	}

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. [P163: possible fix for #4191](https://archive.blender.org/developer/P163.txt) ```diff diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 3b3c86d..4ad10f4 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 dragging outside the text area */ } SetSelection; static int flatten_width(SpaceText *st, const char *str) @@ -2634,25 +2635,57 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev SpaceText *st = CTX_wm_space_text(C); ARegion *ar = CTX_wm_region(C); SetSelection *ssel = op->customdata; + int delta; + const int line_step = (st->lheight_dpi + TXT_LINE_SPACING); - if (event->mval- [x] < 0 || event->mval- [x] > ar->winy) { - int d = (ssel->old- [x] - event->mval- [x]) * st->pix_per_line; - if (d) txt_screen_skip(st, ar, d); + if (((delta = (event->mval- [x] - line_step)) < 0) || + ((delta = (event->mval- [x] - ar->winy)) > 0)) + { - text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x] < 0 ? 0 : ar->winy, 1); + if (abs(delta) > st->pix_per_line) { + delta /= st->pix_per_line; + } + else { + delta = (delta > 0) ? 1 : -1; + } - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + 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.05f); + } + + if (event->type == TIMER) { + /* so wiggling the mouse doesn't speedup scrolling */ + txt_screen_skip(st, ar, -delta); + + text_cursor_set_to_pos(st, ar, event->mval- [x], (delta < 0) ? + line_step : + ar->winy - line_step, 1); + + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + } } else if (!st->wordwrap && (event->mval- [x] < 0 || event->mval- [x] > ar->winx)) { - if (event->mval- [x] > ar->winx) st->left++; - else if (event->mval- [x] < 0 && st->left > 0) st->left--; - text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x], 1); - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); - // XXX PIL_sleep_ms(10); + 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.05f); + } + + if (event->type == TIMER) { + if (event->mval- [x] > ar->winx) st->left++; + else if (event->mval- [x] < 0 && st->left > 0) st->left--; + + text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x], 1); + + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); + } } else { text_cursor_set_to_pos(st, ar, event->mval- [x], event->mval- [x], 1); @@ -2667,6 +2700,8 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev static void text_cursor_set_exit(bContext *C, wmOperator *op) { + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); SpaceText *st = CTX_wm_space_text(C); Text *text = st->text; SetSelection *ssel = op->customdata; @@ -2678,6 +2713,10 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op) MEM_freeN(buffer); } + if (ssel->timer) { + WM_event_remove_timer(wm, win, ssel->timer); + } + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text); @@ -2718,6 +2757,7 @@ static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent * text_cursor_set_exit(C, op); return OPERATOR_FINISHED; case MOUSEMOVE: + case TIMER: text_cursor_set_apply(C, op, event); break; } ```
Set as TODO: http://wiki.blender.org/index.php/Dev:2.5/Source/Development/Todo/Editors#Text_Editor

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Fixed 2b107beffd

Fixed 2b107beffd
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#41919
No description provided.