diff --git a/src/lib/commands.js b/src/lib/commands.js index de3a005a8..ea18e5721 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 03a8c3ba0..4ff090f3e 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 95af69a23..a6a6e5ff4 100644 --- a/src/views/file-menu.hbs +++ b/src/views/file-menu.hbs @@ -53,6 +53,10 @@ {{/is_editor}}
{{#file_on_disk}} +
  • + {{reload}} + +
  • {{share}}