The best way to control Claude Code, Codex and more from any computer or phone

main
patch 351 lines 16 KB
Raw
1 diff --git a/dist/editor/editor.js b/dist/editor/editor.js
2 index b4c280390b52434f63fbe7916d81b150d9006fb4..db87ba385f927d793a80d908cd575216d22a09a7 100644
3 --- a/dist/editor/editor.js
4 +++ b/dist/editor/editor.js
5 @@ -95,6 +95,8 @@ var Editor = class {
6 #deletionsColumn;
7 #overlayElement;
8 #overlayElements;
9 + #fontProbeElement;
10 + #lineReveal;
11 #caretElements;
12 #caretHighlightElements;
13 #primaryCaretElement;
14 @@ -125,6 +127,7 @@ var Editor = class {
15 #altColumnDrag;
16 #shiftKeyPressed = false;
17 #selectionStart;
18 + #dragAnchorUnmounted = false;
19 #deletedSelectionText = "";
20 #reservedSelections;
21 #initSelections;
22 @@ -536,6 +539,7 @@ var Editor = class {
23 const fileInstance = this.#fileInstance;
24 const recycle = reason === "recycle";
25 this.#virtualizedInstance?.cancelScroll(this.#handleCaretRevealDone);
26 + this.#virtualizedInstance?.cancelScroll(this.#handleLineRevealDone);
27 this.#cancelEditPrediction(true, false);
28 if (!recycle) this.#editPredictionHistory = [];
29 const editSession = this.#editSession;
30 @@ -584,6 +588,7 @@ var Editor = class {
31 this.#contentHasFocus = false;
32 this.#overlayElement?.remove();
33 this.#overlayElement = void 0;
34 + this.#fontProbeElement = void 0;
35 this.#resizeObserver?.disconnect();
36 this.#resizeObserver = void 0;
37 this.#fontRemeasureScheduled = false;
38 @@ -657,6 +662,7 @@ var Editor = class {
39 }
40 /** @internal */
41 __captureFocusForDOMReplacement() {
42 + if (this.#isContentMouseDown) return;
43 const contentElement = this.#contentElement;
44 const shadowActiveElement = this.#fileContainer?.shadowRoot?.activeElement;
45 if (contentElement != null && (this.#contentHasFocus || shadowActiveElement === contentElement || shadowActiveElement != null && contentElement.contains(shadowActiveElement))) {
46 @@ -839,7 +845,9 @@ var Editor = class {
47 this.#initSelections = void 0;
48 this.#scrollToPrimaryCaret(false, "center");
49 } else if (this.#scrollingToLine !== void 0) this.#scrollToLine(this.#scrollingToLine, this.#scrollingToLineChar, this.#scrollingToLineNoFocus);
50 - else if (this.#focusRequest?.restore != null) this.#restoreReplacementFocus();
51 + else if (this.#isContentMouseDown) {
52 + if (this.#focusRequest?.restore != null) this.#cancelFocusRequest();
53 + } else if (this.#focusRequest?.restore != null) this.#restoreReplacementFocus();
54 else if (this.#selections !== void 0 && this.#selections.length > 0 && this.#contentHasFocus && !this.#retainSearchPanelFocus) this.focus({ preventScroll: true });
55 if (this.#retainSearchPanelFocus) this.#searchPanel?.focus();
56 if (restoreEditorStateOnSync) {
57 @@ -1022,6 +1030,19 @@ var Editor = class {
58 this.#tokenizer?.applyStyle();
59 this.#spriteElement = createSpriteElement();
60 this.#overlayElement = h("div", { dataset: "editorOverlay" });
61 + // Resizes when the inherited code font changes, so the observer can re-measure.
62 + this.#fontProbeElement = h("span", {
63 + ariaHidden: "true",
64 + style: {
65 + position: "absolute",
66 + top: "0",
67 + left: "0",
68 + visibility: "hidden",
69 + pointerEvents: "none",
70 + whiteSpace: "pre"
71 + },
72 + textContent: "0"
73 + }, this.#overlayElement);
74 const replacementFocusTargetIsContent = (event) => {
75 const target = event.composedPath()[0];
76 return target instanceof Node && this.#contentElement?.contains(target) === true;
77 @@ -1034,7 +1055,11 @@ var Editor = class {
78 const finishMouseSelection = (event) => {
79 if (event.pointerType !== "mouse") return;
80 const refocusEditor = this.#isGutterMouseDown;
81 + const primarySelection = this.#isContentMouseDown ? this.#selections?.at(-1) : void 0;
82 + const renderRange = this.#renderRange;
83 + const selectionLeavesRenderRange = primarySelection !== void 0 && renderRange !== void 0 && (primarySelection.start.line < renderRange.startingLine || primarySelection.end.line >= renderRange.startingLine + renderRange.totalLines);
84 this.#resetSelectionGesture();
85 + if (selectionLeavesRenderRange) this.#suppressNativeSelectionSync = true;
86 if (refocusEditor) this.#focus();
87 if (this.#options.enabledSelectionAction === true && this.#selections !== void 0 && this.#selections.length > 0 && !isCollapsedSelection(this.#selections.at(-1))) this.#updateSelections(this.#selections);
88 };
89 @@ -1061,15 +1086,17 @@ var Editor = class {
90 if (this.#selections !== void 0 && this.#selections.length > 1 && !this.#isContentMouseDown) return;
91 const composedRange = getComposedSelectionRange(shadowRoot);
92 if (composedRange === void 0 || !this.#rangeBelongsToEditor(composedRange)) return;
93 - const selection = convertSelection(composedRange, 0);
94 + let selection = convertSelection(composedRange, 0);
95 + if (this.#isContentMouseDown && !this.#shiftKeyPressed && this.#selectionStart !== void 0) selection = this.#resolveMouseDragSelection(composedRange, selection);
96 if (selection === void 0) return;
97 if (this.#isContentMouseDown && this.#shiftKeyPressed && this.#selections !== void 0 && this.#selections.length > 0) {
98 const primarySelection = this.#selections.at(-1);
99 this.#updateSelections([extendSelection(primarySelection, selection)]);
100 return;
101 }
102 - if (this.#selectionStart !== void 0) selection.direction = createSelectionFrom(this.#selectionStart, selection).direction;
103 - else if (this.#isContentMouseDown) this.#selectionStart = selection;
104 + if (this.#selectionStart !== void 0) {
105 + if (!this.#dragAnchorUnmounted) selection.direction = createSelectionFrom(this.#selectionStart, selection).direction;
106 + } else if (this.#isContentMouseDown) this.#selectionStart = selection;
107 else if (this.#selections !== void 0 && this.#selections.length === 1) {
108 const previous = this.#selections[0];
109 if (comparePosition(previous.start, selection.start) === 0 && comparePosition(previous.end, selection.end) === 0) selection.direction = previous.direction;
110 @@ -1104,8 +1131,50 @@ var Editor = class {
111 this.#altColumnDrag = void 0;
112 this.#shiftKeyPressed = false;
113 this.#selectionStart = void 0;
114 + this.#dragAnchorUnmounted = false;
115 this.#reservedSelections = void 0;
116 }
117 + #resolveMouseDragSelection(composedRange, selection) {
118 + const selectionStart = this.#selectionStart;
119 + if (selectionStart === void 0) return selection;
120 + const renderRange = this.#renderRange;
121 + if (renderRange !== void 0 && (selectionStart.start.line < renderRange.startingLine || selectionStart.end.line >= renderRange.startingLine + renderRange.totalLines)) this.#dragAnchorUnmounted = true;
122 + if (!this.#dragAnchorUnmounted) return selection;
123 + let focus;
124 + if (selection !== void 0) {
125 + const direction = window.getSelection()?.direction;
126 + if (direction === "backward") focus = selection.start;
127 + else if (direction === "forward") focus = selection.end;
128 + else focus = renderRange !== void 0 && selectionStart.end.line >= renderRange.startingLine + renderRange.totalLines ? selection.start : selection.end;
129 + } else {
130 + const startPos = convertSelection({
131 + startContainer: composedRange.startContainer,
132 + startOffset: composedRange.startOffset,
133 + endContainer: composedRange.startContainer,
134 + endOffset: composedRange.startOffset
135 + }, 0)?.start;
136 + const endPos = convertSelection({
137 + startContainer: composedRange.endContainer,
138 + startOffset: composedRange.endOffset,
139 + endContainer: composedRange.endContainer,
140 + endOffset: composedRange.endOffset
141 + }, 0)?.end;
142 + if (startPos !== void 0 && endPos === void 0) focus = startPos;
143 + else if (endPos !== void 0 && startPos === void 0) focus = endPos;
144 + else return;
145 + }
146 + if (comparePosition(focus, selectionStart.start) < 0) return {
147 + start: focus,
148 + end: selectionStart.end,
149 + direction: -1
150 + };
151 + if (comparePosition(focus, selectionStart.end) > 0) return {
152 + start: selectionStart.start,
153 + end: focus,
154 + direction: 1
155 + };
156 + return { ...selectionStart };
157 + }
158 #replaceSelectEventListeners(disposes) {
159 this.#selectEventDisposes?.forEach((dispose) => dispose());
160 this.#selectEventDisposes = disposes;
161 @@ -1130,6 +1199,7 @@ var Editor = class {
162 this.#editorEventDisposes = [
163 addEventListener(contentEl, "focus", () => {
164 this.#contentHasFocus = true;
165 + this.#retainSearchPanelFocus = false;
166 onFocus?.();
167 if (!this.#isContentMouseDown && !this.#isComposing && this.#focusRequest == null && this.#selections !== void 0 && this.#selections.length > 0) this.#setWindowSelection(this.#selections.at(-1));
168 }, { passive: true }),
169 @@ -1163,6 +1233,7 @@ var Editor = class {
170 this.#isContentMouseDown = true;
171 const isAltColumnDrag = e.button === 0 && e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
172 this.#selectionStart = void 0;
173 + this.#dragAnchorUnmounted = false;
174 if (isAltColumnDrag) {
175 this.#altColumnDrag = {
176 pointerId: e.pointerId,
177 @@ -1397,6 +1468,7 @@ var Editor = class {
178 this.#resizeObserver = new ResizeObserver(this.#handleLayoutResize);
179 this.#resizeObserver.observe(contentEl);
180 this.#resizeObserver.observe(contentEl.parentElement);
181 + if (this.#fontProbeElement !== void 0) this.#resizeObserver.observe(this.#fontProbeElement);
182 this.#computeContentOffset(contentEl);
183 }
184 #handleCustomPasteEvent = async () => {
185 @@ -1852,7 +1924,9 @@ var Editor = class {
186 const change = textDocument.applyEdits(edits, true, selections, nextSelections, true);
187 if (change !== void 0) this.#applyChange(change, nextSelections);
188 }
189 - #handleLayoutResize = () => {
190 + #handleLayoutResize = (entries) => {
191 + const contentElement = this.#contentElement;
192 + const metricsChanged = contentElement !== void 0 && entries.some((entry) => entry.target === this.#fontProbeElement) && this.#metrics.init(contentElement);
193 const lineAnnotations = this.#lineAnnotations?.length ?? 0;
194 const prevGutterWidth = this.#gutterWidthCache;
195 const prevContentWidth = this.#contentWidthCache;
196 @@ -1860,12 +1934,12 @@ var Editor = class {
197 this.#contentWidthCache = void 0;
198 const gutterWidthChanged = this.#getGutterWidth() !== prevGutterWidth;
199 const contentWidthChanged = this.#getContentWidth() !== prevContentWidth;
200 - if (!gutterWidthChanged && !contentWidthChanged) return;
201 + if (!gutterWidthChanged && !contentWidthChanged && !metricsChanged) return;
202 this.#lastAccessedCharX = void 0;
203 this.#metrics.clearTextWidthCache();
204 - if (contentWidthChanged) {
205 + if (contentWidthChanged || metricsChanged) {
206 this.#wrapLineOffsetsCache.clear();
207 - if (this.#isWrap || lineAnnotations > 0) this.#lineYCache.clear();
208 + if (metricsChanged || this.#isWrap || lineAnnotations > 0) this.#lineYCache.clear();
209 }
210 if (this.#selections !== void 0 || this.#matches !== void 0 || this.#markerRenderer !== void 0) {
211 this.#updateSelections(this.#selections ?? []);
212 @@ -2013,7 +2087,13 @@ var Editor = class {
213 return;
214 }
215 const primaryPosition = primarySelection.direction === -1 ? primarySelection.end : primarySelection.start;
216 - if (this.#getLineElement(primaryPosition.line) == null) return;
217 + if (this.#getLineElement(primaryPosition.line) == null) {
218 + const request = { restore: void 0 };
219 + this.#cancelFocusRequest();
220 + this.#focusRequest = request;
221 + queueRender(() => this.#releaseFocusRequest(request));
222 + return;
223 + }
224 this.#focus(primaryPosition, true, restore);
225 }
226 #replacementFocusIsAvailable(contentElement) {
227 @@ -2123,6 +2203,16 @@ var Editor = class {
228 this.#scrollCaretIntoView(line, character, "nearest");
229 }
230 };
231 + #handleLineRevealDone = (result) => {
232 + const target = this.#lineReveal;
233 + if (result !== "settled" || target === void 0) return;
234 + this.#lineReveal = void 0;
235 + const { line, char, noFocus } = target;
236 + if (this.#scrollCaretIntoView(line, char, "center") && !noFocus) this.#focusAt({
237 + line,
238 + character: char
239 + });
240 + };
241 #focusAt(position) {
242 if (this.#focusRequest?.restore != null) this.#restoreReplacementFocus(position);
243 else this.#focus(position);
244 @@ -2145,6 +2235,19 @@ var Editor = class {
245 this.#scrollingToLineNoFocus = false;
246 return;
247 }
248 + // The host knows wrapped row heights; a line-height estimate stops short of wrapped content.
249 + const host = this.#virtualizedInstance;
250 + if (host !== void 0) {
251 + this.#scrollingToLine = void 0;
252 + this.#scrollingToLineFixed = false;
253 + this.#lineReveal = {
254 + line,
255 + char,
256 + noFocus
257 + };
258 + host.scrollToLine(line + 1, "center", this.#handleLineRevealDone);
259 + return;
260 + }
261 let yFix = 0;
262 if (this.#scrollingToLine === line && this.#contentElement !== void 0) for (let i = this.#contentElement.childElementCount - 1; i >= 0; i--) {
263 const child = this.#contentElement.children[i];
264 @@ -3370,6 +3473,7 @@ var Editor = class {
265 this.#searchPanel = searchPanel;
266 this.#retainSearchPanelFocus = false;
267 searchPanel.mount();
268 + searchPanel.getHostElement().dataset.searchPanelOverlay = "";
269 }
270 #searchWithNavigationTarget(textDocument, searchParams) {
271 const viewport = this.#getSearchViewportBounds();
272 diff --git a/dist/editor/textMeasure.d.ts b/dist/editor/textMeasure.d.ts
273 index 89e938d89eca77d351aeed65f3c5495383effd97..cde1d6ba89a97bbb1614754a48f8994388c186bd 100644
274 --- a/dist/editor/textMeasure.d.ts
275 +++ b/dist/editor/textMeasure.d.ts
276 @@ -9,8 +9,8 @@ declare class Metrics {
277 lineHeight: number;
278 /** Padding top of the root element. */
279 paddingTop: number;
280 - /** initialize the metrics */
281 - init(root: HTMLElement): void;
282 + /** (re)read the metrics from root, returning true when they changed */
283 + init(root: HTMLElement): boolean;
284 /**
285 * Re-measure the '0' character width against the font that is loaded right
286 * now, returning true when measurement-dependent UI should refresh.
287 diff --git a/dist/editor/textMeasure.js b/dist/editor/textMeasure.js
288 index 96d4fb137ea683b66381b1ce6e47e8708a89366c..13f2564897a5bf53a8f311300003b3ea875c73a5 100644
289 --- a/dist/editor/textMeasure.js
290 +++ b/dist/editor/textMeasure.js
291 @@ -16,9 +16,10 @@ var Metrics = class {
292 lineHeight = 20;
293 /** Padding top of the root element. */
294 paddingTop = 0;
295 - /** initialize the metrics */
296 + /** (re)read the metrics from root, returning true when they changed */
297 init(root) {
298 - if (this.#root === root && this.#canvasCtx !== void 0 && this.ch !== -1) return;
299 + const previousLineHeight = this.lineHeight;
300 + let fontChanged = false;
301 this.#root = root;
302 this.#canvas ??= h("canvas", { style: { display: "none" } });
303 this.#canvasCtx ??= this.#canvas.getContext("2d") ?? void 0;
304 @@ -37,9 +38,11 @@ var Metrics = class {
305 this.#setCanvasFont(font);
306 this.ch = this.canvasMeasureTextWidth("0");
307 this.clearTextWidthCache();
308 + fontChanged = true;
309 }
310 const nextTabSize = parseInt(tabSize, 10);
311 if (!Number.isNaN(nextTabSize)) this.tabSize = nextTabSize;
312 + return fontChanged || this.lineHeight !== previousLineHeight;
313 }
314 /**
315 * Re-measure the '0' character width against the font that is loaded right
316 diff --git a/dist/utils/parsePatchFiles.js b/dist/utils/parsePatchFiles.js
317 index 48568bd6f669ba4826de17ba03caad466e1f0000..f27123f7c812c728ee8393792665ba288141771c 100644
318 --- a/dist/utils/parsePatchFiles.js
319 +++ b/dist/utils/parsePatchFiles.js
320 @@ -339,7 +339,7 @@ function parsePatchFiles(data, options = {}) {
321 return patches;
322 }
323 function decodeDiffFileName(value, stripGitPrefix = false) {
324 - const rawName = value.trim();
325 + const rawName = value.replace(/[\t\r\n]+$/, "");
326 const name = rawName.startsWith("\"") ? parseQuotedDiffFileName(rawName)?.fileName ?? rawName : rawName;
327 return stripGitPrefix && (name.startsWith("a/") || name.startsWith("b/")) ? name.slice(2) : name;
328 }
329 diff --git a/package.json b/package.json
330 index d1fa4d5d79ba70b6cd990b0ac9df5206fe55b58d..8762624a075174f5d9f35224cf091596d951a1a7 100644
331 --- a/package.json
332 +++ b/package.json
333 @@ -60,6 +60,18 @@
334 "./worker/worker-portable.js": {
335 "types": "./dist/worker/worker-portable.d.ts",
336 "import": "./dist/worker/worker-portable.js"
337 + },
338 + "./types": {
339 + "types": "./dist/types.d.ts",
340 + "import": "./dist/types.js"
341 + },
342 + "./utils/getFiletypeFromFileName": {
343 + "types": "./dist/utils/getFiletypeFromFileName.d.ts",
344 + "import": "./dist/utils/getFiletypeFromFileName.js"
345 + },
346 + "./utils/parsePatchFiles": {
347 + "types": "./dist/utils/parsePatchFiles.d.ts",
348 + "import": "./dist/utils/parsePatchFiles.js"
349 }
350 },
351 "publishConfig": {