@opentui/core 0.0.0-20251208-bec95e7d → 0.0.0-20251211-4403a69a

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,7 @@ import {
61
61
  brightRed,
62
62
  brightWhite,
63
63
  brightYellow,
64
+ buildKittyKeyboardFlags,
64
65
  capture,
65
66
  clearEnvCache,
66
67
  convertGlobalToLocalSelection,
@@ -137,7 +138,7 @@ import {
137
138
  white,
138
139
  wrapWithDelegates,
139
140
  yellow
140
- } from "./index-crebvcxc.js";
141
+ } from "./index-yhfn13z6.js";
141
142
  // src/text-buffer-view.ts
142
143
  class TextBufferView {
143
144
  lib;
@@ -308,29 +309,33 @@ class EditBuffer extends EventEmitter {
308
309
  this.guard();
309
310
  return this.bufferPtr;
310
311
  }
311
- setText(text, opts) {
312
+ setText(text) {
312
313
  this.guard();
313
- const history = opts?.history ?? true;
314
314
  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);
315
+ if (this._singleTextMemId !== null) {
316
+ this.lib.textBufferReplaceMemBuffer(this.textBufferPtr, this._singleTextMemId, textBytes, false);
319
317
  } 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);
318
+ this._singleTextMemId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
327
319
  }
320
+ this._singleTextBytes = textBytes;
321
+ this.lib.editBufferSetTextFromMem(this.bufferPtr, this._singleTextMemId);
322
+ }
323
+ setTextOwned(text) {
324
+ this.guard();
325
+ const textBytes = this.lib.encoder.encode(text);
326
+ this.lib.editBufferSetText(this.bufferPtr, textBytes);
327
+ }
328
+ replaceText(text) {
329
+ this.guard();
330
+ const textBytes = this.lib.encoder.encode(text);
331
+ this._textBytes.push(textBytes);
332
+ const memId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
333
+ this.lib.editBufferReplaceTextFromMem(this.bufferPtr, memId);
328
334
  }
329
- setTextOwned(text, opts) {
335
+ replaceTextOwned(text) {
330
336
  this.guard();
331
- const history = opts?.history ?? true;
332
337
  const textBytes = this.lib.encoder.encode(text);
333
- this.lib.editBufferSetText(this.bufferPtr, textBytes, history);
338
+ this.lib.editBufferReplaceText(this.bufferPtr, textBytes);
334
339
  }
335
340
  getLineCount() {
336
341
  this.guard();
@@ -687,6 +692,14 @@ class EditorView {
687
692
  this.guard();
688
693
  return this.lib.editorViewGetEOL(this.viewPtr);
689
694
  }
695
+ getVisualSOL() {
696
+ this.guard();
697
+ return this.lib.editorViewGetVisualSOL(this.viewPtr);
698
+ }
699
+ getVisualEOL() {
700
+ this.guard();
701
+ return this.lib.editorViewGetVisualEOL(this.viewPtr);
702
+ }
690
703
  getLineInfo() {
691
704
  this.guard();
692
705
  return this.lib.editorViewGetLineInfo(this.viewPtr);
@@ -5675,19 +5688,12 @@ class InputRenderable extends Renderable {
5675
5688
  }
5676
5689
  }
5677
5690
  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
5691
  const bindingKey = getKeyBindingKey({
5686
- name: keyName,
5687
- ctrl: keyCtrl,
5688
- shift: keyShift,
5689
- meta: keyMeta,
5690
- super: keySuper,
5692
+ name: key.name,
5693
+ ctrl: key.ctrl,
5694
+ shift: key.shift,
5695
+ meta: key.meta,
5696
+ super: key.super,
5691
5697
  action: "move-left"
5692
5698
  });
5693
5699
  const action = this._keyBindingsMap.get(bindingKey);
@@ -5720,9 +5726,15 @@ class InputRenderable extends Renderable {
5720
5726
  return true;
5721
5727
  }
5722
5728
  }
5723
- if (keySequence && keySequence.length === 1 && keySequence.charCodeAt(0) >= 32 && keySequence.charCodeAt(0) <= 126 && !keyCtrl && !keyMeta && !keySuper && !keyHyper) {
5724
- this.insertText(keySequence);
5725
- return true;
5729
+ if (!key.ctrl && !key.meta && !key.super && !key.hyper) {
5730
+ if (key.name === "space") {
5731
+ this.insertText(" ");
5732
+ return true;
5733
+ }
5734
+ if (key.sequence && key.sequence.length === 1 && key.sequence.charCodeAt(0) >= 32 && key.sequence.charCodeAt(0) <= 126) {
5735
+ this.insertText(key.sequence);
5736
+ return true;
5737
+ }
5726
5738
  }
5727
5739
  return false;
5728
5740
  }
@@ -6267,8 +6279,7 @@ class ScrollBarRenderable extends Renderable {
6267
6279
  }
6268
6280
  }
