feat(search): add global file content search in QuickOpen

This commit is contained in:
gggaiitx authored and GitHub committed 2026-09-19 00:21:27 +08:00
1 parent 5278594ed2
commit 04c6e67bbd
31 files changed
+1509 -16

No files matched your search

@@ -254,6 +254,7 @@ const props = defineProps<{
canExplain?: boolean;
initialViewport?: { scrollTop: number; scrollLeft: number };
initialSelection?: { anchor: number; head: number };
revealRequest?: { id: number; line: number; column?: number };
statementExecutionMarkers?: StatementExecutionMarker[];
}>();
@@ -299,6 +300,7 @@ const emit = defineEmits<{
viewportChange: [viewport: { scrollTop: number; scrollLeft: number }, tabId?: string];
selectionStateChange: [selection: { anchor: number; head: number }];
editorStateFlushed: [];
editorRevealConsumed: [];
sendSelectionToAi: [sql: string];
}>();
@@ -7493,6 +7495,7 @@ onMounted(async () => {
restoreEditorSelection(props.initialSelection, !props.initialViewport);
restoreEditorViewport();
performEditorReveal();
syncContextMenuState(view.value);
emit("previewChangesAvailable", !!previewContextSql.value);
syncEditorFontCssVars(liveFontSize.value, initialSettings.fontFamily);
@@ -7674,6 +7677,16 @@ watch(
{ deep: true },
);
// A content-search jump. Fires on id change (a new or reused tab, or a repeat
// click on the same result), and on mount when the request is already pending.
watch(
() => props.revealRequest?.id,
(id, previousId) => {
if (!id || id === previousId) return;
performEditorReveal();
},
);
watch(
() => props.formatRequestId,
(val) => {
@@ -8045,6 +8058,28 @@ function restoreEditorSelection(selection = props.initialSelection ?? latestSele
view.value.dispatch({ selection: normalizedSelection, scrollIntoView });
}
/** Move cursor/scroll to a 1-based line/column, e.g. from a global content-search match. */
function revealEditorSelection(line: number, column?: number) {
const currentView = view.value;
const EditorSelection = codeMirrorEditorSelection;
if (!currentView || !EditorSelection) return;
const doc = currentView.state.doc;
const targetLine = Math.max(1, Math.min(line ?? 1, doc.lines));
const lineOffset = doc.line(targetLine).from;
const charColumn = Math.max(1, column ?? 1);
const offset = Math.min(lineOffset + charColumn - 1, doc.length);
currentView.dispatch({ selection: EditorSelection.cursor(offset), scrollIntoView: true });
focusEditorView(currentView);
}
/** Consume a pending reveal request (fires once per new id / on mount). */
function performEditorReveal() {
const request = props.revealRequest;
if (!request || !view.value) return;
revealEditorSelection(request.line, request.column);
emit("editorRevealConsumed");
}
function restoreEditorFocus() {
const focusEditorAcrossFrames = () => {
focusEditorView(view.value);