Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 32 additions & 0 deletions src/lib/editorFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reload loses cursor position

Replacing the document here does not retain the cursor position, so someone reloading while working at a particular line can lose their place. The existing disk-change reload saves and restores the cursor; manual reload should do the same.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


this.markLoaded({
Comment on lines +1655 to +1659

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security New edits can be lost

If the user types while the file read is pending, the unsaved-change check has already passed. Reload then replaces those edits and marks the file clean without warning. Recheck the document before replacing it. How this was verified: Editor changes mark the file unsaved during the awaited read, but the subsequent replacement and markLoaded clear that state without another check.

mtime,
isUnsaved: false,
});
} catch (error) {
console.error("Unable to reload file:", error);
toast(strings.error);
}
}

runAction() {
this.#fileAction("RUN");
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/file-menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
{{/is_editor}}
<hr>
{{#file_on_disk}}
<li action="reload">
Comment on lines 55 to +56

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Media tabs cannot reload

This condition also shows Reload on image, audio, and video tabs because they have file URIs. Those tabs have no editor session to refresh, and the reload method does not rebuild their displayed media. Selecting Reload therefore does not update the file the user sees. Restrict the action to editor files or add a media reload path.

<span class="text">{{reload}}</span>
<span class="icon refresh"></span>
</li>
<li action="share">
<span class="text">{{share}}</span>
<span class="icon share"></span>
Expand Down
Loading