Skip to content

Commit

Permalink
Add a reload command
Browse files Browse the repository at this point in the history
Consider this a "hits most use cases" initial take on #44; I think this is
needed anyway. Reloading based on external input should follow later, but I
think those things make more sense when I can make a best-efforts attempt at
reloading and ending up at the same position (which would help make things
feel more like a live-edit viewer).

Anyway, that's a different request/PR. This is about a simple refresh.
  • Loading branch information
davep committed May 28, 2023
1 parent f16b6d8 commit 40b29b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [0.7.0] - Unreleased

### Added

- Added support for using <kbd>Ctrl</kbd>+<kbd>r</kbd> to reload the current
document.

### Fixed

- Added some extra error capture when attempting to build a forge URL while
Expand Down
1 change: 1 addition & 0 deletions frogmouth/dialogs/help_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
| Key | Command |
| -- | -- |
| `Ctrl+d` | Add the current document to the bookmarks |
| `Ctrl+r` | Reload the current document |
| `Ctrl+q` | Quit the application |
| `F1` | This help |
| `F2` | Details about {APPLICATION_TITLE} |
Expand Down
5 changes: 5 additions & 0 deletions frogmouth/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Main(Screen[None]): # pylint:disable=too-many-public-methods
Binding("ctrl+l", "local_files", "", show=False),
Binding("ctrl+left", "backward", "", show=False),
Binding("ctrl+right", "forward", "", show=False),
Binding("ctrl+r", "reload", "", show=False),
Binding("ctrl+t", "table_of_contents", "", show=False),
Binding("ctrl+y", "history", "", show=False),
Binding("escape", "escape", "", show=False),
Expand Down Expand Up @@ -541,3 +542,7 @@ def action_toggle_theme(self) -> None:
save_config(config)
# pylint:disable=attribute-defined-outside-init
self.app.dark = not config.light_mode

def action_reload(self) -> None:
"""Reload the current document."""
self.query_one(Viewer).reload()
5 changes: 5 additions & 0 deletions frogmouth/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def visit(self, location: Path | URL, remember: bool = True) -> None:
else:
raise ValueError("Unknown location type passed to the Markdown viewer")

def reload(self) -> None:
"""Reload the current location."""
if self.location is not None:
self.visit(self.location, False)

def show(self, content: str) -> None:
"""Show some direct text in the viewer.
Expand Down

0 comments on commit 40b29b8

Please sign in to comment.