fix: editor on windows

This commit is contained in:
Akhilesh Rangani 2024-07-08 16:48:06 -04:00
parent 398139ec36
commit d9ce147e09

View File

@ -350,26 +350,17 @@ type ProviderData = {
const yText = yDoc.getText(tab.id); const yText = yDoc.getText(tab.id);
const yProvider = new LiveblocksProvider(room, yDoc); const yProvider = new LiveblocksProvider(room, yDoc);
// const onSync = (isSynced: boolean) => {
// if (isSynced) {
// const text = yText.toString()
// if (text === "") {
// if (activeFileContent) {
// yText.insert(0, activeFileContent)
// } else {
// setTimeout(() => {
// yText.insert(0, editorRef.getValue())
// }, 0)
// }
// }
// }
// }
const onSync = (isSynced: boolean) => { const onSync = (isSynced: boolean) => {
if (isSynced) { if (isSynced) {
const text = yText.toString() const text = yText.toString()
if (text === "") { if (text === "") {
// Not inserting any initial content if (activeFileContent) {
yText.insert(0, activeFileContent)
} else {
setTimeout(() => {
yText.insert(0, editorRef.getValue())
}, 0)
}
} }
} }
} }
@ -484,7 +475,7 @@ type ProviderData = {
// Select file and load content // Select file and load content
// Initialize debounced function once // Initialize debounced function once
// const fileCache = useRef(new Map()); const fileCache = useRef(new Map());
// Debounced function to get file content // Debounced function to get file content
const debouncedGetFile = useCallback( const debouncedGetFile = useCallback(
@ -499,26 +490,28 @@ type ProviderData = {
setGenerate((prev) => ({ ...prev, show: false })); setGenerate((prev) => ({ ...prev, show: false }));
const exists = tabs.find((t) => t.id === tab.id); //editor windows fix
setTabs((prev) => { function updateTabs(){
if (exists) { const exists = tabs.find((t) => t.id === tab.id);
setActiveFileId(exists.id); setTabs((prev) => {
return prev; if (exists) {
} setActiveFileId(exists.id);
return [...prev, tab]; return prev;
}); }
return [...prev, tab];
// if (fileCache.current.has(tab.id)) { });
// setActiveFileContent(fileCache.current.get(tab.id)); }
// } else {
// debouncedGetFile(tab.id, (response: SetStateAction<string>) => { if (fileCache.current.has(tab.id)) {
// fileCache.current.set(tab.id, response); setActiveFileContent(fileCache.current.get(tab.id));
// setActiveFileContent(response); updateTabs();
// }); } else {
// } debouncedGetFile(tab.id, (response: SetStateAction<string>) => {
fileCache.current.set(tab.id, response);
// Always set empty content for new files setActiveFileContent(response);
setActiveFileContent(""); updateTabs();
});
}
setEditorLanguage(processFileType(tab.name)); setEditorLanguage(processFileType(tab.name));
setActiveFileId(tab.id); setActiveFileId(tab.id);