Add editorReady state and update dependencies
This commit is contained in:
16
src/App.tsx
16
src/App.tsx
@@ -155,6 +155,7 @@ export default function App() {
|
|||||||
const [sidebarCollapsed, setSidebarCollapsed] = useState(() => {
|
const [sidebarCollapsed, setSidebarCollapsed] = useState(() => {
|
||||||
return localStorage.getItem("textdb.sidebarCollapsed") === "true";
|
return localStorage.getItem("textdb.sidebarCollapsed") === "true";
|
||||||
});
|
});
|
||||||
|
const [editorReady, setEditorReady] = useState(false);
|
||||||
|
|
||||||
const bodyRef = useRef(body);
|
const bodyRef = useRef(body);
|
||||||
const editorViewRef = useRef<EditorView | null>(null);
|
const editorViewRef = useRef<EditorView | null>(null);
|
||||||
@@ -207,6 +208,7 @@ export default function App() {
|
|||||||
if (editorViewRef.current) {
|
if (editorViewRef.current) {
|
||||||
editorViewRef.current.destroy();
|
editorViewRef.current.destroy();
|
||||||
editorViewRef.current = null;
|
editorViewRef.current = null;
|
||||||
|
setEditorReady(false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -234,6 +236,7 @@ export default function App() {
|
|||||||
});
|
});
|
||||||
editorViewRef.current = view;
|
editorViewRef.current = view;
|
||||||
editorValueRef.current = bodyRef.current;
|
editorValueRef.current = bodyRef.current;
|
||||||
|
setEditorReady(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const isViewingHistory = viewingVersion !== null;
|
const isViewingHistory = viewingVersion !== null;
|
||||||
@@ -379,7 +382,7 @@ export default function App() {
|
|||||||
view.dispatch({
|
view.dispatch({
|
||||||
effects: lineNumbersCompartmentRef.current.reconfigure(extensions)
|
effects: lineNumbersCompartmentRef.current.reconfigure(extensions)
|
||||||
});
|
});
|
||||||
}, [showLineNumbersActive]);
|
}, [editorReady, showLineNumbersActive]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const view = editorViewRef.current;
|
const view = editorViewRef.current;
|
||||||
@@ -389,7 +392,7 @@ export default function App() {
|
|||||||
EditorView.editable.of(!isViewingHistory && !markdownPreview)
|
EditorView.editable.of(!isViewingHistory && !markdownPreview)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}, [isViewingHistory, markdownPreview]);
|
}, [editorReady, isViewingHistory, markdownPreview]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const view = editorViewRef.current;
|
const view = editorViewRef.current;
|
||||||
@@ -415,7 +418,14 @@ export default function App() {
|
|||||||
view.dispatch({
|
view.dispatch({
|
||||||
effects: tabKeymapCompartmentRef.current.reconfigure(keys)
|
effects: tabKeymapCompartmentRef.current.reconfigure(keys)
|
||||||
});
|
});
|
||||||
}, [confirmState, editingFolderId, editingTextId, selectedTextId, settingsOpen]);
|
}, [
|
||||||
|
confirmState,
|
||||||
|
editorReady,
|
||||||
|
editingFolderId,
|
||||||
|
editingTextId,
|
||||||
|
selectedTextId,
|
||||||
|
settingsOpen
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const view = editorViewRef.current;
|
const view = editorViewRef.current;
|
||||||
|
|||||||
Reference in New Issue
Block a user