diff options
author | bptato <nincsnevem662@gmail.com> | 2024-01-19 01:43:46 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-01-19 01:53:28 +0100 |
commit | 3c156384bade3e0e86a837b1b423d401af3cfdd2 (patch) | |
tree | f8cd1b8e82510a0bb2ef1a02de877f00617c965e /src/utils | |
parent | 58ae65ed182a8a78d67756ec62f30261b9ef6c87 (diff) | |
download | chawan-3c156384bade3e0e86a837b1b423d401af3cfdd2.tar.gz |
Re-design word handling, add e, E, W, B, etc.
* Add functions for moving to the beginning/end of words (vi `b', `e'). * As it turns out, there are many possible interpretations of what a word is. Now we have a function for each reasonable interpretation, and the default settings match those of vi (and w3m in w3m.toml). (Exception: it's still broken on line boundaries... TODO) * Remove `bounds` from lineedit, it was horrible API design and mostly useless. In the future, an API similar to what pager now has could be added. * Update docs, and fix some spacing issues with symbols in the tables.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/strwidth.nim | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/utils/strwidth.nim b/src/utils/strwidth.nim index 32e8ca7f..5ce2ba52 100644 --- a/src/utils/strwidth.nim +++ b/src/utils/strwidth.nim @@ -2,8 +2,6 @@ import std/strutils import std/unicode import utils/proptable -import js/error -import types/opt import utils/charcategory import utils/map @@ -101,15 +99,25 @@ func padToWidth*(str: string, size: int, schar = '$'): string = func isDigitAscii(r: Rune): bool = return uint32(r) < 128 and char(r) in AsciiDigit +type BreakCategory* = enum + BREAK_ALPHA, BREAK_SPACE, BREAK_SYMBOL + func breaksWord*(r: Rune): bool = return not (r.isDigitAscii() or r.width() == 0 or r.isAlpha()) -type BoundaryFunction* = proc(x: Rune): JSResult[bool] - -proc breaksWord*(r: Rune, check: Opt[BoundaryFunction]): bool = - if check.isSome: - let f = check.get() - let v = f(r) - if v.isSome: #TODO report error? - return v.get() - return r.breaksWord() +func breaksViWordCat*(r: Rune): BreakCategory = + if r.isWhiteSpace(): + return BREAK_SPACE + elif r.breaksWord(): + return BREAK_SYMBOL + return BREAK_ALPHA + +func breaksWordCat*(r: Rune): BreakCategory = + if not r.breaksWord(): + return BREAK_ALPHA + return BREAK_SPACE + +func breaksBigWordCat*(r: Rune): BreakCategory = + if not r.isWhiteSpace(): + return BREAK_ALPHA + return BREAK_SPACE |