@opentui/core 0.1.61 → 0.1.63
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/3d.js +1 -1
- package/editor-view.d.ts +4 -1
- package/{index-rysm4rsr.js → index-689t9q65.js} +102 -34
- package/{index-rysm4rsr.js.map → index-689t9q65.js.map} +8 -8
- package/index.js +126 -52
- package/index.js.map +6 -6
- package/lib/selection.d.ts +4 -4
- package/package.json +7 -7
- package/renderables/EditBufferRenderable.d.ts +10 -1
- package/renderer.d.ts +18 -6
- package/testing/test-recorder.d.ts +16 -1
- package/testing.js +21 -5
- package/testing.js.map +3 -3
- package/text-buffer-view.d.ts +2 -0
- package/zig.d.ts +6 -1
package/index.js
CHANGED
|
@@ -143,7 +143,7 @@ import {
|
|
|
143
143
|
white,
|
|
144
144
|
wrapWithDelegates,
|
|
145
145
|
yellow
|
|
146
|
-
} from "./index-
|
|
146
|
+
} from "./index-689t9q65.js";
|
|
147
147
|
// src/text-buffer-view.ts
|
|
148
148
|
class TextBufferView {
|
|
149
149
|
lib;
|
|
@@ -172,6 +172,10 @@ class TextBufferView {
|
|
|
172
172
|
this.guard();
|
|
173
173
|
this.lib.textBufferViewSetSelection(this.viewPtr, start, end, bgColor || null, fgColor || null);
|
|
174
174
|
}
|
|
175
|
+
updateSelection(end, bgColor, fgColor) {
|
|
176
|
+
this.guard();
|
|
177
|
+
this.lib.textBufferViewUpdateSelection(this.viewPtr, end, bgColor || null, fgColor || null);
|
|
178
|
+
}
|
|
175
179
|
resetSelection() {
|
|
176
180
|
this.guard();
|
|
177
181
|
this.lib.textBufferViewResetSelection(this.viewPtr);
|
|
@@ -188,6 +192,10 @@ class TextBufferView {
|
|
|
188
192
|
this.guard();
|
|
189
193
|
return this.lib.textBufferViewSetLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
190
194
|
}
|
|
195
|
+
updateLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
196
|
+
this.guard();
|
|
197
|
+
return this.lib.textBufferViewUpdateLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
198
|
+
}
|
|
191
199
|
resetLocalSelection() {
|
|
192
200
|
this.guard();
|
|
193
201
|
this.lib.textBufferViewResetLocalSelection(this.viewPtr);
|
|
@@ -601,6 +609,10 @@ class EditorView {
|
|
|
601
609
|
this.guard();
|
|
602
610
|
this.lib.editorViewSetViewportSize(this.viewPtr, width, height);
|
|
603
611
|
}
|
|
612
|
+
setViewport(x, y, width, height, moveCursor = true) {
|
|
613
|
+
this.guard();
|
|
614
|
+
this.lib.editorViewSetViewport(this.viewPtr, x, y, width, height, moveCursor);
|
|
615
|
+
}
|
|
604
616
|
getViewport() {
|
|
605
617
|
this.guard();
|
|
606
618
|
return this.lib.editorViewGetViewport(this.viewPtr);
|
|
@@ -625,6 +637,10 @@ class EditorView {
|
|
|
625
637
|
this.guard();
|
|
626
638
|
this.lib.editorViewSetSelection(this.viewPtr, start, end, bgColor || null, fgColor || null);
|
|
627
639
|
}
|
|
640
|
+
updateSelection(end, bgColor, fgColor) {
|
|
641
|
+
this.guard();
|
|
642
|
+
this.lib.editorViewUpdateSelection(this.viewPtr, end, bgColor || null, fgColor || null);
|
|
643
|
+
}
|
|
628
644
|
resetSelection() {
|
|
629
645
|
this.guard();
|
|
630
646
|
this.lib.editorViewResetSelection(this.viewPtr);
|
|
@@ -637,9 +653,13 @@ class EditorView {
|
|
|
637
653
|
this.guard();
|
|
638
654
|
return this.getSelection() !== null;
|
|
639
655
|
}
|
|
640
|
-
setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
656
|
+
setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor, updateCursor) {
|
|
641
657
|
this.guard();
|
|
642
|
-
return this.lib.editorViewSetLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
658
|
+
return this.lib.editorViewSetLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null, updateCursor ?? false);
|
|
659
|
+
}
|
|
660
|
+
updateLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor, updateCursor) {
|
|
661
|
+
this.guard();
|
|
662
|
+
return this.lib.editorViewUpdateLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null, updateCursor ?? false);
|
|
643
663
|
}
|
|
644
664
|
resetLocalSelection() {
|
|
645
665
|
this.guard();
|
|
@@ -2675,13 +2695,9 @@ class TextBufferRenderable extends Renderable {
|
|
|
2675
2695
|
}
|
|
2676
2696
|
onResize(width, height) {
|
|
2677
2697
|
this.textBufferView.setViewport(this._scrollX, this._scrollY, width, height);
|
|
2678
|
-
this.
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
if (changed) {
|
|
2682
|
-
this.requestRender();
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2698
|
+
this.yogaNode.markDirty();
|
|
2699
|
+
this.requestRender();
|
|
2700
|
+
this.emit("line-info-change");
|
|
2685
2701
|
}
|
|
2686
2702
|
refreshLocalSelection() {
|
|
2687
2703
|
if (this.lastLocalSelection) {
|
|
@@ -2739,7 +2755,15 @@ class TextBufferRenderable extends Renderable {
|
|
|
2739
2755
|
onSelectionChanged(selection) {
|
|
2740
2756
|
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
2741
2757
|
this.lastLocalSelection = localSelection;
|
|
2742
|
-
|
|
2758
|
+
let changed;
|
|
2759
|
+
if (!localSelection?.isActive) {
|
|
2760
|
+
this.textBufferView.resetLocalSelection();
|
|
2761
|
+
changed = true;
|
|
2762
|
+
} else if (selection?.isStart) {
|
|
2763
|
+
changed = this.textBufferView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
2764
|
+
} else {
|
|
2765
|
+
changed = this.textBufferView.updateLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
2766
|
+
}
|
|
2743
2767
|
if (changed) {
|
|
2744
2768
|
this.requestRender();
|
|
2745
2769
|
}
|
|
@@ -7668,9 +7692,11 @@ class EditBufferRenderable extends Renderable {
|
|
|
7668
7692
|
lastLocalSelection = null;
|
|
7669
7693
|
_tabIndicator;
|
|
7670
7694
|
_tabIndicatorColor;
|
|
7671
|
-
_selectionAnchorState = null;
|
|
7672
7695
|
_cursorChangeListener = undefined;
|
|
7673
7696
|
_contentChangeListener = undefined;
|
|
7697
|
+
_autoScrollVelocity = 0;
|
|
7698
|
+
_autoScrollAccumulator = 0;
|
|
7699
|
+
_scrollSpeed = 16;
|
|
7674
7700
|
editBuffer;
|
|
7675
7701
|
editorView;
|
|
7676
7702
|
_defaultOptions = {
|
|
@@ -7682,6 +7708,7 @@ class EditBufferRenderable extends Renderable {
|
|
|
7682
7708
|
attributes: 0,
|
|
7683
7709
|
wrapMode: "word",
|
|
7684
7710
|
scrollMargin: 0.2,
|
|
7711
|
+
scrollSpeed: 16,
|
|
7685
7712
|
showCursor: true,
|
|
7686
7713
|
cursorColor: RGBA.fromValues(1, 1, 1, 1),
|
|
7687
7714
|
cursorStyle: {
|
|
@@ -7701,6 +7728,7 @@ class EditBufferRenderable extends Renderable {
|
|
|
7701
7728
|
this.selectable = options.selectable ?? this._defaultOptions.selectable;
|
|
7702
7729
|
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
7703
7730
|
this._scrollMargin = options.scrollMargin ?? this._defaultOptions.scrollMargin;
|
|
7731
|
+
this._scrollSpeed = options.scrollSpeed ?? this._defaultOptions.scrollSpeed;
|
|
7704
7732
|
this._showCursor = options.showCursor ?? this._defaultOptions.showCursor;
|
|
7705
7733
|
this._cursorColor = parseColor(options.cursorColor ?? this._defaultOptions.cursorColor);
|
|
7706
7734
|
this._cursorStyle = options.cursorStyle ?? this._defaultOptions.cursorStyle;
|
|
@@ -7901,15 +7929,48 @@ class EditBufferRenderable extends Renderable {
|
|
|
7901
7929
|
this.requestRender();
|
|
7902
7930
|
}
|
|
7903
7931
|
}
|
|
7904
|
-
|
|
7905
|
-
this.
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7932
|
+
get scrollSpeed() {
|
|
7933
|
+
return this._scrollSpeed;
|
|
7934
|
+
}
|
|
7935
|
+
set scrollSpeed(value) {
|
|
7936
|
+
this._scrollSpeed = Math.max(0, value);
|
|
7937
|
+
}
|
|
7938
|
+
onMouseEvent(event) {
|
|
7939
|
+
if (event.type === "scroll") {
|
|
7940
|
+
this.handleScroll(event);
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
handleScroll(event) {
|
|
7944
|
+
if (!event.scroll)
|
|
7945
|
+
return;
|
|
7946
|
+
const { direction, delta } = event.scroll;
|
|
7947
|
+
const viewport = this.editorView.getViewport();
|
|
7948
|
+
if (direction === "up") {
|
|
7949
|
+
const newOffsetY = Math.max(0, viewport.offsetY - delta);
|
|
7950
|
+
this.editorView.setViewport(viewport.offsetX, newOffsetY, viewport.width, viewport.height, true);
|
|
7951
|
+
this.requestRender();
|
|
7952
|
+
} else if (direction === "down") {
|
|
7953
|
+
const totalVirtualLines = this.editorView.getTotalVirtualLineCount();
|
|
7954
|
+
const maxOffsetY = Math.max(0, totalVirtualLines - viewport.height);
|
|
7955
|
+
const newOffsetY = Math.min(viewport.offsetY + delta, maxOffsetY);
|
|
7956
|
+
this.editorView.setViewport(viewport.offsetX, newOffsetY, viewport.width, viewport.height, true);
|
|
7957
|
+
this.requestRender();
|
|
7958
|
+
}
|
|
7959
|
+
if (this._wrapMode === "none") {
|
|
7960
|
+
if (direction === "left") {
|
|
7961
|
+
const newOffsetX = Math.max(0, viewport.offsetX - delta);
|
|
7962
|
+
this.editorView.setViewport(newOffsetX, viewport.offsetY, viewport.width, viewport.height, true);
|
|
7963
|
+
this.requestRender();
|
|
7964
|
+
} else if (direction === "right") {
|
|
7965
|
+
const newOffsetX = viewport.offsetX + delta;
|
|
7966
|
+
this.editorView.setViewport(newOffsetX, viewport.offsetY, viewport.width, viewport.height, true);
|
|
7909
7967
|
this.requestRender();
|
|
7910
7968
|
}
|
|
7911
7969
|
}
|
|
7912
7970
|
}
|
|
7971
|
+
onResize(width, height) {
|
|
7972
|
+
this.editorView.setViewportSize(width, height);
|
|
7973
|
+
}
|
|
7913
7974
|
refreshLocalSelection() {
|
|
7914
7975
|
if (this.lastLocalSelection) {
|
|
7915
7976
|
return this.updateLocalSelection(this.lastLocalSelection);
|
|
@@ -7921,7 +7982,7 @@ class EditBufferRenderable extends Renderable {
|
|
|
7921
7982
|
this.editorView.resetLocalSelection();
|
|
7922
7983
|
return true;
|
|
7923
7984
|
}
|
|
7924
|
-
return this.editorView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
7985
|
+
return this.editorView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg, false);
|
|
7925
7986
|
}
|
|
7926
7987
|
shouldStartSelection(x, y) {
|
|
7927
7988
|
if (!this.selectable)
|
|
@@ -7933,12 +7994,56 @@ class EditBufferRenderable extends Renderable {
|
|
|
7933
7994
|
onSelectionChanged(selection) {
|
|
7934
7995
|
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
7935
7996
|
this.lastLocalSelection = localSelection;
|
|
7936
|
-
const
|
|
7997
|
+
const updateCursor = true;
|
|
7998
|
+
let changed;
|
|
7999
|
+
if (!localSelection?.isActive) {
|
|
8000
|
+
this.editorView.resetLocalSelection();
|
|
8001
|
+
changed = true;
|
|
8002
|
+
} else if (selection?.isStart) {
|
|
8003
|
+
changed = this.editorView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg, updateCursor);
|
|
8004
|
+
} else {
|
|
8005
|
+
changed = this.editorView.updateLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg, updateCursor);
|
|
8006
|
+
}
|
|
8007
|
+
if (changed && localSelection?.isActive && selection?.isSelecting) {
|
|
8008
|
+
const viewport = this.editorView.getViewport();
|
|
8009
|
+
const focusY = localSelection.focusY;
|
|
8010
|
+
const scrollMargin = Math.max(1, Math.floor(viewport.height * this._scrollMargin));
|
|
8011
|
+
if (focusY < scrollMargin) {
|
|
8012
|
+
this._autoScrollVelocity = -this._scrollSpeed;
|
|
8013
|
+
} else if (focusY >= viewport.height - scrollMargin) {
|
|
8014
|
+
this._autoScrollVelocity = this._scrollSpeed;
|
|
8015
|
+
} else {
|
|
8016
|
+
this._autoScrollVelocity = 0;
|
|
8017
|
+
}
|
|
8018
|
+
} else {
|
|
8019
|
+
this._autoScrollVelocity = 0;
|
|
8020
|
+
this._autoScrollAccumulator = 0;
|
|
8021
|
+
}
|
|
7937
8022
|
if (changed) {
|
|
7938
8023
|
this.requestRender();
|
|
7939
8024
|
}
|
|
7940
8025
|
return this.hasSelection();
|
|
7941
8026
|
}
|
|
8027
|
+
onUpdate(deltaTime) {
|
|
8028
|
+
super.onUpdate(deltaTime);
|
|
8029
|
+
if (this._autoScrollVelocity !== 0 && this.hasSelection()) {
|
|
8030
|
+
const deltaSeconds = deltaTime / 1000;
|
|
8031
|
+
this._autoScrollAccumulator += this._autoScrollVelocity * deltaSeconds;
|
|
8032
|
+
const linesToScroll = Math.floor(Math.abs(this._autoScrollAccumulator));
|
|
8033
|
+
if (linesToScroll > 0) {
|
|
8034
|
+
const direction = this._autoScrollVelocity > 0 ? 1 : -1;
|
|
8035
|
+
const viewport = this.editorView.getViewport();
|
|
8036
|
+
const totalVirtualLines = this.editorView.getTotalVirtualLineCount();
|
|
8037
|
+
const maxOffsetY = Math.max(0, totalVirtualLines - viewport.height);
|
|
8038
|
+
const newOffsetY = Math.max(0, Math.min(viewport.offsetY + direction * linesToScroll, maxOffsetY));
|
|
8039
|
+
if (newOffsetY !== viewport.offsetY) {
|
|
8040
|
+
this.editorView.setViewport(viewport.offsetX, newOffsetY, viewport.width, viewport.height, false);
|
|
8041
|
+
this._ctx.requestSelectionUpdate();
|
|
8042
|
+
}
|
|
8043
|
+
this._autoScrollAccumulator -= direction * linesToScroll;
|
|
8044
|
+
}
|
|
8045
|
+
}
|
|
8046
|
+
}
|
|
7942
8047
|
getSelectedText() {
|
|
7943
8048
|
return this.editorView.getSelectedText();
|
|
7944
8049
|
}
|
|
@@ -8102,48 +8207,17 @@ class EditBufferRenderable extends Renderable {
|
|
|
8102
8207
|
return;
|
|
8103
8208
|
if (!shiftPressed) {
|
|
8104
8209
|
this._ctx.clearSelection();
|
|
8105
|
-
this._selectionAnchorState = null;
|
|
8106
8210
|
return;
|
|
8107
8211
|
}
|
|
8108
8212
|
const visualCursor = this.editorView.getVisualCursor();
|
|
8109
|
-
const viewport = this.editorView.getViewport();
|
|
8110
8213
|
const cursorX = this.x + visualCursor.visualCol;
|
|
8111
8214
|
const cursorY = this.y + visualCursor.visualRow;
|
|
8112
8215
|
if (isBeforeMovement) {
|
|
8113
8216
|
if (!this._ctx.hasSelection) {
|
|
8114
8217
|
this._ctx.startSelection(this, cursorX, cursorY);
|
|
8115
|
-
this._selectionAnchorState = {
|
|
8116
|
-
screenX: cursorX,
|
|
8117
|
-
screenY: cursorY,
|
|
8118
|
-
viewportX: viewport.offsetX,
|
|
8119
|
-
viewportY: viewport.offsetY
|
|
8120
|
-
};
|
|
8121
|
-
} else if (!this._selectionAnchorState) {
|
|
8122
|
-
const selection = this._ctx.getSelection();
|
|
8123
|
-
if (selection && selection.isActive) {
|
|
8124
|
-
this._selectionAnchorState = {
|
|
8125
|
-
screenX: selection.anchor.x,
|
|
8126
|
-
screenY: selection.anchor.y,
|
|
8127
|
-
viewportX: viewport.offsetX,
|
|
8128
|
-
viewportY: viewport.offsetY
|
|
8129
|
-
};
|
|
8130
|
-
}
|
|
8131
8218
|
}
|
|
8132
8219
|
} else {
|
|
8133
|
-
|
|
8134
|
-
const deltaY = viewport.offsetY - this._selectionAnchorState.viewportY;
|
|
8135
|
-
const deltaX = viewport.offsetX - this._selectionAnchorState.viewportX;
|
|
8136
|
-
if (deltaY !== 0 || deltaX !== 0) {
|
|
8137
|
-
const newAnchorX = this._selectionAnchorState.screenX - deltaX;
|
|
8138
|
-
const newAnchorY = this._selectionAnchorState.screenY - deltaY;
|
|
8139
|
-
this._ctx.startSelection(this, newAnchorX, newAnchorY);
|
|
8140
|
-
this._ctx.updateSelection(this, cursorX, cursorY);
|
|
8141
|
-
} else {
|
|
8142
|
-
this._ctx.updateSelection(this, cursorX, cursorY);
|
|
8143
|
-
}
|
|
8144
|
-
} else {
|
|
8145
|
-
this._ctx.updateSelection(this, cursorX, cursorY);
|
|
8146
|
-
}
|
|
8220
|
+
this._ctx.updateSelection(this, cursorX, cursorY);
|
|
8147
8221
|
}
|
|
8148
8222
|
}
|
|
8149
8223
|
}
|
|
@@ -8846,5 +8920,5 @@ export {
|
|
|
8846
8920
|
ASCIIFont
|
|
8847
8921
|
};
|
|
8848
8922
|
|
|
8849
|
-
//# debugId=
|
|
8923
|
+
//# debugId=36CCE839639ECF0564756E2164756E21
|
|
8850
8924
|
//# sourceMappingURL=index.js.map
|