From b7ecf6fb0b8ed3eb17acb59643206c5d69203232 Mon Sep 17 00:00:00 2001 From: Devanshu Date: Tue, 29 Sep 2026 19:08:18 +0000 Subject: [PATCH] feat: add reload file action --- src/lib/commands.js | 6 ++++++ src/lib/editorFile.js | 32 ++++++++++++++++++++++++++++++++ src/views/file-menu.hbs | 4 ++++ 3 files changed, 42 insertions(+) diff --git a/src/lib/commands.js b/src/lib/commands.js index de3a005a8e..ea18e57219 100644 --- a/src/lib/commands.js +++ b/src/lib/commands.js @@ -432,6 +432,12 @@ export default { if (!activeFile?.uri) return; activeFile.openWith?.(); }, + reload() { + const { activeFile } = editorManager; + if (!activeFile?.uri) return; + + activeFile.reload?.(); + }, async "open-file"() { editorManager.editor.contentDOM.blur(); const FileBrowser = await loadFileBrowser(); diff --git a/src/lib/editorFile.js b/src/lib/editorFile.js index 03a8c3ba0e..4ff090f3ef 100644 --- a/src/lib/editorFile.js +++ b/src/lib/editorFile.js @@ -1634,6 +1634,38 @@ export default class EditorFile { this.#fileAction("SEND"); } + async reload() { + if (!this.uri) return; + + if (this.refreshUnsavedState()) { + const confirmation = await confirm( + strings.warning.toUpperCase(), + strings["unsaved file"], + ); + + if (!confirmation) return; + } + + try { + const fs = fsOperation(this.uri); + + const stat = await fs.stat?.().catch(() => null); + const mtime = helpers.getStatMtime(stat); + + const value = await fs.readFile(this.encoding); + + this.session.setValue(value); + + this.markLoaded({ + mtime, + isUnsaved: false, + }); + } catch (error) { + console.error("Unable to reload file:", error); + toast(strings.error); + } + } + runAction() { this.#fileAction("RUN"); } diff --git a/src/views/file-menu.hbs b/src/views/file-menu.hbs index 95af69a239..a6a6e5ff46 100644 --- a/src/views/file-menu.hbs +++ b/src/views/file-menu.hbs @@ -53,6 +53,10 @@ {{/is_editor}}
{{#file_on_disk}} +
  • + {{reload}} + +
  • {{share}}