@opentui/core 0.1.38 → 0.1.40

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
@@ -136,7 +136,7 @@ import {
136
136
  white,
137
137
  wrapWithDelegates,
138
138
  yellow
139
- } from "./index-7bav3fax.js";
139
+ } from "./index-kj9k00yt.js";
140
140
  // src/text-buffer-view.ts
141
141
  class TextBufferView {
142
142
  lib;
@@ -2661,9 +2661,8 @@ class CodeRenderable extends TextBufferRenderable {
2661
2661
  _syntaxStyle;
2662
2662
  _isHighlighting = false;
2663
2663
  _treeSitterClient;
2664
- _pendingRehighlight = false;
2665
- _pendingUpdate = false;
2666
- _currentHighlightId = 0;
2664
+ _highlightsDirty = false;
2665
+ _highlightSnapshotId = 0;
2667
2666
  _conceal;
2668
2667
  _drawUnstyledText;
2669
2668
  _shouldRenderTextBuffer = true;
@@ -2685,7 +2684,7 @@ class CodeRenderable extends TextBufferRenderable {
2685
2684
  this._conceal = options.conceal ?? this._contentDefaultOptions.conceal;
2686
2685
  this._drawUnstyledText = options.drawUnstyledText ?? this._contentDefaultOptions.drawUnstyledText;
2687
2686
  this._streaming = options.streaming ?? this._contentDefaultOptions.streaming;
2688
- this.updateContent(this._content);
2687
+ this._highlightsDirty = this._content.length > 0;
2689
2688
  }
2690
2689
  get content() {
2691
2690
  return this._content;
@@ -2693,7 +2692,7 @@ class CodeRenderable extends TextBufferRenderable {
2693
2692
  set content(value) {
2694
2693
  if (this._content !== value) {
2695
2694
  this._content = value;
2696
- this.scheduleUpdate();
2695
+ this._highlightsDirty = true;
2697
2696
  }
2698
2697
  }
2699
2698
  get filetype() {
@@ -2702,7 +2701,7 @@ class CodeRenderable extends TextBufferRenderable {
2702
2701
  set filetype(value) {
2703
2702
  if (this._filetype !== value) {
2704
2703
  this._filetype = value;
2705
- this.scheduleUpdate();
2704
+ this._highlightsDirty = true;
2706
2705
  }
2707
2706
  }
2708
2707
  get syntaxStyle() {
@@ -2711,7 +2710,7 @@ class CodeRenderable extends TextBufferRenderable {
2711
2710
  set syntaxStyle(value) {
2712
2711
  if (this._syntaxStyle !== value) {
2713
2712
  this._syntaxStyle = value;
2714
- this.scheduleUpdate();
2713
+ this._highlightsDirty = true;
2715
2714
  }
2716
2715
  }
2717
2716
  get conceal() {
@@ -2720,7 +2719,7 @@ class CodeRenderable extends TextBufferRenderable {
2720
2719
  set conceal(value) {
2721
2720
  if (this._conceal !== value) {
2722
2721
  this._conceal = value;
2723
- this.scheduleUpdate();
2722
+ this._highlightsDirty = true;
2724
2723
  }
2725
2724
  }
2726
2725
  get drawUnstyledText() {
@@ -2729,7 +2728,7 @@ class CodeRenderable extends TextBufferRenderable {
2729
2728
  set drawUnstyledText(value) {
2730
2729
  if (this._drawUnstyledText !== value) {
2731
2730
  this._drawUnstyledText = value;
2732
- this.scheduleUpdate();
2731
+ this._highlightsDirty = true;
2733
2732
  }
2734
2733
  }
2735
2734
  get streaming() {
@@ -2740,7 +2739,7 @@ class CodeRenderable extends TextBufferRenderable {
2740
2739
  this._streaming = value;
2741
2740
  this._hadInitialContent = false;
2742
2741
  this._lastHighlights = [];
2743
- this.scheduleUpdate();
2742
+ this._highlightsDirty = true;
2744
2743
  }
2745
2744
  }
2746
2745
  get treeSitterClient() {
@@ -2749,39 +2748,21 @@ class CodeRenderable extends TextBufferRenderable {
2749
2748
  set treeSitterClient(value) {
2750
2749
  if (this._treeSitterClient !== value) {
2751
2750
  this._treeSitterClient = value;
2752
- this.scheduleUpdate();
2751
+ this._highlightsDirty = true;
2753
2752
  }
2754
2753
  }
2755
- scheduleUpdate() {
2756
- if (this._pendingUpdate)
2757
- return;
2758
- this._pendingUpdate = true;
2759
- queueMicrotask(() => {
2760
- this._pendingUpdate = false;
2761
- this.updateContent(this._content);
2762
- });
2763
- }
2764
- async updateContent(content) {
2765
- if (content.length === 0)
2766
- return;
2754
+ ensureVisibleTextBeforeHighlight() {
2755
+ const content = this._content;
2767
2756
  if (!this._filetype) {
2768
- this.fallback(content);
2757
+ if (this.isDestroyed)
2758
+ return;
2759
+ this.textBuffer.setText(content);
2769
2760
  this._shouldRenderTextBuffer = true;
2761
+ this.updateTextInfo();
2770
2762
  return;
2771
2763
  }
2772
- this._currentHighlightId++;
2773
- const highlightId = this._currentHighlightId;
2774
2764
  const isInitialContent = this._streaming && !this._hadInitialContent;
2775
- if (isInitialContent) {
2776
- this._hadInitialContent = true;
2777
- }
2778
2765
  const shouldDrawUnstyledNow = this._streaming ? isInitialContent && this._drawUnstyledText : this._drawUnstyledText;
2779
- if (!shouldDrawUnstyledNow) {
2780
- this._shouldRenderTextBuffer = false;
2781
- } else {
2782
- this._shouldRenderTextBuffer = true;
2783
- this.fallback(content);
2784
- }
2785
2766
  if (this._streaming && !isInitialContent) {
2786
2767
  if (this._lastHighlights.length > 0) {
2787
2768
  const chunks = treeSitterToTextChunks(content, this._lastHighlights, this._syntaxStyle, {
@@ -2794,15 +2775,39 @@ class CodeRenderable extends TextBufferRenderable {
2794
2775
  this._shouldRenderTextBuffer = true;
2795
2776
  this.updateTextInfo();
2796
2777
  } else {
2797
- this.fallback(content);
2778
+ if (this.isDestroyed)
2779
+ return;
2780
+ this.textBuffer.setText(content);
2798
2781
  this._shouldRenderTextBuffer = true;
2782
+ this.updateTextInfo();
2799
2783
  }
2784
+ } else if (shouldDrawUnstyledNow) {
2785
+ if (this.isDestroyed)
2786
+ return;
2787
+ this.textBuffer.setText(content);
2788
+ this._shouldRenderTextBuffer = true;
2789
+ this.updateTextInfo();
2790
+ } else {
2791
+ if (this.isDestroyed)
2792
+ return;
2793
+ this._shouldRenderTextBuffer = false;
2794
+ this.updateTextInfo();
2795
+ }
2796
+ }
2797
+ async startHighlight() {
2798
+ const content = this._content;
2799
+ const filetype = this._filetype;
2800
+ const snapshotId = ++this._highlightSnapshotId;
2801
+ if (!filetype)
2802
+ return;
2803
+ const isInitialContent = this._streaming && !this._hadInitialContent;
2804
+ if (isInitialContent) {
2805
+ this._hadInitialContent = true;
2800
2806
  }
2801
2807
  this._isHighlighting = true;
2802
- this._pendingRehighlight = false;
2803
2808
  try {
2804
- const result = await this._treeSitterClient.highlightOnce(content, this._filetype);
2805
- if (highlightId !== this._currentHighlightId) {
2809
+ const result = await this._treeSitterClient.highlightOnce(content, filetype);
2810
+ if (snapshotId !== this._highlightSnapshotId) {
2806
2811
  return;
2807
2812
  }
2808
2813
  if (this.isDestroyed)
@@ -2817,46 +2822,53 @@ class CodeRenderable extends TextBufferRenderable {
2817
2822
  const styledText = new StyledText(chunks);
2818
2823
  this.textBuffer.setStyledText(styledText);
2819
2824
  } else {
2820
- this.fallback(content);
2825
+ this.textBuffer.setText(content);
2821
2826
  }
2822
2827
  this._shouldRenderTextBuffer = true;
2823
2828
  this.updateTextInfo();
2829
+ this._isHighlighting = false;
2830
+ this._highlightsDirty = false;
2831
+ this.requestRender();
2824
2832
  } catch (error) {
2825
- if (highlightId !== this._currentHighlightId) {
2833
+ if (snapshotId !== this._highlightSnapshotId) {
2826
2834
  return;
2827
2835
  }
2828
2836
  console.warn("Code highlighting failed, falling back to plain text:", error);
2829
- this.fallback(content);
2837
+ if (this.isDestroyed)
2838
+ return;
2839
+ this.textBuffer.setText(content);
2830
2840
  this._shouldRenderTextBuffer = true;
2831
- } finally {
2832
- if (highlightId === this._currentHighlightId) {
2833
- this._isHighlighting = false;
2834
- }
2841
+ this.updateTextInfo();
2842
+ this._isHighlighting = false;
2843
+ this._highlightsDirty = false;
2844
+ this.requestRender();
2835
2845
  }
2836
2846
  }
2837
- fallback(content) {
2838
- const fallbackStyledText = this.createFallbackStyledText(content);
2839
- if (this.isDestroyed)
2840
- return;
2841
- this.textBuffer.setStyledText(fallbackStyledText);
2842
- this.updateTextInfo();
2843
- }
2844
- createFallbackStyledText(content) {
2845
- const chunks = [
2846
- {
2847
- __isChunk: true,
2848
- text: content,
2849
- fg: this._defaultFg,
2850
- bg: this._defaultBg,
2851
- attributes: this._defaultAttributes
2852
- }
2853
- ];
2854
- return new StyledText(chunks);
2855
- }
2856
2847
  getLineHighlights(lineIdx) {
2857
2848
  return this.textBuffer.getLineHighlights(lineIdx);
2858
2849
  }
2859
2850
  renderSelf(buffer) {
2851
+ if (this._highlightsDirty) {
2852
+ if (this._content.length === 0) {
2853
+ if (this.isDestroyed)
2854
+ return;
2855
+ this.textBuffer.setText("");
2856
+ this._shouldRenderTextBuffer = false;
2857
+ this._highlightsDirty = false;
2858
+ this.updateTextInfo();
2859
+ } else if (!this._filetype) {
2860
+ if (this.isDestroyed)
2861
+ return;
2862
+ this.textBuffer.setText(this._content);
2863
+ this._shouldRenderTextBuffer = true;
2864
+ this._highlightsDirty = false;
2865
+ this.updateTextInfo();
2866
+ } else {
2867
+ this.ensureVisibleTextBeforeHighlight();
2868
+ this._highlightsDirty = false;
2869
+ this.startHighlight();
2870
+ }
2871
+ }
2860
2872
  if (!this._shouldRenderTextBuffer)
2861
2873
  return;
2862
2874
  super.renderSelf(buffer);
@@ -4214,12 +4226,7 @@ class ScrollBoxRenderable extends BoxRenderable {
4214
4226
  this.internalId = ScrollBoxRenderable.idCounter++;
4215
4227
  this._stickyScroll = stickyScroll;
4216
4228
  this._stickyStart = stickyStart;
4217
- if (scrollAcceleration) {
4218
- this.scrollAccel = scrollAcceleration;
4219
- } else if (process.platform === "darwin") {
4220
- this.scrollAccel = new MacOSScrollAccel;
4221
- }
4222
- this.scrollAccel ??= new LinearScrollAccel;
4229
+ this.scrollAccel = scrollAcceleration ?? new LinearScrollAccel;
4223
4230
  this.wrapper = new BoxRenderable(ctx, {
4224
4231
  flexDirection: "column",
4225
4232
  flexGrow: 1,
@@ -5751,7 +5758,7 @@ function mergeKeyBindings(defaults, custom) {
5751
5758
  return Array.from(map.values());
5752
5759
  }
5753
5760
  function getKeyBindingKey(binding) {
5754
- return `${binding.name}:${!!binding.ctrl}:${!!binding.shift}:${!!binding.meta}`;
5761
+ return `${binding.name}:${binding.ctrl ? 1 : 0}:${binding.shift ? 1 : 0}:${binding.meta ? 1 : 0}:${binding.super ? 1 : 0}`;
5755
5762
  }
5756
5763
  function buildKeyBindingsMap(bindings) {
5757
5764
  const map = new Map;
@@ -5778,27 +5785,35 @@ var defaultTextareaKeybindings = [
5778
5785
  { name: "end", shift: true, action: "select-line-end" },
5779
5786
  { name: "a", ctrl: true, action: "buffer-home" },
5780
5787
  { name: "e", ctrl: true, action: "buffer-end" },
5781
- { name: "d", ctrl: true, action: "delete-line" },
5788
+ { name: "f", ctrl: true, action: "move-right" },
5789
+ { name: "b", ctrl: true, action: "move-left" },
5790
+ { name: "d", ctrl: true, action: "delete-word-forward" },
5791
+ { name: "w", ctrl: true, action: "delete-word-backward" },
5782
5792
  { name: "k", ctrl: true, action: "delete-to-line-end" },
5793
+ { name: "u", ctrl: true, action: "delete-to-line-start" },
5783
5794
  { name: "backspace", action: "backspace" },
5795
+ { name: "backspace", shift: true, action: "backspace" },
5784
5796
  { name: "delete", action: "delete" },
5797
+ { name: "delete", shift: true, action: "delete" },
5785
5798
  { name: "return", action: "newline" },
5786
5799
  { name: "linefeed", action: "newline" },
5787
5800
  { name: "return", meta: true, action: "submit" },
5801
+ { name: "-", ctrl: true, action: "undo" },
5788
5802
  { name: "z", ctrl: true, action: "undo" },
5789
- { name: "Z", ctrl: true, shift: true, action: "redo" },
5803
+ { name: ".", ctrl: true, action: "redo" },
5790
5804
  { name: "y", ctrl: true, action: "redo" },
5805
+ { name: "z", super: true, action: "undo" },
5806
+ { name: "z", super: true, shift: true, action: "redo" },
5791
5807
  { name: "f", meta: true, action: "word-forward" },
5792
5808
  { name: "b", meta: true, action: "word-backward" },
5793
5809
  { name: "right", meta: true, action: "word-forward" },
5794
5810
  { name: "left", meta: true, action: "word-backward" },
5795
- { name: "F", meta: true, shift: true, action: "select-word-forward" },
5796
- { name: "B", meta: true, shift: true, action: "select-word-backward" },
5811
+ { name: "f", meta: true, shift: true, action: "select-word-forward" },
5812
+ { name: "b", meta: true, shift: true, action: "select-word-backward" },
5797
5813
  { name: "right", meta: true, shift: true, action: "select-word-forward" },
5798
5814
  { name: "left", meta: true, shift: true, action: "select-word-backward" },
5799
- { name: "d", meta: true, action: "delete-word-forward" },
5800
- { name: "backspace", meta: true, action: "delete-word-backward" },
5801
- { name: "w", ctrl: true, action: "delete-word-backward" }
5815
+ { name: "d", meta: true, action: "delete-line" },
5816
+ { name: "backspace", meta: true, action: "delete-word-backward" }
5802
5817
  ];
5803
5818
 
5804
5819
  class TextareaRenderable extends EditBufferRenderable {
@@ -5873,6 +5888,7 @@ class TextareaRenderable extends EditBufferRenderable {
5873
5888
  ["buffer-end", () => this.gotoBufferEnd()],
5874
5889
  ["delete-line", () => this.deleteLine()],
5875
5890
  ["delete-to-line-end", () => this.deleteToLineEnd()],
5891
+ ["delete-to-line-start", () => this.deleteToLineStart()],
5876
5892
  ["backspace", () => this.deleteCharBackward()],
5877
5893
  ["delete", () => this.deleteChar()],
5878
5894
  ["newline", () => this.newLine()],
@@ -5896,11 +5912,13 @@ class TextareaRenderable extends EditBufferRenderable {
5896
5912
  const keyCtrl = typeof key === "string" ? false : key.ctrl;
5897
5913
  const keyShift = typeof key === "string" ? false : key.shift;
5898
5914
  const keyMeta = typeof key === "string" ? false : key.meta;
5915
+ const keySuper = typeof key === "string" ? false : key.super;
5899
5916
  const bindingKey = getKeyBindingKey({
5900
5917
  name: keyName,
5901
5918
  ctrl: keyCtrl,
5902
5919
  shift: keyShift,
5903
5920
  meta: keyMeta,
5921
+ super: keySuper,
5904
5922
  action: "move-left"
5905
5923
  });
5906
5924
  const action = this._keyBindingsMap.get(bindingKey);
@@ -6053,6 +6071,14 @@ class TextareaRenderable extends EditBufferRenderable {
6053
6071
  this.requestRender();
6054
6072
  return true;
6055
6073
  }
6074
+ deleteToLineStart() {
6075
+ const cursor = this.editorView.getCursor();
6076
+ if (cursor.col > 0) {
6077
+ this.editBuffer.deleteRange(cursor.row, 0, cursor.row, cursor.col);
6078
+ }
6079
+ this.requestRender();
6080
+ return true;
6081
+ }
6056
6082
  undo() {
6057
6083
  this._ctx.clearSelection();
6058
6084
  this.editBuffer.undo();
@@ -6393,5 +6419,5 @@ export {
6393
6419
  ASCIIFont
6394
6420
  };
6395
6421
 
6396
- //# debugId=5DEE20591CE7786764756E2164756E21
6422
+ //# debugId=99E699B0AAD092B264756E2164756E21
6397
6423
  //# sourceMappingURL=index.js.map