6269
6281
  handleKeyPress(key) {
6270
- const keyName = typeof key === "string" ? key : key.name;
6271
- switch (keyName) {
6282
+ switch (key.name) {
6272
6283
  case "left":
6273
6284
  case "h":
6274
6285
  if (this.orientation !== "horizontal")
@@ -6412,7 +6423,7 @@ class ContentRenderable extends BoxRenderable {
6412
6423
  }
6413
6424
  _getVisibleChildren() {
6414
6425
  if (this._viewportCulling) {
6415
- return getObjectsInViewport(this.viewport, this.getChildrenSortedByPrimaryAxis(), this.primaryAxis).map((child) => child.num);
6426
+ return getObjectsInViewport(this.viewport, this.getChildrenSortedByPrimaryAxis(), this.primaryAxis, 0).map((child) => child.num);
6416
6427
  }
6417
6428
  return this.getChildrenSortedByPrimaryAxis().map((child) => child.num);
6418
6429
  }
@@ -7187,17 +7198,12 @@ class SelectRenderable extends Renderable {
7187
7198
  this.requestRender();
7188
7199
  }
7189
7200
  handleKeyPress(key) {
7190
- const keyName = typeof key === "string" ? key : key.name;
7191
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
7192
- const keyShift = typeof key === "string" ? false : key.shift;
7193
- const keyMeta = typeof key === "string" ? false : key.meta;
7194
- const keySuper = typeof key === "string" ? false : key.super;
7195
7201
  const bindingKey = getKeyBindingKey({
7196
- name: keyName,
7197
- ctrl: keyCtrl,
7198
- shift: keyShift,
7199
- meta: keyMeta,
7200
- super: keySuper,
7202
+ name: key.name,
7203
+ ctrl: key.ctrl,
7204
+ shift: key.shift,
7205
+ meta: key.meta,
7206
+ super: key.super,
7201
7207
  action: "move-up"
7202
7208
  });
7203
7209
  const action = this._keyBindingsMap.get(bindingKey);
@@ -7560,17 +7566,12 @@ class TabSelectRenderable extends Renderable {
7560
7566
  return this._tabWidth;
7561
7567
  }
7562
7568
  handleKeyPress(key) {
7563
- const keyName = typeof key === "string" ? key : key.name;
7564
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
7565
- const keyShift = typeof key === "string" ? false : key.shift;
7566
- const keyMeta = typeof key === "string" ? false : key.meta;
7567
- const keySuper = typeof key === "string" ? false : key.super;
7568
7569
  const bindingKey = getKeyBindingKey({
7569
- name: keyName,
7570
- ctrl: keyCtrl,
7571
- shift: keyShift,
7572
- meta: keyMeta,
7573
- super: keySuper,
7570
+ name: key.name,
7571
+ ctrl: key.ctrl,
7572
+ shift: key.shift,
7573
+ meta: key.meta,
7574
+ super: key.super,
7574
7575
  action: "move-left"
7575
7576
  });
7576
7577
  const action = this._keyBindingsMap.get(bindingKey);
@@ -8099,8 +8100,13 @@ class EditBufferRenderable extends Renderable {
8099
8100
  getLineHighlights(lineIdx) {
8100
8101
  return this.editBuffer.getLineHighlights(lineIdx);
8101
8102
  }
8102
- setText(text, opts) {
8103
- this.editBuffer.setText(text, opts);
8103
+ setText(text) {
8104
+ this.editBuffer.setText(text);
8105
+ this.yogaNode.markDirty();
8106
+ this.requestRender();
8107
+ }
8108
+ replaceText(text) {
8109
+ this.editBuffer.replaceText(text);
8104
8110
  this.yogaNode.markDirty();
8105
8111
  this.requestRender();
8106
8112
  }
@@ -8193,14 +8199,25 @@ var defaultTextareaKeybindings = [
8193
8199
  { name: "end", shift: true, action: "select-buffer-end" },
8194
8200
  { name: "a", ctrl: true, action: "line-home" },
8195
8201
  { name: "e", ctrl: true, action: "line-end" },
8202
+ { name: "a", ctrl: true, shift: true, action: "select-line-home" },
8203
+ { name: "e", ctrl: true, shift: true, action: "select-line-end" },
8204
+ { name: "a", meta: true, action: "visual-line-home" },
8205
+ { name: "e", meta: true, action: "visual-line-end" },
8206
+ { name: "a", meta: true, shift: true, action: "select-visual-line-home" },
8207
+ { name: "e", meta: true, shift: true, action: "select-visual-line-end" },
8196
8208
  { name: "f", ctrl: true, action: "move-right" },
8197
8209
  { name: "b", ctrl: true, action: "move-left" },
8198
- { name: "d", ctrl: true, action: "delete-word-forward" },
8199
8210
  { name: "w", ctrl: true, action: "delete-word-backward" },
8211
+ { name: "backspace", ctrl: true, action: "delete-word-backward" },
8212
+ { name: "d", meta: true, action: "delete-word-forward" },
8213
+ { name: "delete", meta: true, action: "delete-word-forward" },
8214
+ { name: "delete", ctrl: true, action: "delete-word-forward" },
8215
+ { name: "d", ctrl: true, shift: true, action: "delete-line" },
8200
8216
  { name: "k", ctrl: true, action: "delete-to-line-end" },
8201
8217
  { name: "u", ctrl: true, action: "delete-to-line-start" },
8202
8218
  { name: "backspace", action: "backspace" },
8203
8219
  { name: "backspace", shift: true, action: "backspace" },
8220
+ { name: "d", ctrl: true, action: "delete" },
8204
8221
  { name: "delete", action: "delete" },
8205
8222
  { name: "delete", shift: true, action: "delete" },
8206
8223
  { name: "return", action: "newline" },
@@ -8214,11 +8231,12 @@ var defaultTextareaKeybindings = [
8214
8231
  { name: "b", meta: true, action: "word-backward" },
8215
8232
  { name: "right", meta: true, action: "word-forward" },
8216
8233
  { name: "left", meta: true, action: "word-backward" },
8234
+ { name: "right", ctrl: true, action: "word-forward" },
8235
+ { name: "left", ctrl: true, action: "word-backward" },
8217
8236
  { name: "f", meta: true, shift: true, action: "select-word-forward" },
8218
8237
  { name: "b", meta: true, shift: true, action: "select-word-backward" },
8219
8238
  { name: "right", meta: true, shift: true, action: "select-word-forward" },
8220
8239
  { name: "left", meta: true, shift: true, action: "select-word-backward" },
8221
- { name: "d", meta: true, action: "delete-line" },
8222
8240
  { name: "backspace", meta: true, action: "delete-word-backward" }
8223
8241
  ];
8224
8242
 
@@ -8294,6 +8312,10 @@ class TextareaRenderable extends EditBufferRenderable {
8294
8312
  ["line-end", () => this.gotoLineEnd()],
8295
8313
  ["select-line-home", () => this.gotoLineHome({ select: true })],
8296
8314
  ["select-line-end", () => this.gotoLineEnd({ select: true })],
8315
+ ["visual-line-home", () => this.gotoVisualLineHome()],
8316
+ ["visual-line-end", () => this.gotoVisualLineEnd()],
8317
+ ["select-visual-line-home", () => this.gotoVisualLineHome({ select: true })],
8318
+ ["select-visual-line-end", () => this.gotoVisualLineEnd({ select: true })],
8297
8319
  ["select-buffer-home", () => this.gotoBufferHome({ select: true })],
8298
8320
  ["select-buffer-end", () => this.gotoBufferEnd({ select: true })],
8299
8321
  ["buffer-home", () => this.gotoBufferHome()],
@@ -8319,19 +8341,12 @@ class TextareaRenderable extends EditBufferRenderable {
8319
8341
  this.insertText(event.text);
8320
8342
  }
8321
8343
  handleKeyPress(key) {
8322
- const keyName = typeof key === "string" ? key : key.name;
8323
- const keySequence = typeof key === "string" ? key : key.sequence;
8324
- const keyCtrl = typeof key === "string" ? false : key.ctrl;
8325
- const keyShift = typeof key === "string" ? false : key.shift;
8326
- const keyMeta = typeof key === "string" ? false : key.meta;
8327
- const keySuper = typeof key === "string" ? false : key.super;
8328
- const keyHyper = typeof key === "string" ? false : key.hyper;
8329
8344
  const bindingKey = getKeyBindingKey({
8330
- name: keyName,
8331
- ctrl: keyCtrl,
8332
- shift: keyShift,
8333
- meta: keyMeta,
8334
- super: keySuper,
8345
+ name: key.name,
8346
+ ctrl: key.ctrl,
8347
+ shift: key.shift,
8348
+ meta: key.meta,
8349
+ super: key.super,
8335
8350
  action: "move-left"
8336
8351
  });
8337
8352
  const action = this._keyBindingsMap.get(bindingKey);
@@ -8341,16 +8356,22 @@ class TextareaRenderable extends EditBufferRenderable {
8341
8356
  return handler();
8342
8357
  }
8343
8358
  }
8344
- if (keySequence && !keyCtrl && !keyMeta && !keySuper && !keyHyper) {
8345
- const firstCharCode = keySequence.charCodeAt(0);
8346
- if (firstCharCode < 32) {
8347
- return false;
8359
+ if (!key.ctrl && !key.meta && !key.super && !key.hyper) {
8360
+ if (key.name === "space") {
8361
+ this.insertText(" ");
8362
+ return true;
8348
8363
  }
8349
- if (firstCharCode === 127) {
8350
- return false;
8364
+ if (key.sequence) {
8365
+ const firstCharCode = key.sequence.charCodeAt(0);
8366
+ if (firstCharCode < 32) {
8367
+ return false;
8368
+ }
8369
+ if (firstCharCode === 127) {
8370
+ return false;
8371
+ }
8372
+ this.insertText(key.sequence);
8373
+ return true;
8351
8374
  }
8352
- this.insertText(keySequence);
8353
- return true;
8354
8375
  }
8355
8376
  return false;
8356
8377
  }
@@ -8451,7 +8472,13 @@ class TextareaRenderable extends EditBufferRenderable {
8451
8472
  const select = options?.select ?? false;
8452
8473
  this.updateSelectionForMovement(select, true);
8453
8474
  const cursor = this.editorView.getCursor();
8454
- this.editBuffer.setCursor(cursor.row, 0);
8475
+ if (cursor.col === 0 && cursor.row > 0) {
8476
+ this.editBuffer.setCursor(cursor.row - 1, 0);
8477
+ const prevLineEol = this.editBuffer.getEOL();
8478
+ this.editBuffer.setCursor(prevLineEol.row, prevLineEol.col);
8479
+ } else {
8480
+ this.editBuffer.setCursor(cursor.row, 0);
8481
+ }
8455
8482
  this.updateSelectionForMovement(select, false);
8456
8483
  this.requestRender();
8457
8484
  return true;
@@ -8459,8 +8486,32 @@ class TextareaRenderable extends EditBufferRenderable {
8459
8486
  gotoLineEnd(options) {
8460
8487
  const select = options?.select ?? false;
8461
8488
  this.updateSelectionForMovement(select, true);
8489
+ const cursor = this.editorView.getCursor();
8462
8490
  const eol = this.editBuffer.getEOL();
8463
- this.editBuffer.setCursor(eol.row, eol.col);
8491
+ const lineCount = this.editBuffer.getLineCount();
8492
+ if (cursor.col === eol.col && cursor.row < lineCount - 1) {
8493
+ this.editBuffer.setCursor(cursor.row + 1, 0);
8494
+ } else {
8495
+ this.editBuffer.setCursor(eol.row, eol.col);
8496
+ }
8497
+ this.updateSelectionForMovement(select, false);
8498
+ this.requestRender();
8499
+ return true;
8500
+ }
8501
+ gotoVisualLineHome(options) {
8502
+ const select = options?.select ?? false;
8503
+ this.updateSelectionForMovement(select, true);
8504
+ const sol = this.editorView.getVisualSOL();
8505
+ this.editBuffer.setCursor(sol.logicalRow, sol.logicalCol);
8506
+ this.updateSelectionForMovement(select, false);
8507
+ this.requestRender();
8508
+ return true;
8509
+ }
8510
+ gotoVisualLineEnd(options) {
8511
+ const select = options?.select ?? false;
8512
+ this.updateSelectionForMovement(select, true);
8513
+ const eol = this.editorView.getVisualEOL();
8514
+ this.editBuffer.setCursor(eol.logicalRow, eol.logicalCol);
8464
8515
  this.updateSelectionForMovement(select, false);
8465
8516
  this.requestRender();
8466
8517
  return true;
@@ -8721,6 +8772,7 @@ export {
8721
8772
  convertGlobalToLocalSelection,
8722
8773
  clearEnvCache,
8723
8774
  capture,
8775
+ buildKittyKeyboardFlags,
8724
8776
  brightYellow,
8725
8777
  brightWhite,
8726
8778
  brightRed,
@@ -8829,5 +8881,5 @@ export {
8829
8881
  ASCIIFont
8830
8882
  };
8831
8883
 
8832
- //# debugId=F8C236171D38686464756E2164756E21
8884
+ //# debugId=02ED7CC7E35CA36064756E2164756E21
8833
8885
  //# sourceMappingURL=index.js.map