@opentui/core 0.9.0 → 0.9.1

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/edit-buffer.d.ts CHANGED
@@ -17,7 +17,13 @@ export declare class EditBuffer extends EventEmitter {
17
17
  private _destroyed;
18
18
  private _syntaxStyle?;
19
19
  constructor(lib: RenderLib, handle: ContextEditBufferHandle, source: NativeResourceOwner);
20
- static create(widthMethod: WidthMethod, source: NativeResourceOwner): EditBuffer;
20
+ /**
21
+ * With `followSessionWidth`, the buffer measures with the width method of the renderer whose scene shows it,
22
+ * including when the terminal's replies change that method; the cursor, selections, marks and undo points keep
23
+ * their text. Otherwise it keeps `widthMethod`. One renderer at a time may show such a buffer: showing it in another
24
+ * one throws until the first stops showing it (`NativeError` with `status === NativeStatus.WrongSession`).
25
+ */
26
+ static create(widthMethod: WidthMethod, source: NativeResourceOwner, followSessionWidth?: boolean): EditBuffer;
21
27
  get isDestroyed(): boolean;
22
28
  private guard;
23
29
  /** @internal Editor views must use the buffer's library and Context. */
package/index.bun.js CHANGED
@@ -111,7 +111,7 @@ import {
111
111
  Gutter2,
112
112
  MeasureMode2,
113
113
  exports_yoga
114
- } from "./chunk-bun-ywheza3e.js";
114
+ } from "./chunk-bun-v1wzs0bj.js";
115
115
  import {
116
116
  isValidBorderStyle2,
117
117
  parseBorderStyle2,
@@ -244,7 +244,7 @@ import {
244
244
  CliRenderEvents2,
245
245
  RendererControlState2,
246
246
  CliRenderer2
247
- } from "./chunk-bun-rgb7yx3r.js";
247
+ } from "./chunk-bun-xartp4ps.js";
248
248
  // src/syntax-style.ts
249
249
  var attributeNames = ["bold", "italic", "underline", "dim", "strikethrough"];
