@vibecook/ghosttea-react 0.13.2 → 0.13.3
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/TerminalSurface.d.ts +135 -1
- package/dist/TerminalSurface.d.ts.map +1 -1
- package/dist/TerminalSurface.js +245 -78
- package/dist/TerminalSurface.js.map +1 -1
- package/dist/bindings/action-route.d.ts +27 -6
- package/dist/bindings/action-route.d.ts.map +1 -1
- package/dist/bindings/action-route.js +33 -17
- package/dist/bindings/action-route.js.map +1 -1
- package/dist/bindings/index.d.ts +1 -1
- package/dist/bindings/index.d.ts.map +1 -1
- package/dist/bindings/index.js +1 -1
- package/dist/bindings/index.js.map +1 -1
- package/dist/text-input.d.ts +121 -0
- package/dist/text-input.d.ts.map +1 -0
- package/dist/text-input.js +214 -0
- package/dist/text-input.js.map +1 -0
- package/dist/workspace/Workspace.d.ts +6 -1
- package/dist/workspace/Workspace.d.ts.map +1 -1
- package/dist/workspace/Workspace.js +57 -88
- package/dist/workspace/Workspace.js.map +1 -1
- package/dist/workspace/hotkeys.d.ts +53 -1
- package/dist/workspace/hotkeys.d.ts.map +1 -1
- package/dist/workspace/hotkeys.js +70 -1
- package/dist/workspace/hotkeys.js.map +1 -1
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/pane-focus.d.ts +31 -0
- package/dist/workspace/pane-focus.d.ts.map +1 -1
- package/dist/workspace/pane-focus.js +86 -0
- package/dist/workspace/pane-focus.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { terminalKeyDown, terminalKeyUp } from "./keyboard-input.js";
|
|
2
|
+
const ENTER = { type: "key", key: "Enter" };
|
|
3
|
+
const BACKSPACE = { type: "key", key: "Backspace" };
|
|
4
|
+
const DELETE = { type: "key", key: "Delete" };
|
|
5
|
+
/** Edits that carry clipboard-like content: the terminal pastes them, as Ghostty does a drop. */
|
|
6
|
+
const PASTE_INPUT_TYPES = new Set([
|
|
7
|
+
"insertFromPaste",
|
|
8
|
+
"insertFromPasteAsQuotation",
|
|
9
|
+
"insertFromDrop",
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* The keyCode engines give a keydown the IME processed, whose result arrives as
|
|
13
|
+
* composition or input events. Chromium on Windows and Linux also names its key
|
|
14
|
+
* "Process", as Firefox does while composing, but Chromium on macOS keeps the
|
|
15
|
+
* typed key (an "n") and changes only the keyCode. The keydown that starts a
|
|
16
|
+
* composition is not yet `isComposing` either, so on macOS this keyCode is all
|
|
17
|
+
* that marks it, and encoding it would send its letter ahead of the commit.
|
|
18
|
+
* WebKit also sends such a keydown after `compositionend` for the key that
|
|
19
|
+
* committed the composition, Enter included.
|
|
20
|
+
*/
|
|
21
|
+
const IME_PROCESSED_KEY_CODE = 229;
|
|
22
|
+
/**
|
|
23
|
+
* Committed text as terminal input: the text between line breaks, and the
|
|
24
|
+
* Enter key for each `\r\n`, `\r` or `\n`, so a soft keyboard's or an IME's
|
|
25
|
+
* line break sends what the Enter key sends rather than a bare LF.
|
|
26
|
+
*/
|
|
27
|
+
export function committedTextActions(text) {
|
|
28
|
+
const actions = [];
|
|
29
|
+
text.split(/\r\n|\r|\n/).forEach((line, index) => {
|
|
30
|
+
if (index > 0)
|
|
31
|
+
actions.push(ENTER);
|
|
32
|
+
if (line)
|
|
33
|
+
actions.push({ type: "text", text: line });
|
|
34
|
+
});
|
|
35
|
+
return actions;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What a `beforeinput` on the textarea asks of the terminal, or null when it is
|
|
39
|
+
* not the terminal's to take now: a composition's edits (the commit arrives at
|
|
40
|
+
* `compositionend`), an edit with no data to send, a delete of text the field
|
|
41
|
+
* still holds, and every edit type a terminal has no meaning for.
|
|
42
|
+
*/
|
|
43
|
+
export function terminalBeforeInputActions(event, value) {
|
|
44
|
+
if (event.isComposing)
|
|
45
|
+
return null;
|
|
46
|
+
switch (event.inputType) {
|
|
47
|
+
case "insertText":
|
|
48
|
+
case "insertReplacementText":
|
|
49
|
+
return event.data ? committedTextActions(event.data) : null;
|
|
50
|
+
case "insertLineBreak":
|
|
51
|
+
case "insertParagraph":
|
|
52
|
+
return [ENTER];
|
|
53
|
+
case "insertFromPaste":
|
|
54
|
+
case "insertFromPasteAsQuotation":
|
|
55
|
+
case "insertFromDrop":
|
|
56
|
+
return event.data ? [{ type: "paste", text: event.data }] : null;
|
|
57
|
+
case "deleteContentBackward":
|
|
58
|
+
return value === "" ? [BACKSPACE] : null;
|
|
59
|
+
case "deleteContentForward":
|
|
60
|
+
return value === "" ? [DELETE] : null;
|
|
61
|
+
default:
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* What an `input` the browser applied leaves in the textarea for the terminal,
|
|
67
|
+
* which the caller then clears: pasted or dropped content as a paste, anything
|
|
68
|
+
* else as committed text. Null while a composition owns the field.
|
|
69
|
+
*/
|
|
70
|
+
export function terminalInputActions(event, value) {
|
|
71
|
+
if (event.isComposing)
|
|
72
|
+
return null;
|
|
73
|
+
if (value === "")
|
|
74
|
+
return [];
|
|
75
|
+
return PASTE_INPUT_TYPES.has(event.inputType) ? [{ type: "paste", text: value }] : committedTextActions(value);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The key events an edit key sends: the press and release the physical key
|
|
79
|
+
* would, through the same `terminalKeyDown`, so a soft keyboard's Enter
|
|
80
|
+
* encodes exactly as the Enter key does under every keyboard protocol.
|
|
81
|
+
*/
|
|
82
|
+
export function terminalEditKeyEvents(key, timestamp, resolver) {
|
|
83
|
+
const event = {
|
|
84
|
+
key,
|
|
85
|
+
code: key,
|
|
86
|
+
location: 0,
|
|
87
|
+
repeat: false,
|
|
88
|
+
shiftKey: false,
|
|
89
|
+
ctrlKey: false,
|
|
90
|
+
altKey: false,
|
|
91
|
+
metaKey: false,
|
|
92
|
+
timeStamp: timestamp,
|
|
93
|
+
};
|
|
94
|
+
const down = terminalKeyDown(event, resolver);
|
|
95
|
+
return [down, terminalKeyUp(down, event)];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The textarea's text-input state machine. Each edit reaches the terminal
|
|
99
|
+
* exactly once, whichever of its events arrive and in whatever order:
|
|
100
|
+
*
|
|
101
|
+
* - A keydown the terminal encodes is prevented by the surface, so no input
|
|
102
|
+
* follows it. A keydown the text system owns (composing, keyCode 229,
|
|
103
|
+
* "Process", "Unidentified") is neither encoded nor prevented, and its text
|
|
104
|
+
* arrives here instead.
|
|
105
|
+
* - A cancelable `beforeinput` is taken and prevented, so nothing lands in the
|
|
106
|
+
* field. Should a browser apply it anyway, its `input` is dropped.
|
|
107
|
+
* - An edit the browser applies regardless (an uncancelable `beforeinput`)
|
|
108
|
+
* reaches `input`, which sends what landed in the field and clears it. A
|
|
109
|
+
* delete lands nothing, so an uncancelable one is remembered for its `input`.
|
|
110
|
+
* - A composition's text is sent at `compositionend` from the field, which is
|
|
111
|
+
* then cleared. Until then the composition owns the field, whatever its
|
|
112
|
+
* events say: Chromium's commit `input` comes before `compositionend` and is
|
|
113
|
+
* composing, and WebKit's commit edits (`deleteCompositionText`,
|
|
114
|
+
* `insertFromComposition`) come before it too but are not. Firefox's `input`
|
|
115
|
+
* comes after `compositionend` and finds the field empty.
|
|
116
|
+
*/
|
|
117
|
+
export class TerminalTextInput {
|
|
118
|
+
#composing = false;
|
|
119
|
+
#prevented = false;
|
|
120
|
+
#uncancelableDelete = null;
|
|
121
|
+
/**
|
|
122
|
+
* Notes a keydown; true when the text system owns it, so the terminal must
|
|
123
|
+
* neither encode it nor prevent it. Only the event decides: a composition
|
|
124
|
+
* this object believes in never takes a key the platform did not give it.
|
|
125
|
+
*/
|
|
126
|
+
keyDown(event) {
|
|
127
|
+
this.#forgetEdit();
|
|
128
|
+
return (event.isComposing ||
|
|
129
|
+
event.keyCode === IME_PROCESSED_KEY_CODE ||
|
|
130
|
+
event.key === "Process" ||
|
|
131
|
+
event.key === "Unidentified");
|
|
132
|
+
}
|
|
133
|
+
compositionStart() {
|
|
134
|
+
this.#composing = true;
|
|
135
|
+
this.#forgetEdit();
|
|
136
|
+
}
|
|
137
|
+
compositionEnd(field, sink) {
|
|
138
|
+
this.#composing = false;
|
|
139
|
+
this.#forgetEdit();
|
|
140
|
+
this.#flush(committedTextActions(field.value), field, sink);
|
|
141
|
+
}
|
|
142
|
+
/** A blur ends whatever composition a missed `compositionend` left behind; the field keeps its text for one still to come. */
|
|
143
|
+
blur() {
|
|
144
|
+
this.#composing = false;
|
|
145
|
+
this.#forgetEdit();
|
|
146
|
+
}
|
|
147
|
+
beforeInput(event, field, sink) {
|
|
148
|
+
this.#forgetEdit();
|
|
149
|
+
if (this.#composing || event.isComposing)
|
|
150
|
+
return;
|
|
151
|
+
if (!sink.interactive) {
|
|
152
|
+
if (event.cancelable)
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const actions = terminalBeforeInputActions(event, field.value);
|
|
157
|
+
if (!actions)
|
|
158
|
+
return;
|
|
159
|
+
if (!event.cancelable) {
|
|
160
|
+
const [only] = actions;
|
|
161
|
+
if (actions.length === 1 && only?.type === "key" && only.key !== "Enter")
|
|
162
|
+
this.#uncancelableDelete = only;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
this.#prevented = true;
|
|
167
|
+
sink.commit(actions);
|
|
168
|
+
}
|
|
169
|
+
input(event, field, sink) {
|
|
170
|
+
const composing = this.#composing || event.isComposing === true;
|
|
171
|
+
const prevented = this.#prevented;
|
|
172
|
+
const uncancelableDelete = this.#uncancelableDelete;
|
|
173
|
+
this.#forgetEdit();
|
|
174
|
+
if (composing)
|
|
175
|
+
return;
|
|
176
|
+
if (prevented) {
|
|
177
|
+
field.value = "";
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const actions = terminalInputActions({ inputType: event.inputType ?? "", isComposing: false }, field.value) ?? [];
|
|
181
|
+
this.#flush(actions.length === 0 && uncancelableDelete ? [uncancelableDelete] : actions, field, sink);
|
|
182
|
+
}
|
|
183
|
+
#flush(actions, field, sink) {
|
|
184
|
+
field.value = "";
|
|
185
|
+
if (sink.interactive && actions.length > 0)
|
|
186
|
+
sink.commit(actions);
|
|
187
|
+
}
|
|
188
|
+
#forgetEdit() {
|
|
189
|
+
this.#prevented = false;
|
|
190
|
+
this.#uncancelableDelete = null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Wires the textarea's text-input events to `textInput` and returns the
|
|
195
|
+
* cleanup. They are listened to natively: React's `onBeforeInput` is its own
|
|
196
|
+
* polyfill over keypress and textInput, not the DOM's `InputEvent`. Keydowns
|
|
197
|
+
* stay with the surface, which asks `textInput.keyDown` before its bindings.
|
|
198
|
+
*/
|
|
199
|
+
export function attachTerminalTextInput(field, textInput, sink) {
|
|
200
|
+
const listeners = [
|
|
201
|
+
["beforeinput", (event) => textInput.beforeInput(event, field, sink)],
|
|
202
|
+
["input", (event) => textInput.input(event, field, sink)],
|
|
203
|
+
["compositionstart", () => textInput.compositionStart()],
|
|
204
|
+
["compositionend", () => textInput.compositionEnd(field, sink)],
|
|
205
|
+
["blur", () => textInput.blur()],
|
|
206
|
+
];
|
|
207
|
+
for (const [type, listener] of listeners)
|
|
208
|
+
field.addEventListener(type, listener);
|
|
209
|
+
return () => {
|
|
210
|
+
for (const [type, listener] of listeners)
|
|
211
|
+
field.removeEventListener(type, listener);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=text-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-input.js","sourceRoot":"","sources":["../src/text-input.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,aAAa,EAA+B,MAAM,qBAAqB,CA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AC,CAAC;IACjF,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,SAAS;YAAE,KAAK,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtF,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -31,7 +31,12 @@ export interface GhostteaWorkspacePlatform {
|
|
|
31
31
|
configEditor?: GhostteaConfigEditorBridge;
|
|
32
32
|
backdropBlur?: GhostteaBackdropBlurBridge;
|
|
33
33
|
newTab?: (cwd?: string) => void;
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Ghostty `goto_tab` and its relatives. Return false when the selected tab
|
|
36
|
+
* would not change (one tab, or already selected): a `performable:` bind's
|
|
37
|
+
* key then reaches the terminal, as Ghostty's does.
|
|
38
|
+
*/
|
|
39
|
+
selectTab?: (target: "previous" | "next" | "last" | number) => boolean | void;
|
|
35
40
|
closeTab?: () => void;
|
|
36
41
|
onMenuAction: (listener: (action: TerminalMenuAction) => void) => () => void;
|
|
37
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../src/workspace/Workspace.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,aAAa,EAEnB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAmB,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAMnD,OAAO,EAiBL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,W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sB,EACtB,oBAA2B,EAC3B,MAAa,EACb,cAAc,EACd,YAAmB,EACnB,qBAA4B,EAC5B,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,mBAA2B,GAC5B,EAAE,sBAAsB,+BAqnBxB"}
|
|
@@ -12,9 +12,10 @@ import { TERMINAL_THEMES } from "./themes.js";
|
|
|
12
12
|
import { appendPane, collectDeadPanes, containsPane, equalize, insertPane, layoutId, leaves, mountSessionInPane, pane, persistedWorkspace, removePane, replaceSessionInPanes, resizeForPane, restoreNode, updateSession, updateSplit, } from "./pane-layout.js";
|
|
13
13
|
import { resolveKeyEvent, routeConsumesInput } from "../bindings/action-route.js";
|
|
14
14
|
import { configuredBindingsForPlatform } from "../bindings/ghostty-bindings.js";
|
|
15
|
+
import { runWorkspaceBinding } from "./hotkeys.js";
|
|
15
16
|
import { PendingPromiseCache } from "./pending-cache.js";
|
|
16
17
|
import { sessionsToClaim } from "./session-scope.js";
|
|
17
|
-
import { createPaneFocusScheduler } from "./pane-focus.js";
|
|
18
|
+
import { createPaneFocusScheduler, directionalPaneTarget, paneBoxes, relativePaneTarget } from "./pane-focus.js";
|
|
18
19
|
import { decodeWorkspaceDocument } from "./workspace-model.js";
|
|
19
20
|
const DEFAULT_STORAGE_KEY = "ghosttea:workspace:v1";
|
|
20
21
|
export function workspaceOwnsHotkey(active, root, target, activeElement, blocked = false) {
|
|
@@ -501,44 +502,16 @@ export function GhostteaWorkspace({ platform, storageKey = DEFAULT_STORAGE_KEY,
|
|
|
501
502
|
creatingSessionRef.current = false;
|
|
502
503
|
}
|
|
503
504
|
}, [activatePane, createSplitSession, platform.defaultShell, terminalRuntime]);
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
activatePane(
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if (zoomedPaneId)
|
|
515
|
-
return;
|
|
516
|
-
const elements = Array.from(workspaceRef.current?.querySelectorAll("[data-pane-id]") ?? []);
|
|
517
|
-
const current = elements.find((element) => element.dataset.paneId === activePaneId);
|
|
518
|
-
if (!current)
|
|
519
|
-
return;
|
|
520
|
-
const source = current.getBoundingClientRect();
|
|
521
|
-
const sourceX = source.left + source.width / 2;
|
|
522
|
-
const sourceY = source.top + source.height / 2;
|
|
523
|
-
let best;
|
|
524
|
-
for (const element of elements) {
|
|
525
|
-
const id = element.dataset.paneId;
|
|
526
|
-
if (!id || id === activePaneId)
|
|
527
|
-
continue;
|
|
528
|
-
const rect = element.getBoundingClientRect();
|
|
529
|
-
const dx = rect.left + rect.width / 2 - sourceX;
|
|
530
|
-
const dy = rect.top + rect.height / 2 - sourceY;
|
|
531
|
-
const forward = direction === "left" ? -dx : direction === "right" ? dx : direction === "up" ? -dy : dy;
|
|
532
|
-
if (forward <= 0)
|
|
533
|
-
continue;
|
|
534
|
-
const cross = direction === "left" || direction === "right" ? Math.abs(dy) : Math.abs(dx);
|
|
535
|
-
const score = forward + cross * 2;
|
|
536
|
-
if (!best || score < best.score)
|
|
537
|
-
best = { id, score };
|
|
538
|
-
}
|
|
539
|
-
if (best)
|
|
540
|
-
activatePane(best.id);
|
|
541
|
-
}, [activatePane, activePaneId, zoomedPaneId]);
|
|
505
|
+
// Ghostty's goto_split, which says whether focus moved. Ghostty's default
|
|
506
|
+
// (`split-preserve-zoom` without `navigation`, Config.zig:1102, :8671) ends
|
|
507
|
+
// a zoom to go to another pane (GTK split_tree.zig:367-385).
|
|
508
|
+
const goToPane = useCallback((target) => {
|
|
509
|
+
if (target === null)
|
|
510
|
+
return false;
|
|
511
|
+
setZoomedPaneId(null);
|
|
512
|
+
activatePane(target);
|
|
513
|
+
return true;
|
|
514
|
+
}, [activatePane]);
|
|
542
515
|
const closePane = useCallback((paneId) => {
|
|
543
516
|
const current = layoutRef.current;
|
|
544
517
|
const panes = leaves(current);
|
|
@@ -597,32 +570,46 @@ export function GhostteaWorkspace({ platform, storageKey = DEFAULT_STORAGE_KEY,
|
|
|
597
570
|
creatingSessionRef.current = false;
|
|
598
571
|
}
|
|
599
572
|
}, [addSession, terminalRuntime]);
|
|
573
|
+
// What decides whether a binding's command can be performed (hotkeys.ts).
|
|
574
|
+
const bindingState = useMemo(() => ({
|
|
575
|
+
panes: leaves(layout).length,
|
|
576
|
+
activePane: activePane !== undefined,
|
|
577
|
+
remoteSessions: enableRemoteSessions,
|
|
578
|
+
hooks: {
|
|
579
|
+
newTab: platform.newTab !== undefined,
|
|
580
|
+
selectTab: platform.selectTab !== undefined,
|
|
581
|
+
closeTab: platform.closeTab !== undefined,
|
|
582
|
+
newWindow: platform.newWindow !== undefined,
|
|
583
|
+
openConfig: platform.openConfig !== undefined,
|
|
584
|
+
},
|
|
585
|
+
}), [activePane, enableRemoteSessions, layout, platform]);
|
|
586
|
+
// Runs a command runWorkspaceBinding found performable. It returns false
|
|
587
|
+
// only when the command changed nothing: `selectTab`'s own answer.
|
|
600
588
|
const executeWorkspaceCommand = useCallback((command) => {
|
|
601
589
|
if (command.type === "new-tab") {
|
|
602
590
|
platform.newTab?.(activePane?.session.cwd ?? undefined);
|
|
603
591
|
}
|
|
604
592
|
else if (command.type === "select-tab") {
|
|
605
|
-
platform.selectTab?.(command.target);
|
|
593
|
+
return platform.selectTab?.(command.target);
|
|
606
594
|
}
|
|
607
595
|
else if (command.type === "close-tab") {
|
|
608
596
|
platform.closeTab?.();
|
|
609
597
|
}
|
|
610
598
|
else if (command.type === "remote-sessions") {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
setRemotePaletteOpen(true);
|
|
614
|
-
}
|
|
599
|
+
setRemotePaletteDeviceId(undefined);
|
|
600
|
+
setRemotePaletteOpen(true);
|
|
615
601
|
}
|
|
616
602
|
else if (command.type === "split") {
|
|
617
603
|
void newSplit(command.axis);
|
|
618
604
|
}
|
|
619
605
|
else if (command.type === "focus-relative") {
|
|
620
|
-
|
|
606
|
+
return goToPane(relativePaneTarget(layout, activePaneId, command.offset));
|
|
621
607
|
}
|
|
622
608
|
else if (command.type === "focus-direction") {
|
|
623
|
-
|
|
609
|
+
return goToPane(directionalPaneTarget(paneBoxes(layout), activePaneId, command.direction));
|
|
624
610
|
}
|
|
625
611
|
else if (command.type === "resize") {
|
|
612
|
+
// Only a split on the axis moves, but Ghostty counts the resize performed either way.
|
|
626
613
|
if (activePaneId) {
|
|
627
614
|
setLayout((current) => current ? resizeForPane(current, activePaneId, command.axis, command.delta)[0] : current);
|
|
628
615
|
}
|
|
@@ -639,17 +626,8 @@ export function GhostteaWorkspace({ platform, storageKey = DEFAULT_STORAGE_KEY,
|
|
|
639
626
|
else if (command.type === "close-pane") {
|
|
640
627
|
closeActivePane();
|
|
641
628
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
activePane?.session.cwd,
|
|
645
|
-
activePaneId,
|
|
646
|
-
closeActivePane,
|
|
647
|
-
enableRemoteSessions,
|
|
648
|
-
focusDirection,
|
|
649
|
-
focusRelative,
|
|
650
|
-
newSplit,
|
|
651
|
-
platform,
|
|
652
|
-
]);
|
|
629
|
+
return true;
|
|
630
|
+
}, [onTogglePaneZoom, activePane?.session.cwd, activePaneId, closeActivePane, goToPane, layout, newSplit, platform]);
|
|
653
631
|
useEffect(() => {
|
|
654
632
|
const onKeyDown = (event) => {
|
|
655
633
|
if (!workspaceOwnsHotkey(active, workspaceRef.current, event.target, document.activeElement, appearanceSettingsOpen)) {
|
|
@@ -662,61 +640,52 @@ export function GhostteaWorkspace({ platform, storageKey = DEFAULT_STORAGE_KEY,
|
|
|
662
640
|
bindings,
|
|
663
641
|
scopes: ["workspace", "platform", "unhandled"],
|
|
664
642
|
});
|
|
665
|
-
if (!routed)
|
|
643
|
+
if (!routed || routed.kind === "terminal")
|
|
666
644
|
return;
|
|
667
|
-
// After a successful match, always consume. Missing hooks no-op the effect
|
|
668
|
-
// but must not leak Ghostty app binds into the PTY (review P0).
|
|
669
645
|
const consume = () => {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
event.stopPropagation();
|
|
673
|
-
}
|
|
646
|
+
event.preventDefault();
|
|
647
|
+
event.stopPropagation();
|
|
674
648
|
};
|
|
675
649
|
if (remotePaletteOpen) {
|
|
676
650
|
if (routed.kind === "workspace" && routed.command.type === "remote-sessions") {
|
|
677
651
|
setRemotePaletteOpen(false);
|
|
678
652
|
}
|
|
679
653
|
// Drop other app binds while the palette is open; still consume them.
|
|
680
|
-
|
|
654
|
+
if (routeConsumesInput(routed))
|
|
655
|
+
consume();
|
|
681
656
|
return;
|
|
682
657
|
}
|
|
683
|
-
|
|
684
|
-
if (
|
|
685
|
-
if (!(routed.command.type === "new-tab" && !platform.newTab)) {
|
|
686
|
-
if (!(routed.command.type === "select-tab" && !platform.selectTab)) {
|
|
687
|
-
if (!(routed.command.type === "close-tab" && !platform.closeTab)) {
|
|
688
|
-
executeWorkspaceCommand(routed.command);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
else if (routed.kind === "platform") {
|
|
695
|
-
if (routed.effect.type === "toggle_fullscreen")
|
|
658
|
+
const executePlatformEffect = (effect) => {
|
|
659
|
+
if (effect.type === "toggle_fullscreen")
|
|
696
660
|
platform.toggleFullscreen();
|
|
697
|
-
else if (
|
|
661
|
+
else if (effect.type === "close_window")
|
|
698
662
|
platform.closeWindow();
|
|
699
|
-
else if (
|
|
663
|
+
else if (effect.type === "close_all_windows") {
|
|
700
664
|
(platform.closeAllWindows ?? platform.closeWindow)();
|
|
701
665
|
}
|
|
702
|
-
else if (
|
|
666
|
+
else if (effect.type === "new_window") {
|
|
703
667
|
(platform.newWindow ?? platform.newTab)?.(activePane?.session.cwd ?? undefined);
|
|
704
668
|
}
|
|
705
|
-
else if (
|
|
669
|
+
else if (effect.type === "quit") {
|
|
706
670
|
(platform.quit ?? platform.closeWindow)();
|
|
707
671
|
}
|
|
708
|
-
else if (
|
|
672
|
+
else if (effect.type === "open_config") {
|
|
709
673
|
platform.openConfig?.();
|
|
710
674
|
}
|
|
711
|
-
else if (
|
|
675
|
+
else if (effect.type === "reload_config") {
|
|
712
676
|
void terminalRuntime.reloadConfig().catch((cause) => {
|
|
713
677
|
console.error("[terminal-runtime] configuration reload failed", cause);
|
|
714
678
|
platform.reloadConfig?.();
|
|
715
679
|
});
|
|
716
680
|
}
|
|
717
|
-
}
|
|
718
|
-
//
|
|
719
|
-
|
|
681
|
+
};
|
|
682
|
+
// A bind that is not performable consumes its key even when a missing
|
|
683
|
+
// hook no-ops it, so Ghostty app binds never leak into the PTY (review
|
|
684
|
+
// P0). A key the bind leaves (unconsumed, or performable and not
|
|
685
|
+
// performed) reaches the focused surface, which sends it.
|
|
686
|
+
const host = { state: bindingState, workspace: executeWorkspaceCommand, platform: executePlatformEffect };
|
|
687
|
+
if (runWorkspaceBinding(routed, host))
|
|
688
|
+
consume();
|
|
720
689
|
};
|
|
721
690
|
window.addEventListener("keydown", onKeyDown, true);
|
|
722
691
|
return () => window.removeEventListener("keydown", onKeyDown, true);
|
|
@@ -724,8 +693,8 @@ export function GhostteaWorkspace({ platform, storageKey = DEFAULT_STORAGE_KEY,
|
|
|
724
693
|
active,
|
|
725
694
|
activePane?.session.cwd,
|
|
726
695
|
appearanceSettingsOpen,
|
|
696
|
+
bindingState,
|
|
727
697
|
bindings,
|
|
728
|
-
enableRemoteSessions,
|
|
729
698
|
executeWorkspaceCommand,
|
|
730
699
|
platform,
|
|
731
700
|
remotePaletteOpen,
|