WIP: VFONT: Text Object Word Selection #107519

Closed
Harley Acheson wants to merge 2 commits from Harley:TextWordSelect into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Corrections to allow better cursor keyboard movement and selection by
word and mouse word selection by double-clicking.


Corrections to selection of word boundaries when inserting the text cursor, selecting words with keyboard and with the mouse. With this PR applied the following works as expected:

Moving the text cursor a word at time backward (ctrl-left arrow) will generally move directly from the front of one word to the front of the previous word. Similarly pressing ctrl-right arrow will move directly from the end of one word to the end of the next word. Even if the word is only one character long.

However if the text cursor is placed at the end of a word, pressing ctrl-left will move to the beginning of that same word. Pressing ctrl-right will move to the end of a word if you start from the beginning. Even if the word is only a single character long.

Holding shift while using ctrl-left or ctrl-right will select a word at a time.

Double-clicking on a word will select that word even if you click on the space between words. So clicking on the right-side of the space before a word will select that word. And similarly for the end of the word. Even if the word is a single character long, starting or ending the sentence, etc.

Corrections to allow better cursor keyboard movement and selection by word and mouse word selection by double-clicking. ---- Corrections to selection of word boundaries when inserting the text cursor, selecting words with keyboard and with the mouse. With this PR applied the following works as expected: Moving the text cursor a word at time backward (ctrl-left arrow) will generally move directly from the front of one word to the front of the previous word. Similarly pressing ctrl-right arrow will move directly from the end of one word to the end of the next word. Even if the word is only one character long. However if the text cursor is placed at the end of a word, pressing ctrl-left will move to the beginning of that same word. Pressing ctrl-right will move to the end of a word if you start from the beginning. Even if the word is only a single character long. Holding shift while using ctrl-left or ctrl-right will select a word at a time. Double-clicking on a word will select that word even if you click on the space between words. So clicking on the right-side of the space before a word will select that word. And similarly for the end of the word. Even if the word is a single character long, starting or ending the sentence, etc.
Harley Acheson added 1 commit 2023-05-02 00:08:46 +02:00
ad02f4757d VFONT: Text Object Word Selection
Corrections to allow better cursor keyboard movement and selection by
word and mouse word selection by double-clicking.
Harley Acheson requested review from Campbell Barton 2023-05-02 00:08:55 +02:00
Harley Acheson added this to the User Interface project 2023-05-02 00:09:03 +02:00

This makes Ctrl-Arrow key cursor motion fail when stepping over multiple spaces (the cursor stops early).
It should be possible to fix this without changing move_cursor at all.

It should be enough not to step forward/back if there is immediately before/after the cursor, the initial single character forward step also doesn't seem necessary.

Checking how firefox responds to double-clicking on whitespace, it moves the cursor backwards and select the word behind the cursor (not essential for the fix, but seems a reasonable default).

This makes Ctrl-Arrow key cursor motion fail when stepping over multiple spaces (the cursor stops early). It should be possible to fix this without changing `move_cursor` at all. It should be enough not to step forward/back if there is immediately before/after the cursor, the initial single character forward step also doesn't seem necessary. Checking how firefox responds to double-clicking on whitespace, it moves the cursor backwards and select the word behind the cursor (not essential for the fix, but seems a reasonable default).
Harley Acheson added 1 commit 2023-05-07 23:34:32 +02:00
Author
Member

@ideasman42 - It should be possible to fix this without changing move_cursor at all.

Not really because there are errors built into that function with its use of use_init_step for BLI_str_cursor_step_utf32.

If you start with an older version of Blender, like 3.5, before we started mucking around. Ctrl-arrow movement seems to work mostly okay but there are errors. If starting at either side of a single-character word it will move one character too far.

Similarly if your cursor is between the second and third character of a word, pressing ctrl-left will move to the beginning of the word. But if between the first and second character hitting ctrl-left will move to the end of the previous word. The same thing happens if just before the last character of a word, versus the second-to-last, and pressing ctrl-right.

It should be enough not to step forward/back if there is immediately before/after the cursor...

