@neuroplastio/xterm-addon-hotty 0.1.0-next.6 → 0.1.0-next.7

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
@@ -114,10 +114,13 @@ runs programs for whoever connects.
114
114
  selection works as usual. A right click leaves focus where the browser
115
115
  put it, so the context menu's Copy copies the surface's selection.
116
116
  - **A text field's keys** (SPEC §10.2, §10.4) are the program's keymap.
117
- Each key goes through xterm.js's keyboard handling, with what it would
118
- send the program kept back, and is named from that, so a field sees the
119
- key the program would read, in the encoding the program enabled. The
120
- field's keymap (the default, then each `data-keys` from the root to the
117
+ A key that types no text (not a character, or a character with Control
118
+ or Meta) is offered first as pressed, named from the DOM's event, before
119
+ xterm.js translates it: on a Mac, Option+Left is Alt+ArrowLeft, not the
120
+ ESC b the program would read. Otherwise the key goes through xterm.js's
121
+ keyboard handling, with what it would send the program kept back, and
122
+ is named from that, so a field sees the key the program would read, in
123
+ the encoding the program enabled. The field's keymap (the default, then each `data-keys` from the root to the
121
124
  field) decides: an action, which the addon does itself on the field's
122
125
  text with the editing commands, so the browser sends `input` and
123
126
  `change` as for typing; a character, which the browser types; or the
@@ -1251,6 +1251,12 @@ function resolve(multiline, ...values) {
1251
1251
  ["PageUp", "page-up"],
1252
1252
  ["PageDown", "page-down"],
1253
1253
  ["Control+a", "select-all"],
1254
+ ["Meta+ArrowLeft", "line-start"],
1255
+ ["Meta+ArrowRight", "line-end"],
1256
+ ["Meta+ArrowUp", "input-start"],
1257
+ ["Meta+ArrowDown", "input-end"],
1258
+ ["Meta+Backspace", "delete-to-line-start"],
1259
+ ["Meta+a", "select-all"],
1254
1260
  ["Enter", multiline ? "newline" : "submit"]
1255
1261
  ])
1256
1262
  m.bind(k, a);
@@ -2047,7 +2053,10 @@ var Surface = class {
2047
2053
  return el === this.masked ? (this.resolver.get(el, "type") ?? "").toLowerCase() : el.type;
2048
2054
  }
2049
2055
  /**
2050
- * A key in a text field. It is named as the program would read it: from
2056
+ * A key in a text field, offered at most twice (SPEC §10.4). A key that
2057
+ * types no text is offered first as pressed, named from the DOM's event,
2058
+ * before xterm.js translates it (on a Mac, Option+ArrowLeft is ESC b to
2059
+ * the program). Otherwise it is named as the program would read it: from
2051
2060
  * what xterm.js would send the program for it, in the encoding the
2052
2061
  * program enabled, read as SPEC §10.4 says. The field's keymap (the
2053
2062
  * default, then each `data-keys` from the root to the field) says what
@@ -2056,9 +2065,11 @@ var Surface = class {
2056
2065
  */
2057
2066
  fieldKey(e, el, multiline) {
2058
2067
  if (this.host.browserKey(e)) return;
2059
- const data = this.host.encodeKey(e);
2060
- const keys = data === null ? [{ key: domKeyName(e), data: "" }] : inputKeys(data);
2061
2068
  const keymap = this.keymapOf(el, multiline);
2069
+ const pressed = typesNoText(e) ? domKeyName(e) : null;
2070
+ const first = pressed !== null && keymap.lookup(pressed) !== null;
2071
+ const data = first ? "" : this.host.encodeKey(e);
2072
+ const keys = first ? [{ key: pressed, data: "" }] : data === null ? [{ key: domKeyName(e), data: "" }] : inputKeys(data);
2062
2073
  const uses = keys.map((k) => k.key === null ? null : keymap.lookup(k.key));
2063
2074
  const extend = keys.map((k) => k.key !== null && keymap.selects(k.key));
2064
2075
  if (uses.every((u) => u === null)) {
@@ -3177,6 +3188,12 @@ function keyText(key) {
3177
3188
  const v = key.endsWith("++") ? "+" : key.slice(key.lastIndexOf("+") + 1);
3178
3189
  return v === "Space" ? " " : v;
3179
3190
  }
3191
+ function typesNoText(e) {
3192
+ if (e.getModifierState?.("AltGraph")) return false;
3193
+ if ([...e.key].length === 1) return e.ctrlKey || e.metaKey;
3194
+ return !NOT_KEYS.has(e.key);
3195
+ }
3196
+ var NOT_KEYS = /* @__PURE__ */ new Set(["Unidentified", "Dead", "Process", "Compose", "Shift", "Control", "Alt", "AltGraph", "Meta", "OS", "Super", "Hyper", "Fn", "FnLock", "CapsLock", "NumLock", "ScrollLock", "Symbol", "SymbolLock"]);
3180
3197
  function domKeyName(e) {
3181
3198
  const char = [...e.key].length === 1;
3182
3199
  const mods = [e.ctrlKey && "Control", e.altKey && "Alt", e.metaKey && "Meta", e.shiftKey && !char && "Shift"].filter(Boolean);