250
250
  function cloneStyle(style) {
@@ -9546,6 +9546,12 @@ var MEASURE_HEIGHT = 1e4;
9546
9546
 
9547
9547
  class TextTableRenderable extends Renderable2 {
9548
9548
  _content;
9549
+ _cellWidthMethod;
9550
+ _selectionInCells = false;
9551
+ _pressedCell = null;
9552
+ _pressPinned = false;
9553
+ _pressAnchor = null;
9554
+ _pressMoved = false;
9549
9555
  _wrapMode;
9550
9556
  _columnWidthMode;
9551
9557
  _columnFitter;
@@ -9626,10 +9632,35 @@ class TextTableRenderable extends Renderable2 {
9626
9632
  this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
9627
9633
  this.setupMeasureFunc();
9628
9634
  this.runMutation(() => this.rebuildCells(this._content));
9635
+ this.setBuiltinLifecyclePass(() => {
9636
+ if (this._ctx.widthMethod !== this._cellWidthMethod)
9637
+ this.runMutation(() => this.followWidthMethod());
9638
+ });
9629
9639
  } catch (error) {
9630
9640
  this.abortConstruction(error, () => this.destroyCells());
9631
9641
  }
9632
9642
  }
9643
+ followWidthMethod() {
9644
+ const method = this._ctx.widthMethod;
9645
+ const pressed = this._pressedCell && this._cells[this._pressedCell.rowIdx]?.[this._pressedCell.colIdx];
9646
+ const anchor = this._pressAnchor !== null && pressed ? TextBufferView2.create(pressed.textBuffer) : null;
9647
+ if (this._pressPinned)
9648
+ this._pressMoved = true;
9649
+ try {
9650
+ anchor?._selectCharacter(this._pressAnchor);
9651
+ for (const row of this._cells)
9652
+ for (const cell of row)
9653
+ cell.textBuffer.setWidthMethod(method);
9654
+ if (anchor)
9655
+ this._pressAnchor = anchor.getSelection()?.start ?? this._pressAnchor;
9656
+ } finally {
9657
+ anchor?.destroy();
9658
+ }
9659
+ this._cellWidthMethod = method;
9660
+ if (this._lastLocalSelection?.isActive)
9661
+ this._selectionInCells = true;
9662
+ this.invalidateLayout();
9663
+ }
9633
9664
  get content() {
9634
9665
  return this._content;
9635
9666
  }
@@ -9796,9 +9827,14 @@ class TextTableRenderable extends Renderable2 {
9796
9827
  this.ensureLayoutReady();
9797
9828
  const localSelection = convertGlobalToLocalSelection2(selection, Math.trunc(this.x), Math.trunc(this.y));
9798
9829
  this._lastLocalSelection = localSelection;
9830
+ this._selectionInCells = false;
9799
9831
  if (!localSelection?.isActive) {
9800
9832
  this.resetCellSelections();
9801
9833
  this._lastSelectionMode = null;
9834
+ this._pressedCell = null;
9835
+ this._pressPinned = false;
9836
+ this._pressAnchor = null;
9837
+ this._pressMoved = false;
9802
9838
  } else {
9803
9839
  this.applySelectionToCells(localSelection, selection?.isStart ?? false);
9804
9840
  }
@@ -9922,6 +9958,13 @@ class TextTableRenderable extends Renderable2 {
9922
9958
  cells.push(previous[rowIdx]?.slice(0, newColumnCount) ?? []);
9923
9959
  }
9924
9960
  assertCurrent();
9961
+ if (this._cellWidthMethod !== undefined && this._cellWidthMethod !== this._ctx.widthMethod)
9962
+ this.followWidthMethod();
9963
+ const kept = this._selectionInCells ? changes.flatMap(({ row, col }) => {
9964
+ const cell = previous[row]?.[col];
9965
+ const range = cell?.textBufferView.getSelection();
9966
+ return cell && range ? [{ row, col, range, text: cell.textBuffer.getPlainText() }] : [];
9967
+ }) : [];
9925
9968
  const reused = newRowCount === this._rowCount && newColumnCount === this._columnCount && TextBuffer2._replaceStyledTextBatch(changes.map(({ row, col, text }) => ({ ...previous[row][col], text })), assertCurrent);
9926
9969
  try {
9927
9970
  if (!reused) {
@@ -9948,6 +9991,13 @@ class TextTableRenderable extends Renderable2 {
9948
9991
  this._prevCellContent = refs;
9949
9992
  this._rowCount = newRowCount;
9950
9993
  this._columnCount = newColumnCount;
9994
+ this._cellWidthMethod = this._ctx.widthMethod;
9995
+ for (const { row, col, range, text } of kept) {
9996
+ const cell = cells[row][col];
9997
+ if (cell.textBuffer.getPlainText() === text) {
9998
+ cell.textBufferView.setSelection(range.start, range.end, this._selectionBg, this._selectionFg);
9999
+ }
10000
+ }
9951
10001
  this.runCleanup((run) => {
9952
10002
  run(() => this.invalidateLayout());
9953
10003
  for (let rowIdx = 0;rowIdx < previous.length; rowIdx++) {
@@ -10019,7 +10069,7 @@ class TextTableRenderable extends Renderable2 {
10019
10069
  this._layout = layout;
10020
10070
  this.applyLayoutToViews(layout);
10021
10071
  this._layoutDirty = false;
10022
- if (this._lastLocalSelection?.isActive) {
10072
+ if (this._lastLocalSelection?.isActive && !this._selectionInCells) {
10023
10073
  this.applySelectionToCells(this._lastLocalSelection, true);
10024
10074
  }
10025
10075
  }
@@ -10322,9 +10372,23 @@ class TextTableRenderable extends Renderable2 {
10322
10372
  return { rowIdx, colIdx };
10323
10373
  }
10324
10374
  applySelectionToCells(localSelection, isStart) {
10375
+ if (this._pressMoved && !isStart && this._pressedCell)
10376
+ localSelection = { ...localSelection, ...this.movedAnchor() };
10325
10377
  if (localSelection.anchorX === localSelection.focusX && localSelection.anchorY === localSelection.focusY) {
10326
10378
  this.resetCellSelections();
10327
10379
  this._lastSelectionMode = null;
10380
+ if (isStart) {
10381
+ this._pressAnchor = null;
10382
+ this._pressMoved = false;
10383
+ }
10384
+ this._pressedCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
10385
+ this._pressPinned = this._pressedCell !== null;
10386
+ if (this._pressedCell) {
10387
+ const { rowIdx, colIdx } = this._pressedCell;
10388
+ const x = localSelection.anchorX - ((this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPaddingX);
10389
+ const y = localSelection.anchorY - ((this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPaddingY);
10390
+ this._cells[rowIdx][colIdx].textBufferView.setLocalSelection(x, y, x, y, this._selectionBg, this._selectionFg);
10391
+ }
10328
10392
  return;
10329
10393
  }
10330
10394
  const minSelY = Math.min(localSelection.anchorY, localSelection.focusY);
@@ -10365,6 +10429,9 @@ class TextTableRenderable extends Renderable2 {
10365
10429
  if (forceSet) {
10366
10430
  coords = this.getFullCellSelectionCoords(rowIdx, colIdx);
10367
10431
  }
10432
+ if (isAnchorCell && forceSet && this._pressPinned && this._pressAnchor === null) {
10433
+ this._pressAnchor = this.pressOffset(cell.textBufferView);
10434
+ }
10368
10435
  const shouldUseSet = isStart || modeChanged || forceSet;
10369
10436
  if (shouldUseSet) {
10370
10437
  cell.textBufferView.setLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
@@ -10374,6 +10441,43 @@ class TextTableRenderable extends Renderable2 {
10374
10441
  }
10375
10442
  }
10376
10443
  }
10444
+ movedAnchor() {
10445
+ const { rowIdx, colIdx } = this._pressedCell;
10446
+ const view = this._cells[rowIdx][colIdx].textBufferView;
10447
+ const offset = this._pressAnchor ?? this.pressOffset(view);
10448
+ this._pressAnchor = offset;
10449
+ const colors = [this._selectionBg, this._selectionFg];
10450
+ let y = 0;
10451
+ for (let row = 1;row < view.getVirtualLineCount(); row++) {
10452
+ view.setLocalSelection(0, row, 0, 1 << 20, ...colors);
10453
+ const start = view.getSelection()?.start;
10454
+ if (start === undefined || start > offset)
10455
+ break;
10456
+ y = row;
10457
+ }
10458
+ let [low, high] = [0, Math.max(0, (this._layout.columnWidths[colIdx] ?? 0) - this._cellPaddingX * 2)];
10459
+ while (low < high) {
10460
+ const middle = low + high >> 1;
10461
+ view.setLocalSelection(0, y, middle, y, ...colors);
10462
+ if ((view.getSelection()?.end ?? 0) > offset)
10463
+ high = middle;
10464
+ else
10465
+ low = middle + 1;
10466
+ }
10467
+ this._lastSelectionMode = null;
10468
+ return {
10469
+ anchorX: (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPaddingX + low,
10470
+ anchorY: (this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPaddingY + y
10471
+ };
10472
+ }
10473
+ pressOffset(view) {
10474
+ view.updateLocalSelection(0, 0, 0, 1 << 20, this._selectionBg, this._selectionFg);
10475
+ const below = view.getSelection();
10476
+ if (below)
10477
+ return below.start;
10478
+ view.updateLocalSelection(0, 0, 0, -1, this._selectionBg, this._selectionFg);
10479
+ return view.getSelection()?.end ?? 0;
10480
+ }
10377
10481
  resolveSelectionResolution(localSelection) {
10378
10482
  const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
10379
10483
  const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY);
@@ -12774,5 +12878,5 @@ export {
12774
12878
  yellow2 as yellow
12775
12879
  };
12776
12880
 
12777
- //# debugId=1F0E44661199F4FB64756E2164756E21
12881
+ //# debugId=DBEEE44CE6E9F36964756E2164756E21
12778
12882
  //# sourceMappingURL=index.bun.js.map