fix: stop stale file focus requests from stealing context panel selection
This commit is contained in:
@@ -2762,32 +2762,30 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selectedFile?.path !== targetPath) {
|
if (selectedFile?.path !== targetPath) {
|
||||||
if (confirmDiscardOpen) {
|
// Selection is owned by the tab sync / user. A pending focus request must
|
||||||
return;
|
// not steal selection back (e.g. after the user switched to another tab
|
||||||
}
|
// while this file was still loading). Wait; clear once it loads or the
|
||||||
void handleSelectFile(toFileNode(targetPath));
|
// request is superseded.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileLoading || loadedFilePath !== targetPath || fileError || isSelectedImage || isSelectedPdf) {
|
if (fileLoading || loadedFilePath !== targetPath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canEdit && textViewMode === 'edit') {
|
// Best-effort focus: preview renderers (markdown/html preview, drawio,
|
||||||
const view = editorViewRef.current;
|
// JSON tree, images, PDFs) never mount a CodeMirror editor, so the request
|
||||||
if (!view) {
|
// must clear regardless — otherwise it lingers and replays on every
|
||||||
return;
|
// dependency change.
|
||||||
}
|
if (!fileError && !isSelectedImage && !isSelectedPdf && canEdit && textViewMode === 'edit') {
|
||||||
view.focus();
|
editorViewRef.current?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
setPendingFileFocusPath(null);
|
setPendingFileFocusPath(null);
|
||||||
}, [
|
}, [
|
||||||
canEdit,
|
canEdit,
|
||||||
confirmDiscardOpen,
|
|
||||||
fileError,
|
fileError,
|
||||||
fileLoading,
|
fileLoading,
|
||||||
handleSelectFile,
|
|
||||||
isSelectedImage,
|
isSelectedImage,
|
||||||
isSelectedPdf,
|
isSelectedPdf,
|
||||||
loadedFilePath,
|
loadedFilePath,
|
||||||
@@ -2796,7 +2794,6 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
selectedFile?.path,
|
selectedFile?.path,
|
||||||
setPendingFileFocusPath,
|
setPendingFileFocusPath,
|
||||||
textViewMode,
|
textViewMode,
|
||||||
toFileNode,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const nudgeEditorSelectionAboveKeyboard = React.useCallback((view: EditorView | null) => {
|
const nudgeEditorSelectionAboveKeyboard = React.useCallback((view: EditorView | null) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user