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,6 +490,8 @@ type ProviderData = {
setGenerate((prev) => ({ ...prev, show: false })); setGenerate((prev) => ({ ...prev, show: false }));
//editor windows fix
function updateTabs(){
const exists = tabs.find((t) => t.id === tab.id); const exists = tabs.find((t) => t.id === tab.id);
setTabs((prev) => { setTabs((prev) => {
if (exists) { if (exists) {
@ -507,18 +500,18 @@ type ProviderData = {
} }
return [...prev, tab]; return [...prev, tab];
}); });
}
// if (fileCache.current.has(tab.id)) { if (fileCache.current.has(tab.id)) {
// setActiveFileContent(fileCache.current.get(tab.id)); setActiveFileContent(fileCache.current.get(tab.id));
// } else { updateTabs();
// debouncedGetFile(tab.id, (response: SetStateAction<string>) => { } else {
// fileCache.current.set(tab.id, response); debouncedGetFile(tab.id, (response: SetStateAction<string>) => {
// setActiveFileContent(response); fileCache.current.set(tab.id, response);
// }); setActiveFileContent(response);
// } updateTabs();
});
// Always set empty content for new files }
setActiveFileContent("");
setEditorLanguage(processFileType(tab.name)); setEditorLanguage(processFileType(tab.name));
setActiveFileId(tab.id); setActiveFileId(tab.id);