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 | 032b82c13e157a048ac13a540dfd18be9667fe49 (patch) | |
| tree | d8bec1f88fcd529a300bb71316c18ecaf0806b63 /ricochet/src/tui/document_view.cc | |
| parent | 2e6dc81391c5dbb787cfd793ad5823904b3b9c94 (diff) | |
| download | rcc-project-032b82c13e157a048ac13a540dfd18be9667fe49.tar.gz rcc-project-032b82c13e157a048ac13a540dfd18be9667fe49.tar.xz | |
feat(tui): add object focus traversal and link activation
Diffstat (limited to 'ricochet/src/tui/document_view.cc')
| -rw-r--r-- | ricochet/src/tui/document_view.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ricochet/src/tui/document_view.cc b/ricochet/src/tui/document_view.cc index ee74e53..13a5d5f 100644 --- a/ricochet/src/tui/document_view.cc +++ b/ricochet/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; |
