TIP 686: Make NextWord/SelectNextWord behavior platform-independant

Login
Author:		Jan Nijtmans <[email protected]>
State:		Final
Type:		Project
Vote:		Done
Created:	29-1-2024
Tcl-Version:	8.7
Tk-Branch:	tip-686
Vote-Summary:  3 / 0 / 0
Votes-For:     FV, JN, SL
Votes-Against: none
Votes-Present: none

Abstract

The virtual events <<NextWord>>/<<SelectNextWord>> currently behave in a platform-dependent way. On Windows, invoking those events, the insert cursor will move to the beginning of the next word. On UNIX, those events will make the insert cursor move to the end of the current word, but - if the cursor is already at the end of a word - it will jump to the end of the next word.

This TIP proposes the make this behavior platform-independent: <<NextWord>> will move to the beginning of the next word. <<SelectNextWord>> will extend the selection to the end of the current word (or the next one, if the current position is already at the end of the current word)

Rationale

The current behavior for <<NextWord>> is not 'logical' on UNIX: In stead of jumping to the next word it actually jumps to the end of the current word. When traversing words, the behavior on Windows is more logical: There it actually moves the insert cursor to the beginning of the next word.

The current behavior for <<SelectNextWord>> is not 'logical' on Windows. If you want to select a range of text, the normal way to do this is use <<NextWord>> to move to the word you want to begin selecting. Then use <<SelectNextWord>> if you want to select a single word, use <<SelectNextWord>> again if you want two words, and so on. Doing this, will result in the spacing after the words being included in the selection as well: You need to press <<SelectPrevChar>> (eventually multiple times if there is more than one space). On UNIX, this use-case works as expected.

This proposal is the same as currently implemented in notepad++. It's a compromise between the original Windows and the original UNIX behavior. But then (contrary to most compromises) a compromise which takes the best of both worlds.

So, let 'W' mean: including the spaces after the word and 'U' not including those spaces. Then, let's compare with other editors/viewers:

|   editor       |<<NextWord>>|<<SelectNextWord>>|
| -------------- | ---------- | ---------------- |
|Tk 8.6 (windows)|     W      |        W         |
|Tk 8.6 (UNIX)   |     U      |        U         |
|TIP #686        |     W      |        U         |
|notepad++       |     W      |        U         |
|word/wordpad    |     W      |        W         |
|nedit (UNIX)    |     W      |        W         |
|gedit           |     U      |        U         |
|Adobe Acrobat   |     U      |        U         |

Most editors take either the Windows approach, either the UNIX approach. Notepad++ is the only editor I found which takes the compromise approach, as in this TIP.

Nedit takes the Windows approach, even though it is running on UNIX. Adobe Acrobat reader takes the UNIX approach, even though it's running on Windows.

Implementation

Implementation is in Tk branch "tip-686".

Copyright

This document has been placed in the public domain.