From b9bf3ec95d4a291496545d10b472c5f289d16baa Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 24 Feb 2025 11:20:51 +0000 Subject: [PATCH 1/3] :sparkles: Override focus so Viewer can pass on focus --- src/hike/widgets/viewer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/hike/widgets/viewer.py b/src/hike/widgets/viewer.py index 027ad52..4e76233 100644 --- a/src/hike/widgets/viewer.py +++ b/src/hike/widgets/viewer.py @@ -31,6 +31,10 @@ from textual.reactive import var from textual.widgets import Label, Markdown, Rule +############################################################################## +# Typing extensions imports. +from typing_extensions import Self + ############################################################################## # Local imports. from .. import USER_AGENT @@ -149,6 +153,18 @@ def compose(self) -> ComposeResult: ), ) + def focus(self, scroll_visible: bool = True) -> Self: + """Focus the viewer. + + Args: + scroll_visible: Should the widget me scrolled to be visible? + + Returns: + Self. + """ + self.query_one("#document").focus(scroll_visible) + return self + @property def source(self) -> str: """The source of the markdown being viewed.""" From 7bf2c7717ef2edbb03717d1a4c10770f13554cbe Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 24 Feb 2025 11:23:14 +0000 Subject: [PATCH 2/3] :sparkles: Add a command for jumping to the markdown document viewer --- ChangeLog.md | 7 +++++++ src/hike/commands/__init__.py | 2 ++ src/hike/commands/main.py | 7 +++++++ src/hike/providers/main.py | 6 ++++-- src/hike/screens/main.py | 7 +++++++ src/hike/widgets/command_line/general.py | 10 ++++++++++ src/hike/widgets/command_line/widget.py | 2 ++ 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 85bd8eb..cdfe41f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,13 @@ ## Unreleased +**Released: WiP** + +- Added an application command for jumping to the markdown document viewer. +- Added `document` as a command that the command line understands. + +## v0.4.0 + **Released: 2025-02-19** - Added `changelog` as a command that the command line understands. diff --git a/src/hike/commands/__init__.py b/src/hike/commands/__init__.py index 20ffa76..9fa2d13 100644 --- a/src/hike/commands/__init__.py +++ b/src/hike/commands/__init__.py @@ -10,6 +10,7 @@ CopyMarkdownToClipboard, Edit, JumpToCommandLine, + JumpToDocument, Reload, SaveCopy, SearchBookmarks, @@ -37,6 +38,7 @@ "Forward", "JumpToBookmarks", "JumpToCommandLine", + "JumpToDocument", "JumpToHistory", "JumpToLocalBrowser", "JumpToTableOfContents", diff --git a/src/hike/commands/main.py b/src/hike/commands/main.py index 3f37cde..9c531d8 100644 --- a/src/hike/commands/main.py +++ b/src/hike/commands/main.py @@ -28,6 +28,13 @@ class JumpToCommandLine(Command): BINDING_KEY = "/" +############################################################################## +class JumpToDocument(Command): + """Jump to the markdown document""" + + BINDING_KEY = "ctrl+slash" + + ############################################################################## class ChangeCommandLineLocation(Command): """Swap the position of the command line between top and bottom""" diff --git a/src/hike/providers/main.py b/src/hike/providers/main.py index b080eed..f510bbb 100644 --- a/src/hike/providers/main.py +++ b/src/hike/providers/main.py @@ -24,6 +24,7 @@ Forward, JumpToBookmarks, JumpToCommandLine, + JumpToDocument, JumpToHistory, JumpToLocalBrowser, JumpToTableOfContents, @@ -66,11 +67,12 @@ def commands(self) -> CommandHits: yield from self._maybe(Edit) yield from self._maybe(Forward) yield Help() - yield JumpToCommandLine() - yield JumpToTableOfContents() yield JumpToBookmarks() + yield JumpToCommandLine() + yield JumpToDocument() yield JumpToHistory() yield JumpToLocalBrowser() + yield JumpToTableOfContents() yield Quit() yield from self._maybe(Reload) yield from self._maybe(SaveCopy) diff --git a/src/hike/screens/main.py b/src/hike/screens/main.py index 01f1a76..eaef12b 100644 --- a/src/hike/screens/main.py +++ b/src/hike/screens/main.py @@ -43,6 +43,7 @@ Forward, JumpToBookmarks, JumpToCommandLine, + JumpToDocument, JumpToHistory, JumpToLocalBrowser, JumpToTableOfContents, @@ -146,6 +147,7 @@ class Main(EnhancedScreen[None]): Forward, JumpToBookmarks, JumpToCommandLine, + JumpToDocument, JumpToHistory, JumpToLocalBrowser, JumpToTableOfContents, @@ -411,6 +413,11 @@ def action_jump_to_command_line_command(self) -> None: if self.AUTO_FOCUS: self.query_one(self.AUTO_FOCUS).focus() + @on(JumpToDocument) + def action_jump_to_document_command(self) -> None: + """Jump to the document.""" + self.query_one(Viewer).focus() + @on(Backward) def action_backward_command(self) -> None: """Move backward through history.""" diff --git a/src/hike/widgets/command_line/general.py b/src/hike/widgets/command_line/general.py index dc71e45..c371c44 100644 --- a/src/hike/widgets/command_line/general.py +++ b/src/hike/widgets/command_line/general.py @@ -18,6 +18,7 @@ # Local imports. from ...commands import ( JumpToBookmarks, + JumpToDocument, JumpToHistory, JumpToLocalBrowser, JumpToTableOfContents, @@ -68,6 +69,15 @@ class ContentsCommand(GeneralCommand): MESSAGE = JumpToTableOfContents +############################################################################## +class DocumentCommand(GeneralCommand): + """Jump to the markdown document""" + + COMMAND = "`document`" + ALIASES = "`d`, `doc`" + MESSAGE = JumpToDocument + + ############################################################################## class HelpCommand(GeneralCommand): """Show the help screen""" diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index b1812a1..9575140 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -34,6 +34,7 @@ BookmarksCommand, ChangeLogCommand, ContentsCommand, + DocumentCommand, HelpCommand, HistoryCommand, LocalCommand, @@ -61,6 +62,7 @@ # Once the above are out of the way the order doesn't matter so much. BookmarksCommand, ChangeDirectoryCommand, + DocumentCommand, HelpCommand, HistoryCommand, LocalCommand, From eeb76c33c1ae1c9126e727121e4dea8412d26372 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 24 Feb 2025 13:20:45 +0000 Subject: [PATCH 3/3] :pencil: Fix a typo --- src/hike/widgets/viewer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hike/widgets/viewer.py b/src/hike/widgets/viewer.py index 4e76233..bba0be3 100644 --- a/src/hike/widgets/viewer.py +++ b/src/hike/widgets/viewer.py @@ -157,7 +157,7 @@ def focus(self, scroll_visible: bool = True) -> Self: """Focus the viewer. Args: - scroll_visible: Should the widget me scrolled to be visible? + scroll_visible: Should the widget be scrolled to be visible? Returns: Self.