@opentui/core 0.1.59 → 0.1.61

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/index.js CHANGED
@@ -61,6 +61,8 @@ import {
61
61
  brightRed,
62
62
  brightWhite,
63
63
  brightYellow,
64
+ buildKeyBindingsMap,
65
+ buildKittyKeyboardFlags,
64
66
  capture,
65
67
  clearEnvCache,
66
68
  convertGlobalToLocalSelection,
@@ -70,6 +72,7 @@ import {
70
72
  createTerminalPalette,
71
73
  createTextAttributes,
72
74
  cyan,
75
+ defaultKeyAliases,
73
76
  delegate,
74
77
  dim,
75
78
  env,
@@ -84,6 +87,7 @@ import {
84
87
  getBorderSides,
85
88
  getCharacterPositions,
86
89
  getDataPaths,
90
+ getKeyBindingKey,
87
91
  getObjectsInViewport,
88
92
  getTreeSitterClient,
89
93
  green,
@@ -101,6 +105,8 @@ import {
101
105
  main,
102
106
  maybeMakeRenderable,
103
107
  measureText,
108
+ mergeKeyAliases,
109
+ mergeKeyBindings,
104
110
  nonAlphanumericKeys,
105
111
  parseAlign,
106
112
  parseBoxSizing,
@@ -137,7 +143,7 @@ import {
137
143
  white,
138
144
  wrapWithDelegates,
139
145
  yellow
140
- } from "./index-crebvcxc.js";
146
+ } from "./index-rysm4rsr.js";
141
147
  // src/text-buffer-view.ts
142
148
  class TextBufferView {
143
149
  lib;
@@ -308,29 +314,33 @@ class EditBuffer extends EventEmitter {
308
314
  this.guard();
309
315
  return this.bufferPtr;
310
316
  }
311
- setText(text, opts) {
317
+ setText(text) {
312
318
  this.guard();
313
- const history = opts?.history ?? true;
314
319
  const textBytes = this.lib.encoder.encode(text);
315
- if (history) {
316
- this._textBytes.push(textBytes);
317
- const memId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
318
- this.lib.editBufferSetTextFromMem(this.bufferPtr, memId, true);
320
+ if (this._singleTextMemId !== null) {
321
+ this.lib.textBufferReplaceMemBuffer(this.textBufferPtr, this._singleTextMemId, textBytes, false);
319
322
  } else {
320
- if (this._singleTextMemId !== null) {
321
- this.lib.textBufferReplaceMemBuffer(this.textBufferPtr, this._singleTextMemId, textBytes, false);
322
- } else {
323
- this._singleTextMemId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
324
- }
325
- this._singleTextBytes = textBytes;
326
- this.lib.editBufferSetTextFromMem(this.bufferPtr, this._singleTextMemId, false);
323
+ this._singleTextMemId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
327
324
  }
325
+ this._singleTextBytes = textBytes;
326
+ this.lib.editBufferSetTextFromMem(this.bufferPtr, this._singleTextMemId);
327
+ }
328
+ setTextOwned(text) {
329
+ this.guard();
330
+ const textBytes = this.lib.encoder.encode(text);
331
+ this.lib.editBufferSetText(this.bufferPtr, textBytes);
328
332
  }
329
- setTextOwned(text, opts) {
333
+ replaceText(text) {
330
334
  this.guard();
331
- const history = opts?.history ?? true;
332
335
  const textBytes = this.lib.encoder.encode(text);
333
- this.lib.editBufferSetText(this.bufferPtr, textBytes, history);
336
+ this._textBytes.push(textBytes);
337
+ const memId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
338
+ this.lib.editBufferReplaceTextFromMem(this.bufferPtr, memId);
339
+ }
340
+ replaceTextOwned(text) {
341
+ this.guard();
342
+ const textBytes = this.lib.encoder.encode(text);
343
+ this.lib.editBufferReplaceText(this.bufferPtr, textBytes);
334
344
  }
335
345
  getLineCount() {
336
346
  this.guard();
@@ -687,6 +697,14 @@ class EditorView {
687
697
  this.guard();
688
698
  return this.lib.editorViewGetEOL(this.viewPtr);
689
699
  }
700
+ getVisualSOL() {
701
+ this.guard();
702
+ return this.lib.editorViewGetVisualSOL(this.viewPtr);
703
+ }
704
+ getVisualEOL() {
705
+ this.guard();
706
+ return this.lib.editorViewGetVisualEOL(this.viewPtr);
707
+ }
690
708
  getLineInfo() {
691
709
  this.guard();
692
710
  return this.lib.editorViewGetLineInfo(this.viewPtr);
@@ -5434,46 +5452,6 @@ class DiffRenderable extends Renderable {
5434
5452
  }
5435
5453
  }
5436
5454
  }
5437
- // src/lib/keymapping.ts
5438
- var defaultKeyAliases = {
5439
- enter: "return",
5440
- esc: "escape"
5441
- };
5442
- function mergeKeyAliases(defaults, custom) {
5443
- return { ...defaults, ...custom };
5444
- }
5445
- function mergeKeyBindings(defaults, custom) {
5446
- const map = new Map;
5447
- for (const binding of defaults) {
5448
- const key = getKeyBindingKey(binding);
5449
- map.set(key, binding);
5450
- }
5451
- for (const binding of custom) {
5452
- const key = getKeyBindingKey(binding);
5453
- map.set(key, binding);
5454
- }
5455
- return Array.from(map.values());
5456
- }
5457
- function getKeyBindingKey(binding) {
5458
- return `${binding.name}:${binding.ctrl ? 1 : 0}:${binding.shift ? 1 : 0}:${binding.meta ? 1 : 0}:${binding.super ? 1 : 0}`;
5459
- }
5460
- function buildKeyBindingsMap(bindings, aliasMap) {
5461
- const map = new Map;
5462
- const aliases = aliasMap || {};
5463
- for (const binding of bindings) {
5464
- const key = getKeyBindingKey(binding);
5465
- map.set(key, binding.action);
5466
- }
5467
- for (const binding of bindings) {
5468
- const normalizedName = aliases[binding.name] || binding.name;
5469
- if (normalizedName !== binding.name) {
5470
- const aliasedKey = getKeyBindingKey({ ...binding, name: normalizedName });
5471
- map.set(aliasedKey, binding.action);
5472
- }
5473
- }
5474
- return map;
5475
- }
5476
-
5477
5455
  // src/renderables/Input.ts
5478
5456
  var defaultInputKeybindings = [
5479
5457
  { name: "left", action: "move-left" },
@@ -5675,19 +5653,12 @@ class InputRenderable extends Renderable {
5675
5653
  }
5676
5654
  }
5677
5655
  handleKeyPress(key) {
5678
- const keyName = typeof key === "string" ? key : key.name;
5679
- const keySequence = typeof key === "string" ? key : key.sequence;
5680
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
5681
- const keyShift = typeof key === "string" ? false : key.shift;
5682
- const keyMeta = typeof key === "string" ? false : key.meta;
5683
- const keySuper = typeof key === "string" ? false : key.super;
5684
- const keyHyper = typeof key === "string" ? false : key.hyper;
5685
5656
  const bindingKey = getKeyBindingKey({
5686
- name: keyName,
5687
- ctrl: keyCtrl,
5688
- shift: keyShift,
5689
- meta: keyMeta,
5690
- super: keySuper,
5657
+ name: key.name,
5658
+ ctrl: key.ctrl,
5659
+ shift: key.shift,
5660
+ meta: key.meta,
5661
+ super: key.super,
5691
5662
  action: "move-left"
5692
5663
  });
5693
5664
  const action = this._keyBindingsMap.get(bindingKey);
@@ -5720,13 +5691,13 @@ class InputRenderable extends Renderable {
5720
5691
  return true;
5721
5692
  }
5722
5693
  }
5723
- if (!keyCtrl && !keyMeta && !keySuper && !keyHyper) {
5724
- if (keyName === "space") {
5694
+ if (!key.ctrl && !key.meta && !key.super && !key.hyper) {
5695
+ if (key.name === "space") {
5725
5696
  this.insertText(" ");
5726
5697
  return true;
5727
5698
  }
5728
- if (keySequence && keySequence.length === 1 && keySequence.charCodeAt(0) >= 32 && keySequence.charCodeAt(0) <= 126) {
5729
- this.insertText(keySequence);
5699
+ if (key.sequence && key.sequence.length === 1 && key.sequence.charCodeAt(0) >= 32 && key.sequence.charCodeAt(0) <= 126) {
5700
+ this.insertText(key.sequence);
5730
5701
  return true;
5731
5702
  }
5732
5703
  }
@@ -6273,8 +6244,7 @@ class ScrollBarRenderable extends Renderable {
6273
6244
  }
6274
6245
  }
6275
6246
  handleKeyPress(key) {
6276
- const keyName = typeof key === "string" ? key : key.name;
6277
- switch (keyName) {
6247
+ switch (key.name) {
6278
6248
  case "left":
6279
6249
  case "h":
6280
6250
  if (this.orientation !== "horizontal")
@@ -7193,17 +7163,12 @@ class SelectRenderable extends Renderable {
7193
7163
  this.requestRender();
7194
7164
  }
7195
7165
  handleKeyPress(key) {
7196
- const keyName = typeof key === "string" ? key : key.name;
7197
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
7198
- const keyShift = typeof key === "string" ? false : key.shift;
7199
- const keyMeta = typeof key === "string" ? false : key.meta;
7200
- const keySuper = typeof key === "string" ? false : key.super;
7201
7166
  const bindingKey = getKeyBindingKey({
7202
- name: keyName,
7203
- ctrl: keyCtrl,
7204
- shift: keyShift,
7205
- meta: keyMeta,
7206
- super: keySuper,
7167
+ name: key.name,
7168
+ ctrl: key.ctrl,
7169
+ shift: key.shift,
7170
+ meta: key.meta,
7171
+ super: key.super,
7207
7172
  action: "move-up"
7208
7173
  });
7209
7174
  const action = this._keyBindingsMap.get(bindingKey);
@@ -7566,17 +7531,12 @@ class TabSelectRenderable extends Renderable {
7566
7531
  return this._tabWidth;
7567
7532
  }
7568
7533
  handleKeyPress(key) {
7569
- const keyName = typeof key === "string" ? key : key.name;
7570
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
7571
- const keyShift = typeof key === "string" ? false : key.shift;
7572
- const keyMeta = typeof key === "string" ? false : key.meta;
7573
- const keySuper = typeof key === "string" ? false : key.super;
7574
7534
  const bindingKey = getKeyBindingKey({
7575
- name: keyName,
7576
- ctrl: keyCtrl,
7577
- shift: keyShift,
7578
- meta: keyMeta,
7579
- super: keySuper,
7535
+ name: key.name,
7536
+ ctrl: key.ctrl,
7537
+ shift: key.shift,
7538
+ meta: key.meta,
7539
+ super: key.super,
7580
7540
  action: "move-left"
7581
7541
  });
7582
7542
  const action = this._keyBindingsMap.get(bindingKey);
@@ -8105,8 +8065,13 @@ class EditBufferRenderable extends Renderable {
8105
8065
  getLineHighlights(lineIdx) {
8106
8066
  return this.editBuffer.getLineHighlights(lineIdx);
8107
8067
  }
8108
- setText(text, opts) {
8109
- this.editBuffer.setText(text, opts);
8068
+ setText(text) {
8069
+ this.editBuffer.setText(text);
8070
+ this.yogaNode.markDirty();
8071
+ this.requestRender();
8072
+ }
8073
+ replaceText(text) {
8074
+ this.editBuffer.replaceText(text);
8110
8075
  this.yogaNode.markDirty();
8111
8076
  this.requestRender();
8112
8077
  }
@@ -8199,14 +8164,25 @@ var defaultTextareaKeybindings = [
8199
8164
  { name: "end", shift: true, action: "select-buffer-end" },
8200
8165
  { name: "a", ctrl: true, action: "line-home" },
8201
8166
  { name: "e", ctrl: true, action: "line-end" },
8167
+ { name: "a", ctrl: true, shift: true, action: "select-line-home" },
8168
+ { name: "e", ctrl: true, shift: true, action: "select-line-end" },
8169
+ { name: "a", meta: true, action: "visual-line-home" },
8170
+ { name: "e", meta: true, action: "visual-line-end" },
8171
+ { name: "a", meta: true, shift: true, action: "select-visual-line-home" },
8172
+ { name: "e", meta: true, shift: true, action: "select-visual-line-end" },
8202
8173
  { name: "f", ctrl: true, action: "move-right" },
8203
8174
  { name: "b", ctrl: true, action: "move-left" },
8204
- { name: "d", ctrl: true, action: "delete-word-forward" },
8205
8175
  { name: "w", ctrl: true, action: "delete-word-backward" },
8176
+ { name: "backspace", ctrl: true, action: "delete-word-backward" },
8177
+ { name: "d", meta: true, action: "delete-word-forward" },
8178
+ { name: "delete", meta: true, action: "delete-word-forward" },
8179
+ { name: "delete", ctrl: true, action: "delete-word-forward" },
8180
+ { name: "d", ctrl: true, shift: true, action: "delete-line" },
8206
8181
  { name: "k", ctrl: true, action: "delete-to-line-end" },
8207
8182
  { name: "u", ctrl: true, action: "delete-to-line-start" },
8208
8183
  { name: "backspace", action: "backspace" },
8209
8184
  { name: "backspace", shift: true, action: "backspace" },
8185
+ { name: "d", ctrl: true, action: "delete" },
8210
8186
  { name: "delete", action: "delete" },
8211
8187
  { name: "delete", shift: true, action: "delete" },
8212
8188
  { name: "return", action: "newline" },
@@ -8220,11 +8196,12 @@ var defaultTextareaKeybindings = [
8220
8196
  { name: "b", meta: true, action: "word-backward" },
8221
8197
  { name: "right", meta: true, action: "word-forward" },
8222
8198
  { name: "left", meta: true, action: "word-backward" },
8199
+ { name: "right", ctrl: true, action: "word-forward" },
8200
+ { name: "left", ctrl: true, action: "word-backward" },
8223
8201
  { name: "f", meta: true, shift: true, action: "select-word-forward" },
8224
8202
  { name: "b", meta: true, shift: true, action: "select-word-backward" },
8225
8203
  { name: "right", meta: true, shift: true, action: "select-word-forward" },
8226
8204
  { name: "left", meta: true, shift: true, action: "select-word-backward" },
8227
- { name: "d", meta: true, action: "delete-line" },
8228
8205
  { name: "backspace", meta: true, action: "delete-word-backward" }
8229
8206
  ];
8230
8207
 
@@ -8300,6 +8277,10 @@ class TextareaRenderable extends EditBufferRenderable {
8300
8277
  ["line-end", () => this.gotoLineEnd()],
8301
8278
  ["select-line-home", () => this.gotoLineHome({ select: true })],
8302
8279
  ["select-line-end", () => this.gotoLineEnd({ select: true })],
8280
+ ["visual-line-home", () => this.gotoVisualLineHome()],
8281
+ ["visual-line-end", () => this.gotoVisualLineEnd()],
8282
+ ["select-visual-line-home", () => this.gotoVisualLineHome({ select: true })],
8283
+ ["select-visual-line-end", () => this.gotoVisualLineEnd({ select: true })],
8303
8284
  ["select-buffer-home", () => this.gotoBufferHome({ select: true })],
8304
8285
  ["select-buffer-end", () => this.gotoBufferEnd({ select: true })],
8305
8286
  ["buffer-home", () => this.gotoBufferHome()],
@@ -8325,19 +8306,12 @@ class TextareaRenderable extends EditBufferRenderable {
8325
8306
  this.insertText(event.text);
8326
8307
  }
8327
8308
  handleKeyPress(key) {
8328
- const keyName = typeof key === "string" ? key : key.name;
8329
- const keySequence = typeof key === "string" ? key : key.sequence;
8330
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
8331
- const keyShift = typeof key === "string" ? false : key.shift;
8332
- const keyMeta = typeof key === "string" ? false : key.meta;
8333
- const keySuper = typeof key === "string" ? false : key.super;
8334
- const keyHyper = typeof key === "string" ? false : key.hyper;
8335
8309
  const bindingKey = getKeyBindingKey({
8336
- name: keyName,
8337
- ctrl: keyCtrl,
8338
- shift: keyShift,
8339
- meta: keyMeta,
8340
- super: keySuper,
8310
+ name: key.name,
8311
+ ctrl: key.ctrl,
8312
+ shift: key.shift,
8313
+ meta: key.meta,
8314
+ super: key.super,
8341
8315
  action: "move-left"
8342
8316
  });
8343
8317
  const action = this._keyBindingsMap.get(bindingKey);
@@ -8347,20 +8321,20 @@ class TextareaRenderable extends EditBufferRenderable {
8347
8321
  return handler();
8348
8322
  }
8349
8323
  }
8350
- if (!keyCtrl && !keyMeta && !keySuper && !keyHyper) {
8351
- if (keyName === "space") {
8324
+ if (!key.ctrl && !key.meta && !key.super && !key.hyper) {
8325
+ if (key.name === "space") {
8352
8326
  this.insertText(" ");
8353
8327
  return true;
8354
8328
  }
8355
- if (keySequence) {
8356
- const firstCharCode = keySequence.charCodeAt(0);
8329
+ if (key.sequence) {
8330
+ const firstCharCode = key.sequence.charCodeAt(0);
8357
8331
  if (firstCharCode < 32) {
8358
8332
  return false;
8359
8333
  }
8360
8334
  if (firstCharCode === 127) {
8361
8335
  return false;
8362
8336
  }
8363
- this.insertText(keySequence);
8337
+ this.insertText(key.sequence);
8364
8338
  return true;
8365
8339
  }
8366
8340
  }
@@ -8489,6 +8463,24 @@ class TextareaRenderable extends EditBufferRenderable {
8489
8463
  this.requestRender();
8490
8464
  return true;
8491
8465
  }
8466
+ gotoVisualLineHome(options) {
8467
+ const select = options?.select ?? false;
8468
+ this.updateSelectionForMovement(select, true);
8469
+ const sol = this.editorView.getVisualSOL();
8470
+ this.editBuffer.setCursor(sol.logicalRow, sol.logicalCol);
8471
+ this.updateSelectionForMovement(select, false);
8472
+ this.requestRender();
8473
+ return true;
8474
+ }
8475
+ gotoVisualLineEnd(options) {
8476
+ const select = options?.select ?? false;
8477
+ this.updateSelectionForMovement(select, true);
8478
+ const eol = this.editorView.getVisualEOL();
8479
+ this.editBuffer.setCursor(eol.logicalRow, eol.logicalCol);
8480
+ this.updateSelectionForMovement(select, false);
8481
+ this.requestRender();
8482
+ return true;
8483
+ }
8492
8484
  gotoBufferHome(options) {
8493
8485
  const select = options?.select ?? false;
8494
8486
  this.updateSelectionForMovement(select, true);
@@ -8745,6 +8737,7 @@ export {
8745
8737
  convertGlobalToLocalSelection,
8746
8738
  clearEnvCache,
8747
8739
  capture,
8740
+ buildKittyKeyboardFlags,
8748
8741
  brightYellow,
8749
8742
  brightWhite,
8750
8743
  brightRed,
@@ -8853,5 +8846,5 @@ export {
8853
8846
  ASCIIFont
8854
8847
  };
8855
8848
 
8856
- //# debugId=69099B83255E61E264756E2164756E21
8849
+ //# debugId=7F98B9DEC58574A464756E2164756E21
8857
8850
  //# sourceMappingURL=index.js.map