@bastani/atomic-tui 0.9.89 → 0.9.90
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/dist/builtin-command-names.d.ts +4 -0
- package/dist/builtin-command-names.d.ts.map +1 -0
- package/dist/builtin-command-names.js +42 -0
- package/dist/builtin-command-names.js.map +1 -0
- package/dist/clickable-hints.d.ts +84 -0
- package/dist/clickable-hints.d.ts.map +1 -0
- package/dist/clickable-hints.js +267 -0
- package/dist/clickable-hints.js.map +1 -0
- package/dist/components/editor.d.ts +7 -1
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +63 -25
- package/dist/components/editor.js.map +1 -1
- package/dist/components/settings-list.d.ts.map +1 -1
- package/dist/components/settings-list.js +3 -2
- package/dist/components/settings-list.js.map +1 -1
- package/dist/components/windowed-container.d.ts +2 -0
- package/dist/components/windowed-container.d.ts.map +1 -1
- package/dist/components/windowed-container.js +4 -0
- package/dist/components/windowed-container.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +5 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +115 -0
- package/dist/keys.js.map +1 -1
- package/dist/terminal.d.ts +3 -0
- package/dist/terminal.d.ts.map +1 -1
- package/dist/terminal.js +16 -0
- package/dist/terminal.js.map +1 -1
- package/dist/tui-alt-screen.d.ts +24 -3
- package/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/tui-alt-screen.js +205 -58
- package/dist/tui-alt-screen.js.map +1 -1
- package/dist/tui.d.ts +23 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +48 -5
- package/dist/tui.js.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +79 -11
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/tui-alt-screen.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AltScreenSearchComponent, AltScreenSearchIndex, getAltScreenSearchMatchKey, } from "./alt-screen-search.js";
|
|
2
|
+
import { hintActionAt, readHintSpans } from "./clickable-hints.js";
|
|
2
3
|
import { AltScreenFlashContainer } from "./components/alt-screen-flash.js";
|
|
3
4
|
import { ScrollView } from "./components/scroll-view.js";
|
|
4
5
|
import { WindowedContainer } from "./components/windowed-container.js";
|
|
@@ -19,6 +20,8 @@ const ENABLE_ALL_MOTION_MOUSE = "\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1004h\x1
|
|
|
19
20
|
const DISABLE_MOUSE = "\x1b[?1006l\x1b[?1004l\x1b[?1003l\x1b[?1002l\x1b[?1000l";
|
|
20
21
|
const FOCUS_IN = "\x1b[I";
|
|
21
22
|
const FOCUS_OUT = "\x1b[O";
|
|
23
|
+
/** The Shift, Alt and Ctrl bits of an SGR mouse report's button. */
|
|
24
|
+
const MODIFIER_BUTTON_BITS = 4 | 8 | 16;
|
|
22
25
|
const BEGIN_SYNCHRONIZED_OUTPUT = "\x1b[?2026h";
|
|
23
26
|
const END_SYNCHRONIZED_OUTPUT = "\x1b[?2026l";
|
|
24
27
|
const EXIT_TRANSCRIPT_START = `${BEGIN_SYNCHRONIZED_OUTPUT}${EXIT_ALT_SCREEN}${DISABLE_AUTOWRAP}`;
|
|
@@ -34,7 +37,12 @@ const MAX_CACHED_OFFSCREEN_KITTY_DECODED_BYTES = 64 * 1024 * 1024;
|
|
|
34
37
|
const EXIT_WRITE_CHARACTERS = 16 * 1024;
|
|
35
38
|
const EXIT_PREPARE_ROWS = 512;
|
|
36
39
|
const EXIT_SLICE_BUDGET_MS = 8;
|
|
37
|
-
|
|
40
|
+
/** How soon a second press on the same spot must follow the first to make a double- or triple-click. */
|
|
41
|
+
export const MULTI_CLICK_INTERVAL_MS = 500;
|
|
42
|
+
/** Whole elapsed milliseconds: clock corrections must not move an outstanding click's deadline. */
|
|
43
|
+
function clickTime() {
|
|
44
|
+
return Math.floor(performance.now());
|
|
45
|
+
}
|
|
38
46
|
const COPY_ERROR_FLASH_DURATION_MS = 5000;
|
|
39
47
|
// Regular mode delegates double-click selection to the terminal emulator. Fullscreen owns mouse selection,
|
|
40
48
|
// so it uses iTerm2's default "characters considered part of a word" set:
|
|
@@ -59,6 +67,9 @@ function samePointerGeometry(a, b) {
|
|
|
59
67
|
*/
|
|
60
68
|
function sameDrawnAtPointer(a, b) {
|
|
61
69
|
return (a !== undefined &&
|
|
70
|
+
(a.hint === b.hint ||
|
|
71
|
+
(a.hint?.kind === "key" && b.hint?.kind === "key" && a.hint.key === b.hint.key) ||
|
|
72
|
+
(a.hint?.kind === "command" && b.hint?.kind === "command" && a.hint.command === b.hint.command)) &&
|
|
62
73
|
a.drawn.length === b.drawn.length &&
|
|
63
74
|
a.drawn.every((item, index) => item === b.drawn[index]) &&
|
|
64
75
|
samePointerGeometry(a, b));
|
|
@@ -97,6 +108,8 @@ export class TuiAltScreen extends TuiBase {
|
|
|
97
108
|
mode = "fullscreen";
|
|
98
109
|
[VIEWPORT_TUI] = true;
|
|
99
110
|
previousScreen = [];
|
|
111
|
+
unselectedScreen = [];
|
|
112
|
+
highlightedRows = new Set();
|
|
100
113
|
lastDocument = [];
|
|
101
114
|
exitWrites = 0;
|
|
102
115
|
previousScreenWidth = 0;
|
|
@@ -126,6 +139,12 @@ export class TuiAltScreen extends TuiBase {
|
|
|
126
139
|
scrollToEndIndicatorRect;
|
|
127
140
|
activeSearch;
|
|
128
141
|
pressedUrl;
|
|
142
|
+
/** The key hint under the press, which the click that releases there runs. */
|
|
143
|
+
pressedHint;
|
|
144
|
+
/** A press on a key hint is down: its drag and release go to the text selection. */
|
|
145
|
+
hintGestureActive = false;
|
|
146
|
+
/** The key hints the last frame painted, by screen row. */
|
|
147
|
+
paintedHints = [];
|
|
129
148
|
/** What the screen showed under the pointer when the left button went down. */
|
|
130
149
|
pressFrame;
|
|
131
150
|
/** Rows of the primary transcript that a drawn-over row covers: the pinned prompt and the jump-to-latest row. */
|
|
@@ -137,7 +156,9 @@ export class TuiAltScreen extends TuiBase {
|
|
|
137
156
|
/** What the screen showed at a press a component took: its click needs the same geometry at the release. */
|
|
138
157
|
mousePressFrame;
|
|
139
158
|
mousePressMoved = false;
|
|
140
|
-
|
|
159
|
+
/** Single clicks whose action waits until a second press can no longer continue them. */
|
|
160
|
+
waitingSingleClicks = new Map();
|
|
161
|
+
singleClickTimer;
|
|
141
162
|
wheelScroll;
|
|
142
163
|
mouseEnabled;
|
|
143
164
|
searchMatchStyle;
|
|
@@ -204,6 +225,8 @@ export class TuiAltScreen extends TuiBase {
|
|
|
204
225
|
}
|
|
205
226
|
/** Drop the text selection and multi-click history, e.g. before the host replaces the transcript. */
|
|
206
227
|
resetTextSelection() {
|
|
228
|
+
this.dropWaitingSingleClicks();
|
|
229
|
+
this.clearComponentMouseGesture();
|
|
207
230
|
this.clearTextSelection();
|
|
208
231
|
this.lastClick = undefined;
|
|
209
232
|
}
|
|
@@ -250,9 +273,11 @@ export class TuiAltScreen extends TuiBase {
|
|
|
250
273
|
this.selectionInitialRange = undefined;
|
|
251
274
|
this.lastClick = undefined;
|
|
252
275
|
this.pressedUrl = undefined;
|
|
276
|
+
this.pressedHint = undefined;
|
|
277
|
+
this.hintGestureActive = false;
|
|
278
|
+
this.paintedHints = [];
|
|
253
279
|
this.selectionDragged = false;
|
|
254
280
|
this.clearComponentMouseGesture();
|
|
255
|
-
this.lastComponentClick = undefined;
|
|
256
281
|
this.resetRenderState();
|
|
257
282
|
const term = process.env.TERM?.toLowerCase() ?? "";
|
|
258
283
|
// Multiplexers can lag when every pointer movement is forwarded. Button-motion
|
|
@@ -268,6 +293,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
268
293
|
}
|
|
269
294
|
beforeTerminalStop(_options) {
|
|
270
295
|
this.closeSearch();
|
|
296
|
+
this.dropWaitingSingleClicks();
|
|
271
297
|
this.stopSelectionAutoScroll();
|
|
272
298
|
this.selectionPressActive = false;
|
|
273
299
|
this.stopScrollbarHover();
|
|
@@ -639,6 +665,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
639
665
|
}
|
|
640
666
|
handleViewportInput(data) {
|
|
641
667
|
if (data === FOCUS_OUT) {
|
|
668
|
+
this.dropWaitingSingleClicks();
|
|
642
669
|
const hadActiveSelection = this.selectionPressActive;
|
|
643
670
|
const hadNonEmptyActiveSelection = hadActiveSelection && this.getSelectionBounds() !== undefined;
|
|
644
671
|
this.selectionPressActive = false;
|
|
@@ -648,9 +675,10 @@ export class TuiAltScreen extends TuiBase {
|
|
|
648
675
|
this.requestRender();
|
|
649
676
|
this.stopScrollbarDrag();
|
|
650
677
|
this.pressedUrl = undefined;
|
|
678
|
+
this.pressedHint = undefined;
|
|
679
|
+
this.hintGestureActive = false;
|
|
651
680
|
this.selectionDragged = false;
|
|
652
681
|
this.clearComponentMouseGesture();
|
|
653
|
-
this.lastComponentClick = undefined;
|
|
654
682
|
if (hadActiveSelection) {
|
|
655
683
|
this.selectionAnchor = undefined;
|
|
656
684
|
this.selectionFocus = undefined;
|
|
@@ -666,6 +694,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
666
694
|
return { consume: true };
|
|
667
695
|
const wheelEvent = this.parseWheelEvent(data);
|
|
668
696
|
if (wheelEvent) {
|
|
697
|
+
this.lastClick = undefined;
|
|
669
698
|
const lines = this.wheelScroll.next(wheelEvent.direction, performance.now());
|
|
670
699
|
// SGR mouse button codes use bit 3 (value 8) for the Alt modifier.
|
|
671
700
|
const wheelDelta = wheelEvent.direction * ((wheelEvent.button & 8) !== 0 ? lines * ALT_WHEEL_SCROLL_MULTIPLIER : lines);
|
|
@@ -836,18 +865,55 @@ export class TuiAltScreen extends TuiBase {
|
|
|
836
865
|
dispatchMouseToTarget(event, target) {
|
|
837
866
|
return dispatchMouseEvent(target.component, retargetMouseEvent(event, target));
|
|
838
867
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
this.
|
|
850
|
-
|
|
868
|
+
/** Run an action only if its press stays single. */
|
|
869
|
+
waitForSingleClick(result, start) {
|
|
870
|
+
const action = result.whenSingleClick;
|
|
871
|
+
if (action === undefined)
|
|
872
|
+
return;
|
|
873
|
+
if (start.count !== 1 || !this.altScreenActive) {
|
|
874
|
+
result.onSingleClickCancel?.();
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
this.waitingSingleClicks.set(start, result);
|
|
878
|
+
this.scheduleSingleClickTimer();
|
|
879
|
+
}
|
|
880
|
+
scheduleSingleClickTimer() {
|
|
881
|
+
const first = this.waitingSingleClicks.keys().next().value;
|
|
882
|
+
if (!first || this.singleClickTimer)
|
|
883
|
+
return;
|
|
884
|
+
// One past the interval: a second press exactly at its end still counts. Deliver tied deadlines in press order.
|
|
885
|
+
this.singleClickTimer = setTimeout(() => {
|
|
886
|
+
this.singleClickTimer = undefined;
|
|
887
|
+
try {
|
|
888
|
+
for (const [press, result] of this.waitingSingleClicks) {
|
|
889
|
+
if (clickTime() - press.timestamp <= MULTI_CLICK_INTERVAL_MS)
|
|
890
|
+
break;
|
|
891
|
+
this.waitingSingleClicks.delete(press);
|
|
892
|
+
result.whenSingleClick?.();
|
|
893
|
+
this.requestRender();
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
finally {
|
|
897
|
+
this.scheduleSingleClickTimer();
|
|
898
|
+
}
|
|
899
|
+
}, Math.max(0, first.timestamp + MULTI_CLICK_INTERVAL_MS + 1 - clickTime()));
|
|
900
|
+
this.singleClickTimer.unref?.();
|
|
901
|
+
}
|
|
902
|
+
/** A second click continued the clicks begun at `start`: they are a double- or triple-click, not single clicks. */
|
|
903
|
+
cancelWaitingSingleClicks(start) {
|
|
904
|
+
const waiting = this.waitingSingleClicks.get(start);
|
|
905
|
+
if (!waiting)
|
|
906
|
+
return;
|
|
907
|
+
this.waitingSingleClicks.delete(start);
|
|
908
|
+
if (this.waitingSingleClicks.size === 0) {
|
|
909
|
+
clearTimeout(this.singleClickTimer);
|
|
910
|
+
this.singleClickTimer = undefined;
|
|
911
|
+
}
|
|
912
|
+
waiting.onSingleClickCancel?.();
|
|
913
|
+
}
|
|
914
|
+
dropWaitingSingleClicks() {
|
|
915
|
+
for (const start of this.waitingSingleClicks.keys())
|
|
916
|
+
this.cancelWaitingSingleClicks(start);
|
|
851
917
|
}
|
|
852
918
|
clearTextSelection() {
|
|
853
919
|
this.stopSelectionAutoScroll();
|
|
@@ -857,6 +923,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
857
923
|
this.selectionGranularity = "character";
|
|
858
924
|
this.selectionInitialRange = undefined;
|
|
859
925
|
this.pressedUrl = undefined;
|
|
926
|
+
this.pressedHint = undefined;
|
|
860
927
|
this.selectionDragged = false;
|
|
861
928
|
}
|
|
862
929
|
handleMouseEvent(raw) {
|
|
@@ -868,12 +935,17 @@ export class TuiAltScreen extends TuiBase {
|
|
|
868
935
|
? "move"
|
|
869
936
|
: "drag"
|
|
870
937
|
: "press";
|
|
938
|
+
const timestamp = clickTime();
|
|
939
|
+
const previous = this.lastClick;
|
|
940
|
+
// A press taken by a scrollbar, search button or another gesture also breaks the click sequence.
|
|
941
|
+
if (type === "press")
|
|
942
|
+
this.lastClick = undefined;
|
|
871
943
|
const event = this.createMouseEvent(type, raw.button, raw.x, raw.y);
|
|
872
944
|
if (this.mouseCapture || this.mousePressTarget) {
|
|
873
945
|
const target = this.mouseCapture ?? this.mousePressTarget;
|
|
874
946
|
if (this.mousePressPoint && (raw.x !== this.mousePressPoint.x || raw.y !== this.mousePressPoint.y)) {
|
|
875
947
|
this.mousePressMoved = true;
|
|
876
|
-
this.
|
|
948
|
+
this.lastClick = undefined;
|
|
877
949
|
}
|
|
878
950
|
let render = false;
|
|
879
951
|
const targetResult = this.dispatchMouseToTarget(event, target);
|
|
@@ -882,17 +954,23 @@ export class TuiAltScreen extends TuiBase {
|
|
|
882
954
|
if (raw.release) {
|
|
883
955
|
// The release always reaches the target, so it can end what its press started. The click needs the
|
|
884
956
|
// same target still drawn where it was pressed, not another that took its place.
|
|
885
|
-
|
|
957
|
+
const click = this.lastClick;
|
|
958
|
+
if (click &&
|
|
959
|
+
!this.mousePressMoved &&
|
|
886
960
|
this.mousePressPoint?.x === raw.x &&
|
|
887
961
|
this.mousePressPoint.y === raw.y &&
|
|
888
962
|
sameDrawnAtPointer(this.mousePressFrame, this.pointerFrame(raw.x, raw.y))) {
|
|
889
963
|
const clickEvent = this.createMouseEvent("click", raw.button, raw.x, raw.y, {
|
|
890
|
-
clickCount:
|
|
964
|
+
clickCount: click.count,
|
|
891
965
|
});
|
|
892
966
|
const clickResult = this.dispatchMouseToTarget(clickEvent, target);
|
|
893
|
-
if (clickResult)
|
|
967
|
+
if (clickResult) {
|
|
894
968
|
render = this.applyMouseDispatchResult(clickEvent, clickResult) || render;
|
|
969
|
+
this.waitForSingleClick(clickResult, click);
|
|
970
|
+
}
|
|
895
971
|
}
|
|
972
|
+
else
|
|
973
|
+
this.lastClick = undefined;
|
|
896
974
|
this.clearComponentMouseGesture();
|
|
897
975
|
}
|
|
898
976
|
if (render)
|
|
@@ -901,6 +979,13 @@ export class TuiAltScreen extends TuiBase {
|
|
|
901
979
|
}
|
|
902
980
|
if (this.handleSearchMouseEvent(raw))
|
|
903
981
|
return;
|
|
982
|
+
// A press on a key hint, and the drag or release that follows it, belong to the text selection: a click runs the
|
|
983
|
+
// hint and a drag selects text, whatever component drew the hint.
|
|
984
|
+
if (this.hintGestureActive || (type === "press" && this.isHintPress(raw))) {
|
|
985
|
+
this.hintGestureActive = !raw.release;
|
|
986
|
+
this.handleSelectionMouseEvent(raw, timestamp, previous);
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
904
989
|
const overlay = this.dispatchMouseToOverlay(event);
|
|
905
990
|
if (!overlay.hit) {
|
|
906
991
|
if (this.handleScrollToEndIndicatorMouseEvent(raw))
|
|
@@ -922,6 +1007,16 @@ export class TuiAltScreen extends TuiBase {
|
|
|
922
1007
|
this.mousePressTarget = result.target;
|
|
923
1008
|
this.mousePressPoint = { x: raw.x, y: raw.y };
|
|
924
1009
|
this.mousePressFrame = this.pointerFrame(raw.x, raw.y);
|
|
1010
|
+
this.recordPress(previous, {
|
|
1011
|
+
timestamp,
|
|
1012
|
+
button: raw.button,
|
|
1013
|
+
row: raw.y,
|
|
1014
|
+
col: raw.x,
|
|
1015
|
+
wordStart: raw.x,
|
|
1016
|
+
wordEnd: raw.x,
|
|
1017
|
+
drawn: this.mousePressFrame.drawn,
|
|
1018
|
+
component: result.target.component,
|
|
1019
|
+
});
|
|
925
1020
|
this.mousePressMoved = false;
|
|
926
1021
|
}
|
|
927
1022
|
if (render)
|
|
@@ -930,7 +1025,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
930
1025
|
}
|
|
931
1026
|
if (this.handleRightClickPaste(raw))
|
|
932
1027
|
return;
|
|
933
|
-
this.handleSelectionMouseEvent(raw);
|
|
1028
|
+
this.handleSelectionMouseEvent(raw, timestamp, previous);
|
|
934
1029
|
}
|
|
935
1030
|
parseWheelEvent(data) {
|
|
936
1031
|
const sgr = /^\x1b\[<(\d+);(\d+);(\d+)[Mm]$/.exec(data);
|
|
@@ -1077,6 +1172,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1077
1172
|
this.selectionInitialRange = undefined;
|
|
1078
1173
|
this.lastClick = undefined;
|
|
1079
1174
|
this.pressedUrl = undefined;
|
|
1175
|
+
this.pressedHint = undefined;
|
|
1080
1176
|
this.selectionDragged = false;
|
|
1081
1177
|
this.setScrollbarHover(target.scrollView);
|
|
1082
1178
|
const onThumb = event.y >= target.geometry.thumbTop && event.y < target.geometry.thumbTop + target.geometry.thumbHeight;
|
|
@@ -1182,34 +1278,21 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1182
1278
|
this.selectionFocus = range.end;
|
|
1183
1279
|
}
|
|
1184
1280
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
previous
|
|
1199
|
-
|
|
1200
|
-
previous.drawn.every((item, index) => item === drawn[index])
|
|
1201
|
-
? (previous.count % 3) + 1
|
|
1202
|
-
: 1;
|
|
1203
|
-
this.lastClick = {
|
|
1204
|
-
timestamp: now,
|
|
1205
|
-
count,
|
|
1206
|
-
row: screenRow,
|
|
1207
|
-
col: screenCol,
|
|
1208
|
-
wordStart: start,
|
|
1209
|
-
wordEnd: end,
|
|
1210
|
-
drawn,
|
|
1211
|
-
awaitingPaint: false,
|
|
1212
|
-
};
|
|
1281
|
+
recordPress(previous, press) {
|
|
1282
|
+
// A control counts presses on the same cell. Text selection also accepts another cell of the same word.
|
|
1283
|
+
const continues = previous &&
|
|
1284
|
+
press.timestamp - previous.timestamp <= MULTI_CLICK_INTERVAL_MS &&
|
|
1285
|
+
previous.button === press.button &&
|
|
1286
|
+
previous.row === press.row &&
|
|
1287
|
+
(previous.col === press.col ||
|
|
1288
|
+
(previous.wordStart === press.wordStart && previous.wordEnd === press.wordEnd)) &&
|
|
1289
|
+
(!previous.component || !press.component || previous.component === press.component) &&
|
|
1290
|
+
previous.drawn.length === press.drawn.length &&
|
|
1291
|
+
previous.drawn.every((item, i) => item === press.drawn[i]);
|
|
1292
|
+
const count = continues ? (previous.count % 3) + 1 : 1;
|
|
1293
|
+
if (continues)
|
|
1294
|
+
this.cancelWaitingSingleClicks(previous);
|
|
1295
|
+
this.lastClick = { ...press, count, awaitingPaint: false };
|
|
1213
1296
|
return count;
|
|
1214
1297
|
}
|
|
1215
1298
|
/** What the screen shows at `x`, `y`: the painted row, the layout boxes and overlay drawn there. */
|
|
@@ -1220,6 +1303,9 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1220
1303
|
const innermost = boxes[0];
|
|
1221
1304
|
return {
|
|
1222
1305
|
line: this.previousScreen[y],
|
|
1306
|
+
hint: this.hintAt(x, y),
|
|
1307
|
+
unselectedLine: this.unselectedScreen[y],
|
|
1308
|
+
highlighted: this.highlightedRows.has(y),
|
|
1223
1309
|
boxes: boxes.map((box) => ({ component: box.component, x: box.rect.x, y: box.rect.y })),
|
|
1224
1310
|
drawn: overlay
|
|
1225
1311
|
? drawnAt(overlay.component, overlay.width, y - overlay.row)
|
|
@@ -1284,7 +1370,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1284
1370
|
this.selectionAutoScrollDirection = 0;
|
|
1285
1371
|
this.selectionDragPointer = undefined;
|
|
1286
1372
|
}
|
|
1287
|
-
handleSelectionMouseEvent(event) {
|
|
1373
|
+
handleSelectionMouseEvent(event, timestamp, previous) {
|
|
1288
1374
|
const button = event.button & 3;
|
|
1289
1375
|
if (button !== 0 && !(event.release && button === 3))
|
|
1290
1376
|
return;
|
|
@@ -1299,16 +1385,44 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1299
1385
|
return;
|
|
1300
1386
|
this.updateSelectionFocus(point);
|
|
1301
1387
|
const releaseFrame = this.pointerFrame(event.x, event.y);
|
|
1302
|
-
const
|
|
1388
|
+
const samePaint = samePointerFrame(this.pressFrame, releaseFrame);
|
|
1389
|
+
const click = this.lastClick;
|
|
1390
|
+
// Drawing or clearing a selection changes the row's styling, not what the next press would select.
|
|
1391
|
+
const sameSpot = samePaint ||
|
|
1392
|
+
(sameDrawnAtPointer(this.pressFrame, releaseFrame) &&
|
|
1393
|
+
stripTerminalSequences(this.pressFrame?.line ?? "") ===
|
|
1394
|
+
stripTerminalSequences(releaseFrame.line ?? "") &&
|
|
1395
|
+
getOsc8LinkAtColumn(this.pressFrame?.line ?? "", event.x) ===
|
|
1396
|
+
getOsc8LinkAtColumn(releaseFrame.line ?? "", event.x));
|
|
1397
|
+
const unchanged = samePaint ||
|
|
1398
|
+
(sameSpot &&
|
|
1399
|
+
this.pressFrame?.highlighted &&
|
|
1400
|
+
!releaseFrame.highlighted &&
|
|
1401
|
+
this.pressFrame.unselectedLine === releaseFrame.unselectedLine);
|
|
1402
|
+
if (click && (click.row !== event.y || click.col !== event.x || !sameSpot))
|
|
1403
|
+
this.lastClick = undefined;
|
|
1404
|
+
const isClick = this.lastClick !== undefined &&
|
|
1405
|
+
!this.selectionDragged &&
|
|
1303
1406
|
this.selectionAnchor.scrollView === point.scrollView &&
|
|
1304
1407
|
this.selectionAnchor.row === point.row &&
|
|
1305
1408
|
this.selectionAnchor.col === point.col;
|
|
1306
1409
|
// A click acts on what the screen showed when it was pressed: a repaint that changed what is under the
|
|
1307
1410
|
// pointer before the release makes it no click at all.
|
|
1308
|
-
const samePaint = samePointerFrame(this.pressFrame, releaseFrame);
|
|
1309
1411
|
this.pressFrame = undefined;
|
|
1310
|
-
const clickedUrl = isClick ? this.pressedUrl : undefined;
|
|
1412
|
+
const clickedUrl = isClick && unchanged ? this.pressedUrl : undefined;
|
|
1311
1413
|
this.pressedUrl = undefined;
|
|
1414
|
+
// A key hint acts on a single click of what the press showed, as a pressed key would.
|
|
1415
|
+
const clickedHint = isClick && unchanged ? this.pressedHint : undefined;
|
|
1416
|
+
this.pressedHint = undefined;
|
|
1417
|
+
if (clickedHint) {
|
|
1418
|
+
this.selectionAnchor = undefined;
|
|
1419
|
+
this.selectionFocus = undefined;
|
|
1420
|
+
if (this.lastClick)
|
|
1421
|
+
this.lastClick.awaitingPaint = true;
|
|
1422
|
+
this.runHintAction(clickedHint);
|
|
1423
|
+
this.requestRender();
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1312
1426
|
if (clickedUrl && this.openUrl) {
|
|
1313
1427
|
this.selectionAnchor = undefined;
|
|
1314
1428
|
this.selectionFocus = undefined;
|
|
@@ -1321,17 +1435,18 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1321
1435
|
this.requestRender();
|
|
1322
1436
|
return;
|
|
1323
1437
|
}
|
|
1324
|
-
if (isClick &&
|
|
1438
|
+
if (click && isClick && unchanged && !releaseFrame.decorated) {
|
|
1325
1439
|
const clickEvent = this.createMouseEvent("click", event.button, event.x, event.y, {
|
|
1326
|
-
clickCount:
|
|
1440
|
+
clickCount: click.count,
|
|
1327
1441
|
});
|
|
1328
1442
|
const overlay = this.dispatchMouseToOverlay(clickEvent);
|
|
1329
1443
|
const result = overlay.result ?? (overlay.hit ? undefined : this.dispatchMouseToLayout(clickEvent));
|
|
1330
1444
|
if (result) {
|
|
1331
1445
|
const render = this.applyMouseDispatchResult(clickEvent, result);
|
|
1332
1446
|
this.clearTextSelection();
|
|
1333
|
-
|
|
1334
|
-
|
|
1447
|
+
this.waitForSingleClick(result, click);
|
|
1448
|
+
// Only an immediate action has changed what the next frame draws here.
|
|
1449
|
+
click.awaitingPaint = result.whenSingleClick === undefined;
|
|
1335
1450
|
if (render)
|
|
1336
1451
|
this.requestRender();
|
|
1337
1452
|
return;
|
|
@@ -1348,6 +1463,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1348
1463
|
this.selectionDragged = true;
|
|
1349
1464
|
this.lastClick = undefined;
|
|
1350
1465
|
this.pressedUrl = undefined;
|
|
1466
|
+
this.pressedHint = undefined;
|
|
1351
1467
|
this.updateSelectionFocus(point);
|
|
1352
1468
|
this.updateSelectionAutoScroll(event);
|
|
1353
1469
|
this.requestRender();
|
|
@@ -1361,7 +1477,17 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1361
1477
|
const anchor = this.getSelectionPoint(event, scrollView);
|
|
1362
1478
|
const word = this.getWordSelection(anchor);
|
|
1363
1479
|
const pressFrame = this.pointerFrame(event.x, event.y);
|
|
1364
|
-
const
|
|
1480
|
+
const col = Math.max(0, Math.min(this.terminal.columns - 1, event.x));
|
|
1481
|
+
const offset = col - anchor.col;
|
|
1482
|
+
const clickCount = this.recordPress(previous, {
|
|
1483
|
+
timestamp,
|
|
1484
|
+
button: event.button,
|
|
1485
|
+
row: event.y,
|
|
1486
|
+
col,
|
|
1487
|
+
wordStart: (word?.start.col ?? anchor.col) + offset,
|
|
1488
|
+
wordEnd: (word?.end.col ?? anchor.col) + offset,
|
|
1489
|
+
drawn: pressFrame.drawn,
|
|
1490
|
+
});
|
|
1365
1491
|
const range = clickCount === 2 ? word : clickCount === 3 ? this.getLineSelection(anchor) : undefined;
|
|
1366
1492
|
this.selectionGranularity = range ? (clickCount === 2 ? "word" : "line") : "character";
|
|
1367
1493
|
this.selectionInitialRange = range;
|
|
@@ -1372,8 +1498,18 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1372
1498
|
this.pressedUrl = range
|
|
1373
1499
|
? undefined
|
|
1374
1500
|
: getOsc8LinkAtColumn(this.previousScreen[Math.max(0, Math.min(this.terminal.rows - 1, event.y))] ?? "", Math.max(0, Math.min(this.terminal.columns - 1, event.x)));
|
|
1501
|
+
this.pressedHint = range || (event.button & MODIFIER_BUTTON_BITS) !== 0 ? undefined : pressFrame.hint;
|
|
1375
1502
|
this.requestRender();
|
|
1376
1503
|
}
|
|
1504
|
+
/** The action of the key hint the last frame painted at screen cell `x`, `y`, when keys reach what is drawn there. */
|
|
1505
|
+
hintAt(x, y) {
|
|
1506
|
+
const action = hintActionAt(this.paintedHints[y], x);
|
|
1507
|
+
return action !== undefined && this.takesKeysAt(x, y) ? action : undefined;
|
|
1508
|
+
}
|
|
1509
|
+
/** A plain left press on a key hint, which the text selection takes so a click runs the hint and a drag selects. */
|
|
1510
|
+
isHintPress(event) {
|
|
1511
|
+
return !event.release && event.button === 0 && this.hintAt(event.x, event.y) !== undefined;
|
|
1512
|
+
}
|
|
1377
1513
|
getSelectionBounds() {
|
|
1378
1514
|
if (!this.selectionAnchor || !this.selectionFocus)
|
|
1379
1515
|
return undefined;
|
|
@@ -1549,6 +1685,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1549
1685
|
return `${result}\x1b[27m`;
|
|
1550
1686
|
}
|
|
1551
1687
|
applySelection(screen, layout = this.currentLayout) {
|
|
1688
|
+
this.highlightedRows.clear();
|
|
1552
1689
|
const selection = this.getSelectionBounds();
|
|
1553
1690
|
if (!selection)
|
|
1554
1691
|
return screen;
|
|
@@ -1592,6 +1729,7 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1592
1729
|
const columns = this.getSelectionColumns(line, row, screenSelection, minColumn, maxColumn);
|
|
1593
1730
|
if (columns.end <= columns.start)
|
|
1594
1731
|
return line;
|
|
1732
|
+
this.highlightedRows.add(row);
|
|
1595
1733
|
const before = sliceByColumn(line, 0, columns.start, true);
|
|
1596
1734
|
const selected = sliceByColumn(line, columns.start, columns.end - columns.start, true);
|
|
1597
1735
|
const after = sliceByColumn(line, columns.end, Math.max(0, lineWidth - columns.end), true);
|
|
@@ -1742,9 +1880,18 @@ export class TuiAltScreen extends TuiBase {
|
|
|
1742
1880
|
let screen = rendered.screen;
|
|
1743
1881
|
if (screen.length > height)
|
|
1744
1882
|
screen = screen.slice(screen.length - height);
|
|
1883
|
+
this.unselectedScreen = screen.slice();
|
|
1745
1884
|
screen = this.applySelection(screen, nextLayout);
|
|
1746
1885
|
screen = this.compositeFlashes(screen, width, height);
|
|
1747
1886
|
const cursorPos = this.extractCursorPosition(screen, height);
|
|
1887
|
+
const paintedHints = [];
|
|
1888
|
+
screen = screen.map((line, row) => {
|
|
1889
|
+
const read = readHintSpans(line);
|
|
1890
|
+
if (read.spans.length > 0)
|
|
1891
|
+
paintedHints[row] = read.spans;
|
|
1892
|
+
return read.line;
|
|
1893
|
+
});
|
|
1894
|
+
this.paintedHints = paintedHints;
|
|
1748
1895
|
screen = this.applyLineResets(screen).map((line) => {
|
|
1749
1896
|
if (isImageLine(line) || visibleWidth(line) <= width)
|
|
1750
1897
|
return line;
|