UI: Console Text Operations #108626

Manually merged
Campbell Barton merged 13 commits from Harley/blender:ConsoleSelect into main 2023-09-22 05:42:35 +02:00
Member

Adds the ability to set text cursor position in the Console editor
by clicking with the mouse and many other expected operations.


There are currently quite a few deficiencies in the expected text behavior with Console. This PR adds setting text cursor by mouse click, Shift-arrows, ctrl-shift-arrows, shift-home, shift-end. deletion & movement while there is a selection, ctrl-A to select all. Cut to clipboard. Copying into a selection. Default and IC keymaps. Double-clicking on a word sets cursor position, etc.

ConsoleSelect.gif

Adds the ability to set text cursor position in the Console editor by clicking with the mouse and many other expected operations. --- There are currently quite a few deficiencies in the expected text behavior with Console. This PR adds setting text cursor by mouse click, Shift-arrows, ctrl-shift-arrows, shift-home, shift-end. deletion & movement while there is a selection, ctrl-A to select all. Cut to clipboard. Copying into a selection. Default and IC keymaps. Double-clicking on a word sets cursor position, etc. ![ConsoleSelect.gif](/attachments/eb5812f4-602b-429e-a3a0-b77987f96201)
Harley Acheson changed title from WIP: Console Text Cursor Position With Mouse to WIP: Console Text Operations 2023-06-06 01:40:19 +02:00
Harley Acheson added this to the User Interface project 2023-06-06 01:57:06 +02:00

NOTE: moved TODO's in code to: #108641.

NOTE: moved TODO's in code to: #108641.
Harley Acheson changed title from WIP: Console Text Operations to UI: Console Text Operations 2023-06-06 18:31:06 +02:00
Harley Acheson requested review from Campbell Barton 2023-06-06 18:31:32 +02:00
Campbell Barton requested changes 2023-06-07 07:39:09 +02:00
Campbell Barton left a comment
Owner

Noticed an odd issue, where dragging the selection may place the cursor if the user hovers over the prompt, dragging away may have the selection starting & ending outside the editable prompt, now with a moved cursor.

There is another issue where a selection prevents cursor motion (the first cursor motion drops the selection, the second moves), I think it's better if the cursor always moves, ignoring the selection.

In this case I think it should reset to it's original location.

Noticed an odd issue, where dragging the selection may place the cursor if the user hovers over the prompt, dragging away may have the selection starting & ending outside the editable prompt, now with a moved cursor. There is another issue where a selection prevents cursor motion (the first cursor motion drops the selection, the second moves), I think it's better if the cursor always moves, ignoring the selection. In this case I think it should reset to it's original location.
@ -1056,3 +1115,4 @@
return OPERATOR_FINISHED;
}
bool console_copy_poll(bContext *C)

Should b static.

Should b static.
Harley marked this conversation as resolved

Testing this patch, it now seems like a bug when the cursor isn't on either side of the selection (as happens in a text editor). With this change it happens in some cases and not others as it can't be ensured because selection may exist outside the editable area.

One solution could be to place the cursor on clicking but don't set the cursor position when dragging the selection, as it feels like a glitch when the selection and the cursor position get out of sync.

Testing this patch, it now seems like a bug when the cursor isn't on either side of the selection (as happens in a text editor). With this change it happens in some cases and not others as it can't be ensured because selection may exist outside the editable area. One solution could be to place the cursor on clicking but don't set the cursor position when dragging the selection, as it feels like a glitch when the selection and the cursor position get out of sync.
Author
Member

Testing this patch, it now seems like a bug when the cursor isn't on either side of the selection (as happens in a text editor). With this change it happens in some cases and not others as it can't be ensured because selection may exist outside the editable area.

Not arguing at all, just talking out loud...

The complication here is that we have a combination of editable and non-editable text, but I still want all of it to be selectable. As in I really want to keep the ability to select "bpy.context" from the history.

But... this seems to naturally allow times where a selection does not include the cursor because it is non-editable. I wouldn't want to ever not display the cursor though, because it continues to indicate where new text would be inserted. So I can highlight "bpy.context" in the read-only info, ctrl-c and then ctrl-v will go exactly where the cursor is shown. This just requires a cursor that can sometimes be outside of the selection.

There is another issue where a selection prevents cursor motion (the first cursor motion drops the selection, the second moves)

Unless we are talking about different things, this follows behavior in Blender Text Editor, UI text entry, and Windows Notepad. If you have a selection and then press left or right arrow the selection is first cleared and the cursor only moves on the second arrow key.

Of course this probably should only happen when the cursor is inside that selection, so what you probably are talking about is that it feels odd when the selection is in a non-editable area. That makes sense. I updated the PR so it only does this movement skip if there is a selection in the editable portion.