I updated this PR with a font_select_word_exec that is probably the kind of simple thing you are expecting, while only having minimal changes to move_cursor that I am hoping make sense. PREV_WORD and NEXT_WORD are just changed not do that init_step in most cases.

> @ideasman42 - It should be possible to fix this without changing move_cursor at all. Not really because there are errors built into that function with its use of `use_init_step` for `BLI_str_cursor_step_utf32`. If you start with an older version of Blender, like 3.5, before we started mucking around. Ctrl-arrow movement _seems_ to work mostly okay but there are errors. If starting at either side of a single-character word it will move one character too far. Similarly if your cursor is between the second and third character of a word, pressing ctrl-left will move to the beginning of the word. But if between the first and second character hitting ctrl-left will move to the end of the previous word. The same thing happens if just before the last character of a word, versus the second-to-last, and pressing ctrl-right. > It should be enough not to step forward/back if there is immediately before/after the cursor... I updated this PR with a `font_select_word_exec` that is probably the kind of simple thing you are expecting, while only having minimal changes to `move_cursor` that I am hoping make sense. PREV_WORD and NEXT_WORD are just changed not do that init_step in most cases.

@ideasman42 - It should be possible to fix this without changing move_cursor at all.

Not really because there are errors built into that function with its use of use_init_step for BLI_str_cursor_step_utf32.

If your proposing functionality changes I rather this be handled separately, the behavior your pointing out is matched in the text-editor, python-console & text fields.

The logic is that Ctrl motion that would take a single step, always step over that character (as there is no need to hold Ctrl if a single character needed to be stepped over). Changing this may be fine but it's a separate matter.

It might be simplest not to use word stepping logic and instead and check the white space directly.

> > @ideasman42 - It should be possible to fix this without changing move_cursor at all. > > Not really because there are errors built into that function with its use of `use_init_step` for `BLI_str_cursor_step_utf32`. If your proposing functionality changes I rather this be handled separately, the behavior your pointing out is matched in the text-editor, python-console & text fields. The logic is that Ctrl motion that would take a single step, always step over that character (as there is no need to hold Ctrl if a single character needed to be stepped over). Changing this may be fine but it's a separate matter. It might be simplest not to use word stepping logic and instead and check the white space directly.
Author
Member

If your proposing functionality changes I rather this be handled separately, the behavior your pointing out is matched in the text-editor, python-console & text fields.

Yes, it is the same behavior all over. Following shows where the cursor goes when using Ctrl-Arrows. The incorrect move shown in red happens everywhere.

WordBoundary1.png

It also result in this kind of behavior around one-letter words:

WordBoundary2.gif

This all just comes from that use_init_step happening all the time, doing that initial one-character move without any testing. We always call BLI_str_cursor_step_utf8 and BLI_str_cursor_step_utf32 with that set true.

So fixing it is messy. But I'll post a PR that we can stare at and maybe think about how it could be less messy.

> If your proposing functionality changes I rather this be handled separately, the behavior your pointing out is matched in the text-editor, python-console & text fields. Yes, it is the same behavior all over. Following shows where the cursor goes when using Ctrl-Arrows. The incorrect move shown in red happens everywhere. ![WordBoundary1.png](/attachments/2f015dbe-18b5-4862-bb7a-04df48391d34) It also result in this kind of behavior around one-letter words: ![WordBoundary2.gif](/attachments/d221ed90-8aae-4743-94d5-aeef76a7d294) This all just comes from that use_init_step happening all the time, doing that initial one-character move without any testing. We always call `BLI_str_cursor_step_utf8` and `BLI_str_cursor_step_utf32` with that set true. So fixing it is messy. But I'll post a PR that we can stare at and maybe think about how it could be less messy.
Harley Acheson changed title from VFONT: Text Object Word Selection to WIP: VFONT: Text Object Word Selection 2023-05-08 22:01:07 +02:00
Harley Acheson closed this pull request 2023-05-15 22:56:13 +02:00
Harley Acheson deleted branch TextWordSelect 2023-05-15 22:56:22 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
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#107519
No description provided.