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 (confirmDiscardOpen) {
|
||||
return;
|
||||
}
|
||||
void handleSelectFile(toFileNode(targetPath));
|
||||
// Selection is owned by the tab sync / user. A pending focus request must
|
||||
// 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
|
||||
// request is superseded.
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileLoading || loadedFilePath !== targetPath || fileError || isSelectedImage || isSelectedPdf) {
|
||||
if (fileLoading || loadedFilePath !== targetPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (canEdit && textViewMode === 'edit') {
|
||||
const view = editorViewRef.current;
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
view.focus();
|
||||
// Best-effort focus: preview renderers (markdown/html preview, drawio,
|
||||
// JSON tree, images, PDFs) never mount a CodeMirror editor, so the request
|
||||
// must clear regardless — otherwise it lingers and replays on every
|
||||
// dependency change.
|
||||
if (!fileError && !isSelectedImage && !isSelectedPdf && canEdit && textViewMode === 'edit') {
|
||||
editorViewRef.current?.focus();
|
||||
}
|
||||
|
||||
setPendingFileFocusPath(null);
|
||||
}, [
|
||||
canEdit,
|
||||
confirmDiscardOpen,
|
||||
fileError,
|
||||
fileLoading,
|
||||
handleSelectFile,
|
||||
isSelectedImage,
|
||||
isSelectedPdf,
|
||||
loadedFilePath,
|
||||
@@ -2796,7 +2794,6 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
||||
selectedFile?.path,
|
||||
setPendingFileFocusPath,
|
||||
textViewMode,
|
||||
toFileNode,
|
||||
]);
|
||||
|
||||
const nudgeEditorSelectionAboveKeyboard = React.useCallback((view: EditorView | null) => {
|
||||
|
||||
Reference in New Issue
Block a user