@opentui/core 0.1.52 → 0.1.54

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
@@ -137,7 +137,7 @@ import {
137
137
  white,
138
138
  wrapWithDelegates,
139
139
  yellow
140
- } from "./index-vhxgbbed.js";
140
+ } from "./index-aedd54rx.js";
141
141
  // src/text-buffer-view.ts
142
142
  class TextBufferView {
143
143
  lib;
@@ -243,6 +243,10 @@ class TextBufferView {
243
243
  this.guard();
244
244
  return this.lib.textBufferViewMeasureForDimensions(this.viewPtr, width, height);
245
245
  }
246
+ getVirtualLineCount() {
247
+ this.guard();
248
+ return this.lib.textBufferViewGetVirtualLineCount(this.viewPtr);
249
+ }
246
250
  destroy() {
247
251
  if (this._destroyed)
248
252
  return;
@@ -2501,6 +2505,9 @@ class TextBufferRenderable extends Renderable {
2501
2505
  get lineCount() {
2502
2506
  return this.textBuffer.getLineCount();
2503
2507
  }
2508
+ get virtualLineCount() {
2509
+ return this.textBufferView.getVirtualLineCount();
2510
+ }
2504
2511
  get scrollY() {
2505
2512
  return this._scrollY;
2506
2513
  }
@@ -2650,6 +2657,7 @@ class TextBufferRenderable extends Renderable {
2650
2657
  }
2651
2658
  onResize(width, height) {
2652
2659
  this.textBufferView.setViewport(this._scrollX, this._scrollY, width, height);
2660
+ this.updateTextInfo();
2653
2661
  if (this.lastLocalSelection) {
2654
2662
  const changed = this.updateLocalSelection(this.lastLocalSelection);
2655
2663
  if (changed) {
@@ -3318,12 +3326,12 @@ class GutterRenderable extends Renderable {
3318
3326
  this._lineNumberOffset = options.lineNumberOffset;
3319
3327
  this._hideLineNumbers = options.hideLineNumbers;
3320
3328
  this._lineNumbers = options.lineNumbers ?? new Map;
3321
- this._lastKnownLineCount = this.target.lineCount;
3329
+ this._lastKnownLineCount = this.target.virtualLineCount;
3322
3330
  this._lastKnownScrollY = this.target.scrollY;
3323
3331
  this.calculateSignWidths();
3324
3332
  this.setupMeasureFunc();
3325
3333
  this.onLifecyclePass = () => {
3326
- const currentLineCount = this.target.lineCount;
3334
+ const currentLineCount = this.target.virtualLineCount;
3327
3335
  if (currentLineCount !== this._lastKnownLineCount) {
3328
3336
  this._lastKnownLineCount = currentLineCount;
3329
3337
  this.yogaNode.markDirty();
@@ -3334,7 +3342,7 @@ class GutterRenderable extends Renderable {
3334
3342
  setupMeasureFunc() {
3335
3343
  const measureFunc = (width, widthMode, height, heightMode) => {
3336
3344
  const gutterWidth = this.calculateWidth();
3337
- const gutterHeight = this.target.lineCount;
3345
+ const gutterHeight = this.target.virtualLineCount;
3338
3346
  return {
3339
3347
  width: gutterWidth,
3340
3348
  height: gutterHeight
@@ -3345,6 +3353,23 @@ class GutterRenderable extends Renderable {
3345
3353
  remeasure() {
3346
3354
  this.yogaNode.markDirty();
3347
3355
  }
3356
+ setLineNumberOffset(offset) {
3357
+ if (this._lineNumberOffset !== offset) {
3358
+ this._lineNumberOffset = offset;
3359
+ this.yogaNode.markDirty();
3360
+ this.requestRender();
3361
+ }
3362
+ }
3363
+ setHideLineNumbers(hideLineNumbers) {
3364
+ this._hideLineNumbers = hideLineNumbers;
3365
+ this.yogaNode.markDirty();
3366
+ this.requestRender();
3367
+ }
3368
+ setLineNumbers(lineNumbers) {
3369
+ this._lineNumbers = lineNumbers;
3370
+ this.yogaNode.markDirty();
3371
+ this.requestRender();
3372
+ }
3348
3373
  calculateSignWidths() {
3349
3374
  this._maxBeforeWidth = 0;
3350
3375
  this._maxAfterWidth = 0;
@@ -3360,7 +3385,7 @@ class GutterRenderable extends Renderable {
3360
3385
  }
3361
3386
  }
3362
3387
  calculateWidth() {
3363
- const totalLines = this.target.lineCount;
3388
+ const totalLines = this.target.virtualLineCount;
3364
3389
  let maxLineNumber = totalLines + this._lineNumberOffset;
3365
3390
  if (this._lineNumbers.size > 0) {
3366
3391
  for (const customLineNum of this._lineNumbers.values()) {
@@ -3564,7 +3589,7 @@ class LineNumberRenderable extends Renderable {
3564
3589
  super.add(this.target);
3565
3590
  }
3566
3591
  add(child) {
3567
- if (!this.target && "lineInfo" in child && "lineCount" in child && "scrollY" in child) {
3592
+ if (!this.target && "lineInfo" in child && "lineCount" in child && "virtualLineCount" in child && "scrollY" in child) {
3568
3593
  this.setTarget(child);
3569
3594
  return this.getChildrenCount() - 1;
3570
3595
  }
@@ -3703,13 +3728,8 @@ class LineNumberRenderable extends Renderable {
3703
3728
  set lineNumberOffset(value) {
3704
3729
  if (this._lineNumberOffset !== value) {
3705
3730
  this._lineNumberOffset = value;
3706
- if (this.gutter && this.target) {
3707
- const target = this.target;
3708
- super.remove(this.gutter.id);
3709
- super.remove(this.target.id);
3710
- this.gutter = null;
3711
- this.target = null;
3712
- this.setTarget(target);
3731
+ if (this.gutter) {
3732
+ this.gutter.setLineNumberOffset(value);
3713
3733
  }
3714
3734
  }
3715
3735
  }
@@ -3718,13 +3738,8 @@ class LineNumberRenderable extends Renderable {
3718
3738
  }
3719
3739
  setHideLineNumbers(hideLineNumbers) {
3720
3740
  this._hideLineNumbers = hideLineNumbers;
3721
- if (this.gutter && this.target) {
3722
- const target = this.target;
3723
- super.remove(this.gutter.id);
3724
- super.remove(this.target.id);
3725
- this.gutter = null;
3726
- this.target = null;
3727
- this.setTarget(target);
3741
+ if (this.gutter) {
3742
+ this.gutter.setHideLineNumbers(hideLineNumbers);
3728
3743
  }
3729
3744
  }
3730
3745
  getHideLineNumbers() {
@@ -3732,13 +3747,8 @@ class LineNumberRenderable extends Renderable {
3732
3747
  }
3733
3748
  setLineNumbers(lineNumbers) {
3734
3749
  this._lineNumbers = lineNumbers;
3735
- if (this.gutter && this.target) {
3736
- const target = this.target;
3737
- super.remove(this.gutter.id);
3738
- super.remove(this.target.id);
3739
- this.gutter = null;
3740
- this.target = null;
3741
- this.setTarget(target);
3750
+ if (this.gutter) {
3751
+ this.gutter.setLineNumbers(lineNumbers);
3742
3752
  }
3743
3753
  }
3744
3754
  getLineNumbers() {
@@ -4569,6 +4579,7 @@ class DiffRenderable extends Renderable {
4569
4579
  _conceal;
4570
4580
  _selectionBg;
4571
4581
  _selectionFg;
4582
+ _treeSitterClient;
4572
4583
  _showLineNumbers;
4573
4584
  _lineNumberFg;
4574
4585
  _lineNumberBg;
@@ -4589,6 +4600,7 @@ class DiffRenderable extends Renderable {
4589
4600
  leftCodeRenderable = null;
4590
4601
  rightCodeRenderable = null;
4591
4602
  pendingRebuild = false;
4603
+ _lastWidth = 0;
4592
4604
  errorTextRenderable = null;
4593
4605
  errorCodeRenderable = null;
4594
4606
  constructor(ctx, options) {
@@ -4601,9 +4613,10 @@ class DiffRenderable extends Renderable {
4601
4613
  this._filetype = options.filetype;
4602
4614
  this._syntaxStyle = options.syntaxStyle;
4603
4615
  this._wrapMode = options.wrapMode;
4604
- this._conceal = options.conceal ?? true;
4616
+ this._conceal = options.conceal ?? false;
4605
4617
  this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined;
4606
4618
  this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined;
4619
+ this._treeSitterClient = options.treeSitterClient;
4607
4620
  this._showLineNumbers = options.showLineNumbers ?? true;
4608
4621
  this._lineNumberFg = parseColor(options.lineNumberFg ?? "#888888");
4609
4622
  this._lineNumberBg = parseColor(options.lineNumberBg ?? "transparent");
@@ -4659,7 +4672,10 @@ class DiffRenderable extends Renderable {
4659
4672
  onResize(width, height) {
4660
4673
  super.onResize(width, height);
4661
4674
  if (this._view === "split" && this._wrapMode !== "none" && this._wrapMode !== undefined) {
4662
- this.requestRebuild();
4675
+ if (this._lastWidth !== width) {
4676
+ this._lastWidth = width;
4677
+ this.requestRebuild();
4678
+ }
4663
4679
  }
4664
4680
  }
4665
4681
  requestRebuild() {
@@ -4726,7 +4742,8 @@ class DiffRenderable extends Renderable {
4726
4742
  conceal: this._conceal,
4727
4743
  width: "100%",
4728
4744
  flexGrow: 1,
4729
- flexShrink: 1
4745
+ flexShrink: 1,
4746
+ ...this._treeSitterClient !== undefined && { treeSitterClient: this._treeSitterClient }
4730
4747
  });
4731
4748
  super.add(this.errorCodeRenderable);
4732
4749
  } else {
@@ -4755,7 +4772,8 @@ class DiffRenderable extends Renderable {
4755
4772
  height: "100%",
4756
4773
  ...drawUnstyledText !== undefined && { drawUnstyledText },
4757
4774
  ...this._selectionBg !== undefined && { selectionBg: this._selectionBg },
4758
- ...this._selectionFg !== undefined && { selectionFg: this._selectionFg }
4775
+ ...this._selectionFg !== undefined && { selectionFg: this._selectionFg },
4776
+ ...this._treeSitterClient !== undefined && { treeSitterClient: this._treeSitterClient }
4759
4777
  };
4760
4778
  const newRenderable = new CodeRenderable(this.ctx, codeOptions);
4761
4779
  if (side === "left") {
@@ -4767,6 +4785,7 @@ class DiffRenderable extends Renderable {
4767
4785
  } else {
4768
4786
  existingRenderable.content = content;
4769
4787
  existingRenderable.wrapMode = wrapMode ?? "none";
4788
+ existingRenderable.conceal = this._conceal;
4770
4789
  if (drawUnstyledText !== undefined) {
4771
4790
  existingRenderable.drawUnstyledText = drawUnstyledText;
4772
4791
  }
@@ -5027,9 +5046,10 @@ class DiffRenderable extends Renderable {
5027
5046
  `);
5028
5047
  const preRightContent = rightLogicalLines.map((l) => l.content).join(`
5029
5048
  `);
5030
- const effectiveWrapMode = canDoWrapAlignment ? this._wrapMode : "none";
5031
- const leftCodeRenderable = this.createOrUpdateCodeRenderable("left", preLeftContent, effectiveWrapMode, true);
5032
- const rightCodeRenderable = this.createOrUpdateCodeRenderable("right", preRightContent, effectiveWrapMode, true);
5049
+ const needsConsistentConcealing = (this._wrapMode === "word" || this._wrapMode === "char") && this._conceal && this._filetype;
5050
+ const drawUnstyledText = !needsConsistentConcealing;
5051
+ const leftCodeRenderable = this.createOrUpdateCodeRenderable("left", preLeftContent, this._wrapMode, drawUnstyledText);
5052
+ const rightCodeRenderable = this.createOrUpdateCodeRenderable("right", preRightContent, this._wrapMode, drawUnstyledText);
5033
5053
  let finalLeftLines;
5034
5054
  let finalRightLines;
5035
5055
  if (canDoWrapAlignment) {
@@ -5383,6 +5403,15 @@ class DiffRenderable extends Renderable {
5383
5403
  }
5384
5404
  }
5385
5405
  }
5406
+ get conceal() {
5407
+ return this._conceal;
5408
+ }
5409
+ set conceal(value) {
5410
+ if (this._conceal !== value) {
5411
+ this._conceal = value;
5412
+ this.rebuildView();
5413
+ }
5414
+ }
5386
5415
  }
5387
5416
  // src/renderables/Input.ts
5388
5417
  var InputRenderableEvents;
@@ -7229,10 +7258,12 @@ class TabSelectRenderable extends Renderable {
7229
7258
  }
7230
7259
  }
7231
7260
  refreshFrameBuffer() {
7232
- if (!this.frameBuffer || this._options.length === 0)
7261
+ if (!this.frameBuffer)
7233
7262
  return;
7234
7263
  const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
7235
7264
  this.frameBuffer.clear(bgColor);
7265
+ if (this._options.length === 0)
7266
+ return;
7236
7267
  const contentX = 0;
7237
7268
  const contentY = 0;
7238
7269
  const contentWidth = this.width;
@@ -7568,6 +7599,9 @@ class EditBufferRenderable extends Renderable {
7568
7599
  get lineCount() {
7569
7600
  return this.editBuffer.getLineCount();
7570
7601
  }
7602
+ get virtualLineCount() {
7603
+ return this.editorView.getVirtualLineCount();
7604
+ }
7571
7605
  get scrollY() {
7572
7606
  return this.editorView.getViewport().offsetY;
7573
7607
  }
@@ -7826,12 +7860,15 @@ class EditBufferRenderable extends Renderable {
7826
7860
  }
7827
7861
  }
7828
7862
  destroy() {
7863
+ if (this.isDestroyed)
7864
+ return;
7829
7865
  if (this._focused) {
7830
7866
  this._ctx.setCursorPosition(0, 0, false);
7867
+ this.blur();
7831
7868
  }
7832
- super.destroy();
7833
7869
  this.editorView.destroy();
7834
7870
  this.editBuffer.destroy();
7871
+ super.destroy();
7835
7872
  }
7836
7873
  set onCursorChange(handler) {
7837
7874
  this._cursorChangeListener = handler;
@@ -8358,7 +8395,9 @@ class TextareaRenderable extends EditBufferRenderable {
8358
8395
  }
8359
8396
  blur() {
8360
8397
  super.blur();
8361
- this.updateColors();
8398
+ if (!this.isDestroyed) {
8399
+ this.updateColors();
8400
+ }
8362
8401
  }
8363
8402
  get placeholder() {
8364
8403
  return this._placeholder;
@@ -8617,5 +8656,5 @@ export {
8617
8656
  ASCIIFont
8618
8657
  };
8619
8658
 
8620
- //# debugId=61DC3DAACFF9549264756E2164756E21
8659
+ //# debugId=04B0510AE1DAC91C64756E2164756E21
8621
8660
  //# sourceMappingURL=index.js.map