v0.5.1 8e4df5c

screen_cursor.go RawHistoryFolder

1package vt
2
3import (
4	"strconv"
5	"strings"
6
7	renderer "github.com/bnema/vev-vt/core"
8)
9
10type cursorState struct {
11	row        int
12	col        int
13	style      renderer.Style
14	originMode bool
15	insertMode bool
16	saved      bool
17}
18
19func (s *Screen) cursorReportRow() int {
20	if s.originMode {
21		return clamp(s.Row, s.cursorMinRow(), s.cursorMaxRow()) - s.cursorMinRow() + 1
22	}
23	return s.Row + 1
24}
25
26func (s *Screen) cursorMinRow() int {
27	if s.originMode {
28		return clamp(s.scrollTop, 0, s.frame.Height-1)
29	}
30	return 0
31}
32
33func (s *Screen) cursorMaxRow() int {
34	if s.originMode {
35		return clamp(s.scrollBottom, 0, s.frame.Height-1)
36	}
37	return max(s.frame.Height-1, 0)
38}
39
40func (s *Screen) addressedRow(row int) int {
41	if s.originMode {
42		return clamp(s.scrollTop+row-1, s.cursorMinRow(), s.cursorMaxRow())
43	}
44	return clamp(row-1, 0, s.frame.Height-1)
45}
46
47func (s *Screen) addressCursor(row, col int) {
48	s.Row = s.addressedRow(row)
49	s.Col = clamp(col-1, 0, s.frame.Width-1)
50}
51
52func (s *Screen) homeCursor() {
53	s.addressCursor(1, 1)
54}
55
56func (s *Screen) applyCursorStyle(params string) {
57	if strings.HasPrefix(params, ">") || !strings.HasSuffix(params, " ") {
58		return
59	}
60	styleParam := strings.TrimSuffix(params, " ")
61	style := 0
62	if styleParam != "" {
63		v, err := strconv.Atoi(styleParam)
64		if err != nil {
65			return
66		}
67		style = v
68	}
69	if style < 0 || style > 6 {
70		return
71	}
72	s.cursorStyle = style
73	s.cursorStyleSet = true
74}
75
76func (s *Screen) saveCursor() {
77	s.savedCursor = cursorState{row: s.Row, col: s.Col, style: s.Style, originMode: s.originMode, insertMode: s.insertMode, saved: true}
78}
79
80func (s *Screen) restoreCursor() {
81	if !s.savedCursor.saved {
82		return
83	}
84	s.Row = clamp(s.savedCursor.row, 0, s.frame.Height-1)
85	s.Col = clamp(s.savedCursor.col, 0, s.frame.Width-1)
86	s.Style = s.savedCursor.style
87	s.originMode = s.savedCursor.originMode
88	s.insertMode = s.savedCursor.insertMode
89}

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 2

Tags 13

↑↓ moveenter openesc close