mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-11 16:22:09 -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 previewMode: "split" // split | full
|
||||||
property string pluginHighlightedHtml: ""
|
property string pluginHighlightedHtml: ""
|
||||||
property string lastPluginContent: ""
|
property string lastPluginContent: ""
|
||||||
|
property int loadRequestId: 0
|
||||||
|
|
||||||
signal saveRequested()
|
signal saveRequested()
|
||||||
signal openRequested()
|
signal openRequested()
|
||||||
@@ -54,10 +55,18 @@ Column {
|
|||||||
function loadCurrentTabContent() {
|
function loadCurrentTabContent() {
|
||||||
if (!currentTab) return
|
if (!currentTab) return
|
||||||
|
|
||||||
|
const requestedTabId = currentTab.id
|
||||||
|
const requestId = ++loadRequestId
|
||||||
contentLoaded = false
|
contentLoaded = false
|
||||||
NotepadStorageService.loadTabContent(
|
NotepadStorageService.loadTabContent(
|
||||||
NotepadStorageService.currentTabIndex,
|
NotepadStorageService.currentTabIndex,
|
||||||
(content) => {
|
(content) => {
|
||||||
|
const activeTab = NotepadStorageService.tabs.length > NotepadStorageService.currentTabIndex
|
||||||
|
? NotepadStorageService.tabs[NotepadStorageService.currentTabIndex]
|
||||||
|
: null
|
||||||
|
if (requestId !== loadRequestId || !activeTab || activeTab.id !== requestedTabId)
|
||||||
|
return
|
||||||
|
|
||||||
lastSavedContent = content
|
lastSavedContent = content
|
||||||
textArea.text = content
|
textArea.text = content
|
||||||
contentLoaded = true
|
contentLoaded = true
|
||||||
|
|||||||
@@ -102,6 +102,14 @@ Singleton {
|
|||||||
metadataFile.setText(JSON.stringify(metadata, null, 2))
|
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) {
|
function loadTabContent(tabIndex, callback) {
|
||||||
if (tabIndex < 0 || tabIndex >= tabs.length) {
|
if (tabIndex < 0 || tabIndex >= tabs.length) {
|
||||||
callback("")
|
callback("")
|
||||||
@@ -109,6 +117,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tab = tabs[tabIndex]
|
var tab = tabs[tabIndex]
|
||||||
|
var requestTabId = tab.id
|
||||||
var fullPath = tab.isTemporary
|
var fullPath = tab.isTemporary
|
||||||
? baseDir + "/" + tab.filePath
|
? baseDir + "/" + tab.filePath
|
||||||
: tab.filePath
|
: tab.filePath
|
||||||
@@ -123,6 +132,16 @@ Singleton {
|
|||||||
var fileChecker = fileExistsComponent.createObject(root, {
|
var fileChecker = fileExistsComponent.createObject(root, {
|
||||||
path: fullPath,
|
path: fullPath,
|
||||||
callback: (exists) => {
|
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) {
|
if (exists) {
|
||||||
var loader = tabFileLoaderComponent.createObject(root, {
|
var loader = tabFileLoaderComponent.createObject(root, {
|
||||||
path: fullPath,
|
path: fullPath,
|
||||||
|
|||||||
Reference in New Issue
Block a user