@lengmoxxl/sdk 0.1.50 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -71,6 +71,8 @@ bindKeys(panel, [
71
71
  - 绑定只在焦点位于 `element` 内时生效;按下没有对应动作的键不拦截,页面照常收到。
72
72
  - 一个既能结束又能继续的前缀(`g` 与 `gg`)等 800ms(`timeout` 可改)再执行,等的时候再按一下就接着匹配,按别的键则结束等待并把这一按从头匹配(该按的绑定照常执行);点击页面也作废。
73
73
  - 元素里有输入框时,默认只有写了 `insert: true` 的绑定在框内生效(框里的字母归框);整页就是编辑器时用 `{ fields: 'all' }`。
74
+ - `repeat: true` 让绑定在按住时也响应:系统送来的每次重复按键都再执行一次,`j`、`<Down>` 这类移动键靠它连续走;
75
+ 没写 `repeat` 的绑定按住只执行一次,重复按键留给元素自己;只有单按一次就能执行完的绑定能这么写,等前缀时的重复按键不作数。
74
76
  - `ignore(event)` 直接放行某些按键。
75
77
  - 返回值是解绑函数,React 里 `useEffect(() => bindKeys(...))` 直接返回即可;序列的中间状态按元素保存,重新绑定不会打断按了一半的 `gg`。
76
78
 
package/dist/keys.d.ts CHANGED
@@ -9,7 +9,10 @@ interface Stroke {
9
9
  interface KeyBinding {
10
10
  keys: string;
11
11
  run(): void;
12
+ /** Runs inside a field too, where the field would keep the letters for itself. */
12
13
  insert?: boolean;
14
+ /** Runs again on every press the system sends for a key held down, which is how a held `j` walks on. */
15
+ repeat?: boolean;
13
16
  }
14
17
  /**
15
18
  * One press, written either as `<C-Space>` or as `C-Space`, and read as nothing when it names no key. Shift is carried
package/dist/keys.js CHANGED
@@ -134,8 +134,9 @@ function bindTries(element, triesFor, options) {
134
134
  event.preventDefault();
135
135
  event.stopPropagation();
136
136
  };
137
+ const completes = (node) => node.binding !== void 0 && !node.children.size;
137
138
  const onKeyDown = (event) => {
138
- if (event.isComposing || event.repeat) return;
139
+ if (event.isComposing) return;
139
140
  const started = prefixes.get(element);
140
141
  if (options.before?.(event, started !== void 0)) {
141
142
  takeEvent(event);
@@ -145,9 +146,22 @@ function bindTries(element, triesFor, options) {
145
146
  if (options.ignore?.(event)) return;
146
147
  const { outside, field } = triesFor(event);
147
148
  const trie = isEditable(event) ? field : outside;
149
+ const strokes = strokesOf(event);
150
+ if (event.repeat) {
151
+ if (started) return;
152
+ for (const stroke of strokes) {
153
+ const next = nodeAt(trie, [stroke]);
154
+ if (next && completes(next) && next.binding?.repeat) {
155
+ takeEvent(event);
156
+ next.binding.run();
157
+ return;
158
+ }
159
+ }
160
+ return;
161
+ }
148
162
  const takePress = (next, path) => {
149
163
  takeEvent(event);
150
- if (next.binding && !next.children.size) {
164
+ if (completes(next)) {
151
165
  runAfterWait(next.binding);
152
166
  return;
153
167
  }
@@ -156,7 +170,6 @@ function bindTries(element, triesFor, options) {
156
170
  prefixes.set(element, { path, timer });
157
171
  options.prefix?.(next, path.map(labelOf));
158
172
  };
159
- const strokes = strokesOf(event);
160
173
  const tryStrokes = (base) => {
161
174
  for (const stroke of strokes) {
162
175
  const path = [...base, stroke];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lengmoxxl/sdk",
3
- "version": "0.1.50",
3
+ "version": "0.1.51",
4
4
  "description": "Client SDK for WangCai: connect to a local or remote machine and drive its pty, files and git",
5
5
  "license": "MIT",
6
6
  "repository": {