From 268790943f1a3680ac2e87303b26e12294169b07 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Sat, 18 Jan 2025 03:32:53 -0500 Subject: [PATCH] Add option to reopen file from last session --- src/main.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index 3723fa2..ee65f89 100644 --- a/src/main.js +++ b/src/main.js @@ -379,6 +379,7 @@ let config = { recentFiles: [], scrollSpeed: 1, debug: false, + reopenLastSession: false }; function getShortcut(shortcut) { @@ -421,13 +422,8 @@ async function saveConfig() { } async function addRecentFile(filePath) { - if (!config.recentFiles.includes(filePath)) { - config.recentFiles.unshift(filePath); - if (config.recentFiles.length > 10) { - config.recentFiles = config.recentFiles.slice(0, 10); - } - await saveConfig(config); - } + config.recentFiles = [filePath, ...config.recentFiles.filter(file => file !== filePath)].slice(0, 10); + await saveConfig(config); } // Pointers to all objects @@ -6730,7 +6726,11 @@ async function startup() { await loadConfig(); createNewFileDialog(_newFile, _open, config); if (!window.openedFiles?.length) { - showNewFileDialog(config); + if (config.reopenLastSession && config.recentFiles?.length) { + _open(config.recentFiles[0]) + } else { + showNewFileDialog(config); + } } }