SkipWord

interface SkipWord

When you hold Ctrl and press the Left or Right arrow keys, it jumps by 1 word. However, what is considered a word isn't clear, and can depend on the context.

For example, to a programmer, a word is an identifier, which can have numbers as well as digits. So foo42 is a word.

In a natural language context, a word may be anything which doesn't contain whitespace.

Each of my implementations have an option preSkipWhitespace, which defaults to true. Pretty much every text editor I've used pre-skips whitespace, and I hate it! IMHO, skipping forwards should be symmetrical with skipping backwards, with the downside, that whitespace is considered a word! Therefore, it takes an extra key-press to skip it. But I can type faster than I can think. I don't want to think about where the editor is going to jump to next, I want it to be simple and symmetric (i.e. the same caret positions are used going forwards and backwards). If I overshoot, then hitting the other arrow key should correct it.

This is NOT the case when preSkipWhitespace = true. When using the left arrow, the caret only visits the start of each word, and when using the right arrow, it only visits the end of each word. IMHO, this sucks, but I assume I'm an outlier, because that's the default (or only option) in every text editor I've seen.

I'm going to stick with convention - Glok does it the way I hate!

The default algorithm is forProgrammers (preSkipWhitespace=true)

To change TextField's behaviour, set instance to byWhiteSpaceOnly, letterDigitOther or forProgrammers.

Inheritors

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun backwards(position: Int, text: CharSequence): Int
Link copied to clipboard
abstract fun forwards(position: Int, text: CharSequence): Int
Link copied to clipboard
abstract fun selectWord(position: Int, text: CharSequence): Pair<Int, Int>