From 8e047f45f59208419beaf17c3e0e25ee48ebda5d Mon Sep 17 00:00:00 2001 From: purian23 Date: Wed, 18 Mar 2026 00:10:35 -0400 Subject: [PATCH] (notepad): Update tab loading with request ID validation --- .../Modules/Notepad/NotepadTextEditor.qml | 9 +++++++++ quickshell/Services/NotepadStorageService.qml | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/quickshell/Modules/Notepad/NotepadTextEditor.qml b/quickshell/Modules/Notepad/NotepadTextEditor.qml index 527bc47a..7ea0b27d 100644 --- a/quickshell/Modules/Notepad/NotepadTextEditor.qml +++ b/quickshell/Modules/Notepad/NotepadTextEditor.qml @@ -31,6 +31,7 @@ Column { property string previewMode: "split" // split | full property string pluginHighlightedHtml: "" property string lastPluginContent: "" + property int loadRequestId: 0 signal saveRequested() signal openRequested() @@ -54,10 +55,18 @@ Column { function loadCurrentTabContent() { if (!currentTab) return + const requestedTabId = currentTab.id + const requestId = ++loadRequestId contentLoaded = false NotepadStorageService.loadTabContent( NotepadStorageService.currentTabIndex, (content) => { + const activeTab = NotepadStorageService.tabs.length > NotepadStorageService.currentTabIndex + ? NotepadStorageService.tabs[NotepadStorageService.currentTabIndex] + : null + if (requestId !== loadRequestId || !activeTab || activeTab.id !== requestedTabId) + return + lastSavedContent = content textArea.text = content contentLoaded = true diff --git a/quickshell/Services/NotepadStorageService.qml b/quickshell/Services/NotepadStorageService.qml index 02dfd6b5..3a6257a4 100644 --- a/quickshell/Services/NotepadStorageService.qml +++ b/quickshell/Services/NotepadStorageService.qml @@ -102,6 +102,14 @@ Singleton { metadataFile.setText(JSON.stringify(metadata, null, 2)) } + function getTabById(tabId) { + for (var i = 0; i < tabs.length; i++) { + if (tabs[i].id === tabId) + return tabs[i] + } + return null + } + function loadTabContent(tabIndex, callback) { if (tabIndex < 0 || tabIndex >= tabs.length) { callback("") @@ -109,6 +117,7 @@ Singleton { } var tab = tabs[tabIndex] + var requestTabId = tab.id var fullPath = tab.isTemporary ? baseDir + "/" + tab.filePath : tab.filePath @@ -123,6 +132,16 @@ Singleton { var fileChecker = fileExistsComponent.createObject(root, { path: fullPath, callback: (exists) => { + var currentTab = root.getTabById(requestTabId) + var currentPath = currentTab + ? (currentTab.isTemporary ? baseDir + "/" + currentTab.filePath : currentTab.filePath) + : "" + + if (!currentTab || currentPath !== fullPath) { + callback("") + return + } + if (exists) { var loader = tabFileLoaderComponent.createObject(root, { path: fullPath,