-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add reload action for open files #2948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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({ | ||
|
Comment on lines
+1655
to
+1659
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| mtime, | ||
| isUnsaved: false, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Unable to reload file:", error); | ||
| toast(strings.error); | ||
| } | ||
| } | ||
|
|
||
| runAction() { | ||
| this.#fileAction("RUN"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,10 @@ | |
| {{/is_editor}} | ||
| <hr> | ||
| {{#file_on_disk}} | ||
| <li action="reload"> | ||
|
Comment on lines
55
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!