diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-12-22 18:32:10 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-12-22 18:32:10 +0100 |
| commit | c45502f877370dbbe365e2014be64af3d3b212b8 (patch) | |
| tree | 7fafb798a2e5b524601b785879107c591c537aed | |
| parent | a4d4052d3a38b534bdfb7501341d11125609de79 (diff) | |
| download | chawan-c45502f877370dbbe365e2014be64af3d3b212b8.tar.gz | |
config: fix overriding substring bindings
It is unfortunately a breaking change, but the existing behavior was
practically broken anyway.
The only issue I can think of is that keybindings like `yy' now override
`y', which previously worked because y (regrettably) calls feedNext. But
those should be added to the default config anyway.
(If a user really desires the old behavior, they can just re-bind y to
cmd.buffer.copySelection after their own custom bindings. Config values
are now stored in an ordered table, so this should work.)
I've left the undocumented JS setter as it is, because the old behavior
seems more useful there. (Perhaps there should be a separate function
that behaves like toml?)
| -rw-r--r-- | src/config/config.nim | 14 | ||||
| -rw-r--r-- | src/config/toml.nim | 2 |
2 files changed, 6 insertions, 10 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index a55c807f..a197853b 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -218,9 +218,6 @@ proc contains*(a: ActionMap; b: string): bool = proc getOrDefault(a: ActionMap; b: string): string = return a.t.getOrDefault(b) -proc hasKeyOrPut(a: var ActionMap; b, c: string): bool = - return a.t.hasKeyOrPut(b, c) - func getRealKey(key: string): string = var realk: string var control = 0 @@ -276,8 +273,7 @@ proc setter(a: var ActionMap; k, v: string) {.jssetprop.} = var teststr = k teststr.setLen(teststr.high) for i in countdown(k.high, 0): - if teststr notin a: - a[teststr] = "client.feedNext()" + discard a.t.hasKeyOrPut(teststr, "client.feedNext()") teststr.setLen(i) proc delete(a: var ActionMap; k: string): bool {.jsdelprop.} = @@ -520,10 +516,10 @@ proc parseConfigValue(ctx: var ConfigParser; x: var ActionMap; v: TomlValue; for kk, vv in v: typeCheck(vv, tvtString, k & "[" & kk & "]") let rk = getRealKey(kk) - var buf: string - for i in 0 ..< rk.high: - buf &= rk[i] - discard x.hasKeyOrPut(buf, "client.feedNext()") + var buf = "" + for c in rk.toOpenArray(0, rk.high - 1): + buf &= c + x[buf] = "client.feedNext()" x[rk] = vv.s proc parseConfigValue[T: enum](ctx: var ConfigParser; x: var T; v: TomlValue; diff --git a/src/config/toml.nim b/src/config/toml.nim index 296c7766..8ba6d442 100644 --- a/src/config/toml.nim +++ b/src/config/toml.nim @@ -54,7 +54,7 @@ type TomlTable* = ref object of TomlNode key: seq[string] nodes: seq[TomlNode] - map: Table[string, TomlValue] + map: OrderedTable[string, TomlValue] func `$`*(val: TomlValue): string |