Notepad2e icon indicating copy to clipboard operation
Notepad2e copied to clipboard

Always select closest word

Open ProgerXP opened this issue 6 years ago • 10 comments
trafficstars

This is likely a Scintilla feature.

Document with two lines (| indicate cursor positions):

|  aa bb
|  'aa bb

Place cursor at line 1, Ctrl+Space - aa will be selected. This is good.

Place cursor at line 2, Ctrl+Space - the entire line will be selected. This is bad - it should behave as line 1, i.e. locate the closest word by right-scanning and then select it. For selecting a line there is Ctrl+Shift+Space hotkey.

In other words, for both lines selection should be the same.

ProgerXP avatar Dec 25 '18 11:12 ProgerXP

Place cursor at line 1, Space - aa will be selected. This is good.

Cannot reproduce. Press on Space-key should insert whitespace character (0x20) and will move whole line to the right. I can't get how it may affect current document selection. Please provide your INI file and animation GIF (if possible).

cshnik avatar Dec 25 '18 18:12 cshnik

Sorry, I entirely missed the modifier - it's a hotkey, thus it's Ctrl+Space for "select word" (and Ctrl+Shift+Space for "select line").

ProgerXP avatar Dec 25 '18 19:12 ProgerXP

Fixed.

cshnik avatar Dec 25 '18 20:12 cshnik

Extend this behaviour so that it works left-side too. Document:

aa bb ' |

Ctrl+Space currently selects the entire line. Instead, make it select closest left-side word (bb), or if there's none - do nothing. Make it the same for right-side scanning (in the first post in this issue), i.e. when there is no close word - do nothing, do not select the line.

Ctrl+Space will never select a complete line after this change.

ProgerXP avatar Sep 26 '20 19:09 ProgerXP

Fixed.

cshnik avatar Oct 12 '20 17:10 cshnik

Document:

Press Ctrl+Space - the program hangs.

ProgerXP avatar Nov 14 '20 17:11 ProgerXP

Fixed.

cshnik avatar Nov 17 '20 19:11 cshnik

48300c9 introduced a subtile change: Ctrl+Space no longer selects word on the next line. Consider this document:

first
|
third

Ctrl+Space used to select third, now it selects nothing. Adjust implementation to allow right-scanning over newlines (it's okay to have a hardcoded limit on this, like 10000 bytes/characters).

After this, Ctrl+Space still won't select anything for this document:

first
|

But it will select third for this:

|
third

ProgerXP avatar Aug 04 '21 18:08 ProgerXP

Fixed. No right-scanning text limit is required since algorithm uses Scintilla`s standard SCI_WORDENDPOSITION-message.

cshnik avatar Sep 08 '22 16:09 cshnik

Must skip non-word symbols in the same way as implemented for the same-line selection:

|
// foo

Result:


// [foo]

Additionally, trying next line should be done only if there is no word on the same line:

a.|
b

Currently, Ctrl+Space selects [b] but it should select [a].

ProgerXP avatar Sep 09 '22 09:09 ProgerXP

Fixed.

cshnik avatar Oct 30 '22 22:10 cshnik

Memo: as it was coded, in absence of any word on the left (on the same line) and on the right until EOF it moves caret to before the first column on the last non-empty line:

.|
.

.          <- to here: |.

ProgerXP avatar Nov 10 '22 13:11 ProgerXP

Place cursor at line 2, Ctrl+Space - the entire line will be selected. This is bad - it should behave as line 1, i.e. locate the closest word by right-scanning and then select it. For selecting a line there is Ctrl+Shift+Space hotkey.

As it was implemented by 48300c9ef8818a04869c1deb5807514eb188f4b5 https://github.com/ProgerXP/Notepad2e/issues/205#issuecomment-699536336, when there is a selection Ctrl+Space does nothing (keeps that selection). Adjust it so that it pretends selection is empty and selects the closest word near the cursor (i.e. start or end of the selection depending on caret location). If there's no word, selection is unchanged (as currently), else the word is selected (which may be the same selection or intersect with it).

For example: a[a a|]a - Ctrl+Space: aa [aa|] - Ctrl+Space: aa [aa|] (same).

Another: a[|a a]a or a|a aa or |aa aa or aa| aa - Ctrl+Space (and subsequent): [aa|] aa.

One case when this is more useful than the current behaviour is doing a Find on a word's part in order to change it (e.g. change case) - currently you have to press arrow left or right to clear the located selection, then Ctrl+Space.

ProgerXP avatar Nov 20 '22 08:11 ProgerXP

Done.

cshnik avatar Nov 23 '22 06:11 cshnik

[|
aa]

Currently, pressing Ctrl+Space clears the selection. Pressing it again selects [aa]. It should select that on the first keystroke.

ProgerXP avatar Nov 28 '22 10:11 ProgerXP

Fixed.

cshnik avatar Nov 28 '22 17:11 cshnik