mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-03 20:32:07 -04:00
(notepad): Update tab loading with request ID validation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user