> Testing this patch, it now seems like a bug when the cursor isn't on either side of the selection (as happens in a text editor). With this change it happens in some cases and not others as it can't be ensured because selection may exist outside the editable area. Not arguing at all, just talking out loud... The complication here is that we have a combination of editable and non-editable text, but I still want all of it to be selectable. As in I really want to keep the ability to select "bpy.context" from the history. But... this seems to naturally allow times where a selection does not include the cursor because it is non-editable. I wouldn't want to ever not display the cursor though, because it continues to indicate where new text would be inserted. So I can highlight "bpy.context" in the read-only info, ctrl-c and then ctrl-v will go exactly where the cursor is shown. This just requires a cursor that can sometimes be outside of the selection. > There is another issue where a selection prevents cursor motion (the first cursor motion drops the selection, the second moves) Unless we are talking about different things, this follows behavior in Blender Text Editor, UI text entry, and Windows Notepad. If you have a selection and then press left or right arrow the selection is first cleared and the cursor only moves on the second arrow key. Of course this probably should only happen when the cursor is inside that selection, so what you probably are talking about is that it feels odd when the selection is in a non-editable area. That makes sense. I updated the PR so it only does this movement skip if there is a selection in the editable portion.
Author
Member

@ideasman42:

I made it so that the cursor is not shown if the end of the selection is outside of the editable range. This still feels fine to me and should get rid of that weirdness you felt when the cursor was shown outside of the selection:

MixedSelection.gif

I also fixed a bug so now if you select a portion that is mixed editable and not, hitting "delete" will remove the editable portion.

@ideasman42: I made it so that the cursor is **not shown** if the end of the selection is outside of the editable range. This still feels fine to me and should get rid of that weirdness you felt when the cursor was shown outside of the selection: ![MixedSelection.gif](/attachments/29e4aebe-5c77-4bec-9f09-86e9d1570f1a) I also fixed a bug so now if you select a portion that is mixed editable and not, hitting "delete" will remove the editable portion.
Harley Acheson force-pushed ConsoleSelect from dc12774a33 to d389ac0c64 2023-06-28 06:55:23 +02:00 Compare
Campbell Barton requested changes 2023-07-07 08:45:40 +02:00
Campbell Barton left a comment
Owner

Testing the patch, the cursor is vanishing when selecting text outside the text field.

Testing the patch, the cursor is vanishing when selecting text outside the text field.
@ -3073,3 +3073,3 @@
items.extend([
("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True, "repeat": True},
{"properties": [("type", 'PREVIOUS_WORD')]}),
{"properties": [("type", 'PREVIOUS_WORD'),("select", False)]}),

"select": False should be the default, there is no need to add it to the key-map.

`"select": False` should be the default, there is no need to add it to the key-map.
Harley marked this conversation as resolved
Author
Member

@ideasman42 - Testing the patch, the cursor is vanishing when selecting text outside the text field.

Chasing this down required a bit of backtracking. The idea of ever hiding the cursor is removed. The only real visible change is that when doing one type of mixed selection - starting from the editable text and then extending into the non-editable - the cursor position has to move to the start of selection. This is needed to preserve the cursor position when moving directly up. Hard to explain, but all shown in the following:

ConsoleSelect.gif

> @ideasman42 - Testing the patch, the cursor is vanishing when selecting text outside the text field. Chasing this down required a bit of backtracking. The idea of ever hiding the cursor is removed. The only real visible change is that when doing one type of mixed selection - starting from the editable text and then extending into the non-editable - the cursor position has to move to the start of selection. This is needed to preserve the cursor position when moving directly up. Hard to explain, but all shown in the following: ![ConsoleSelect.gif](/attachments/c0f76c2a-a493-4aeb-98ff-33a98c7de374)
Harley Acheson force-pushed ConsoleSelect from f89715b1d5 to fb4f6e4d2b 2023-07-14 02:05:46 +02:00 Compare
  • Is there any reason not to use Ctrl-X for cut?
  • Temporarily moving the cursor into the editable area will move the cursor, AFAICS the cursor should always stay at it's location unless either the beginning/end of the selection is in the editable area.
- Is there any reason not to use Ctrl-X for cut? - Temporarily moving the cursor into the editable area will move the cursor, AFAICS the cursor should always stay at it's location unless either the beginning/end of the selection is in the editable area.
Harley Acheson added 2 commits 2023-07-18 20:33:15 +02:00
Author
Member
  • Is there any reason not to use Ctrl-X for cut?

No, not sure what was up with that. Now Ctrl-X is Cut.

Temporarily moving the cursor into the editable area will move the cursor, AFAICS the cursor should always stay at it's location unless either the beginning/end of the selection is in the editable area.

You mean this?

ConsoleCursor.gif

Seems pretty normal to me with this circumstance of having editable and non-editable areas but all being selectable. I wouldn't want the selection to not be shown on drag. You have objected to having the cursor not at the beginning or end of selection. And I wouldn't want the cursor to snap back to where it was before the drag. And I don't like hiding the text cursor.

> - Is there any reason not to use Ctrl-X for cut? No, not sure what was up with that. Now Ctrl-X is Cut. > Temporarily moving the cursor into the editable area will move the cursor, AFAICS the cursor should always stay at it's location unless either the beginning/end of the selection is in the editable area. You mean this? ![ConsoleCursor.gif](/attachments/45166cc9-1e54-4272-ba91-06d40071c116) Seems pretty normal to me with this circumstance of having editable and non-editable areas but all being selectable. I wouldn't want the selection to not be shown on drag. You have objected to having the cursor not at the beginning or end of selection. And I wouldn't want the cursor to snap back to where it was before the drag. And I don't like hiding the text cursor.
Harley Acheson added 2 commits 2023-07-24 03:01:57 +02:00
Campbell Barton requested changes 2023-07-24 04:28:56 +02:00
Campbell Barton left a comment
Owner

Behavior in it's current state seems acceptable, I think it's probably possible to support moving the cursor with the mouse - but snapping back to the original location in the case the user moves the cursor outside the editable area (so the path traveled between two points never gives a different outcome) but also don't find it a blocking issue that the cursor is set on mouse release instead of snapping back.


Since this patch is applied, showing the console view (Shift-F4) without any interaction gives a warning:

source/blender/editors/space_console/console_draw.cc:221:33: runtime error: signed integer overflow: 2147483647 + 7 cannot be represented in type 'int'

Behavior in it's current state seems acceptable, I think it's probably possible to support moving the cursor with the mouse - but snapping back to the original location in the case the user moves the cursor outside the editable area (so the path traveled between two points never gives a different outcome) but also don't find it a blocking issue that the cursor is set on mouse release instead of snapping back. --- Since this patch is applied, showing the console view (Shift-F4) without any interaction gives a warning: `source/blender/editors/space_console/console_draw.cc:221:33: runtime error: signed integer overflow: 2147483647 + 7 cannot be represented in type 'int'`
@ -1185,2 +1284,2 @@
ED_area_tag_redraw(CTX_wm_area(C));
}
console_cursor_set_to_pos(sc, region, scu, mval, move_cursor);
ED_area_tag_redraw(CTX_wm_area(C));

