diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-10-26 20:38:32 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-10-26 20:38:32 +0800 |
| commit | 2971d699423e2f28f2686b098cb5dbf9a705038e (patch) | |
| tree | 43abe71fbedd4a90527c26c68fcba73ab71f6519 /src/tui/document_view.cc | |
| parent | cb1f404cc6b8b9dce135efd26fa32dc0d6fd79c4 (diff) | |
| download | rwebbrowser-2971d699423e2f28f2686b098cb5dbf9a705038e.tar.gz rwebbrowser-2971d699423e2f28f2686b098cb5dbf9a705038e.tar.xz | |
feat(tui): add object focus traversal and link activation
Diffstat (limited to 'src/tui/document_view.cc')
| -rw-r--r-- | src/tui/document_view.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tui/document_view.cc b/src/tui/document_view.cc index ee74e53..13a5d5f 100644 --- a/src/tui/document_view.cc +++ b/src/tui/document_view.cc @@ -361,6 +361,28 @@ bool DocumentView::locate( const DocumentPoint& point ) std::optional<HitTarget> DocumentView::focused_target() const { return layout_.target( snapshot_.cursor ); } +FocusResult DocumentView::focus( bool backward ) +{ + const auto next = layout_.focus( snapshot_.cursor, backward ); + if ( !next ) { + return FocusResult::Empty; + } + stop_drag(); + snapshot_.cursor = next->position; + finish_move( false ); + return next->wrapped ? FocusResult::Wrapped : FocusResult::Moved; +} + +const Link* DocumentView::focused_link() const +{ + const auto target = focused_target(); + if ( !target || !std::holds_alternative<LinkId>( *target ) ) { + return nullptr; + } + // Layout link targets originate from this same immutable document. + return &*std::ranges::find( document_.data().links, std::get<LinkId>( *target ), &Link::id ); +} + void DocumentView::draw( Frame& frame, CellPoint origin ) const { const auto selection = snapshot_.selection ? std::optional( snapshot_.selection->range ) : std::nullopt; |
