vim_navigation.go RawHistoryFolder

1package usecase
2
3import (
4	"context"
5	"errors"
6
7	"github.com/bnema/dumber/internal/application/dto"
8	"github.com/bnema/dumber/internal/application/port"
9)
10
11var (
12	errUnsupportedVimNavigationAction = errors.New("vim navigation: unsupported action")
13	errUnsupportedVimNavigationEngine = errors.New("vim navigation: unsupported webview capability")
14)
15
16// VimNavigationUseCase maps configured Vim Mode navigation actions to optional
17// WebView capabilities. The UI layer supplies the active WebView and remains
18// responsible only for event and theme context.
19type VimNavigationUseCase struct{}
20
21// NewVimNavigationUseCase creates a stateless Vim navigation use case.
22func NewVimNavigationUseCase() *VimNavigationUseCase {
23	return &VimNavigationUseCase{}
24}
25
26// Execute dispatches a configured semantic Vim action to the active WebView.
27func (*VimNavigationUseCase) Execute(ctx context.Context, wv port.WebView, action string, count int, highlightColor string) error {
28	if wv == nil {
29		return errors.New("vim navigation: nil webview")
30	}
31
32	switch action {
33	case "confirm":
34		activator, ok := wv.(port.SemanticNavigationActivator)
35		if !ok {
36			return errUnsupportedVimNavigationEngine
37		}
38		return activator.ActivateSemanticNavigationTarget(ctx)
39	case "focus-input":
40		focuser, ok := wv.(port.PageInputFocuser)
41		if !ok {
42			return errUnsupportedVimNavigationEngine
43		}
44		focuser.FocusNextInput()
45		return nil
46	}
47
48	var request dto.SemanticNavigationRequest
49	switch action {
50	case "heading-next":
51		request = dto.SemanticNavigationRequest{
52			Target:         dto.SemanticNavigationTargetHeading,
53			Direction:      dto.SemanticNavigationForward,
54			Count:          count,
55			HighlightColor: highlightColor,
56		}
57	case "heading-prev":
58		request = dto.SemanticNavigationRequest{
59			Target:         dto.SemanticNavigationTargetHeading,
60			Direction:      dto.SemanticNavigationBackward,
61			Count:          count,
62			HighlightColor: highlightColor,
63		}
64	default:
65		return errUnsupportedVimNavigationAction
66	}
67
68	navigator, ok := wv.(port.SemanticNavigable)
69	if !ok {
70		return errUnsupportedVimNavigationEngine
71	}
72	return navigator.NavigateSemantic(ctx, request)
73}
74
75// ClearSemanticNavigationHighlight removes the visual target left by semantic
76// navigation when the active Vim Mode session ends.
77func (*VimNavigationUseCase) ClearSemanticNavigationHighlight(ctx context.Context, wv port.WebView) error {
78	if wv == nil {
79		return nil
80	}
81	clearer, ok := wv.(port.SemanticNavigationHighlightClearer)
82	if !ok {
83		return nil
84	}
85	return clearer.ClearSemanticNavigationHighlight(ctx)
86}
87
88// NavigatePageFocus keeps focus traversal inside a page when the active page
89// control would otherwise hand the host window a Tab event.
90func (*VimNavigationUseCase) NavigatePageFocus(wv port.WebView, backward bool) bool {
91	if wv == nil {
92		return false
93	}
94	navigator, ok := wv.(port.PageFocusNavigator)
95	if !ok {
96		return false
97	}
98	navigator.NavigatePageFocus(backward)
99	return true
100}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close