Logic that only redraws when the selection was changed has been removed. I would like to keep this logic other$wise every cursor motion is redrawing unnecessarily. It shouldn't be so involved to detect changes between this and the previous state.

Logic that only redraws when the selection was changed has been removed. I would like to keep this logic other$wise every cursor motion is redrawing unnecessarily. It shouldn't be so involved to detect changes between this and the previous state.
Harley marked this conversation as resolved
Harley Acheson added 2 commits 2023-07-24 21:45:05 +02:00

Noticed pressing Home/End with a selection in the cursor area just drops the selection and doesnt move the cursor.

Noticed pressing Home/End with a selection in the cursor area just drops the selection and doesnt move the cursor.
Harley Acheson added 1 commit 2023-07-25 03:05:35 +02:00
Author
Member

@ideasman42 - Noticed pressing Home/End with a selection in the cursor area just drops the selection and doesn't move the cursor.

Thanks for noticing. Fixed!

> @ideasman42 - Noticed pressing Home/End with a selection in the cursor area just drops the selection and doesn't move the cursor. Thanks for noticing. Fixed!
Harley Acheson added 1 commit 2023-08-10 21:56:48 +02:00
Campbell Barton requested changes 2023-08-11 07:58:49 +02:00
Campbell Barton left a comment
Owner

Two issues remain:

source/blender/editors/space_console/console_draw.cc:221:33: runtime error: signed integer overflow: 2147483647 + 3 cannot be represented in type 'int'

console_delete_editable_selection does out of bounds memory access.

  • Type in one long command, then a short command (that do nothing, start with #).
  • Press up until the long command is shown.
  • Press Ctrl-A
  • Press up until the short command is shown.
  • Press Ctrl-Delete

Attached ASAN error.

Two issues remain: ``` source/blender/editors/space_console/console_draw.cc:221:33: runtime error: signed integer overflow: 2147483647 + 3 cannot be represented in type 'int' ``` `console_delete_editable_selection` does out of bounds memory access. - Type in one long command, then a short command (that do nothing, start with `#`). - Press up until the long command is shown. - Press Ctrl-A - Press up until the short command is shown. - Press Ctrl-Delete Attached ASAN error.
6.7 KiB
Harley Acheson added 2 commits 2023-08-12 01:06:05 +02:00
Author
Member

@ideasman42 - ...console_draw.cc:221:33: runtime error: signed integer overflow...

Yes, I should have noticed that those mouse position values were initialized with INT_MAX. Testing for that now.

console_delete_editable_selection does out of bounds memory access.

Thanks for those instructions. Very interesting. I'm now dealing with that as error detection, handling that now fine.

> @ideasman42 - ...console_draw.cc:221:33: runtime error: signed integer overflow... Yes, I should have noticed that those mouse position values were initialized with INT_MAX. Testing for that now. > console_delete_editable_selection does out of bounds memory access. Thanks for those instructions. Very interesting. I'm now dealing with that as error detection, handling that now fine.
Harley Acheson added 2 commits 2023-08-23 02:23:23 +02:00
Campbell Barton approved these changes 2023-09-22 05:32:56 +02:00
Campbell Barton manually merged commit 18e07098ef into main 2023-09-22 05:42:35 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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
2 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#108626
No description provided.