v0.1.0 7deb448

screen_resize.go RawHistoryFolder

1package vt
2
3import "github.com/bnema/vev/pkg/renderer"
4
5func (s *Screen) Resize(width, height int) {
6	if width == s.Frame.Width && height == s.Frame.Height {
7		return
8	}
9	if width <= 0 || height <= 0 {
10		// renderer.Frame permits a collapsed geometry. There is no layout to
11		// preserve until a usable viewport is supplied again.
12		width, height = max(width, 0), max(height, 0)
13		s.buffer = newBuffer(width, height)
14		s.Row, s.Col = 0, 0
15		if state := s.alternate; state != nil {
16			state.buffer = newBuffer(width, height)
17			state.frame = state.buffer.frame
18			state.row, state.col = 0, 0
19			state.scrollTop, state.scrollBottom = 0, height-1
20		}
21	} else {
22		resize := func(b *buffer, row, col int, saved *cursorState, evict bool) (int, int) {
23			active := &bufferCursor{row: row, col: col}
24			var savedPoint *bufferCursor
25			if saved != nil && saved.saved {
26				savedPoint = &bufferCursor{row: saved.row, col: saved.col}
27			}
28			evicted, evictedBounds := b.resize(width, height, active, savedPoint)
29			if evict {
30				for i, line := range evicted {
31					s.recordEvicted(line, evictedBounds[i])
32				}
33			}
34			if savedPoint != nil {
35				saved.row, saved.col = savedPoint.row, clamp(savedPoint.col, 0, width-1)
36			}
37			return active.row, clamp(active.col, 0, width-1)
38		}
39
40		if s.alternate != nil {
41			// Both screen states are reflowed independently, but active and saved
42			// cursors for each state are mapped by their single buffer layout pass.
43			s.Row, s.Col = resize(s.buffer, s.Row, s.Col, &s.savedCursor, false)
44			state := s.alternate
45			if state.buffer == nil {
46				state.buffer = bufferFromFrame(state.frame)
47			}
48			state.row, state.col = resize(state.buffer, state.row, state.col, &state.savedCursor, true)
49			state.frame = state.buffer.frame
50			state.scrollTop, state.scrollBottom = 0, height-1
51		} else {
52			s.Row, s.Col = resize(s.buffer, s.Row, s.Col, &s.savedCursor, true)
53		}
54	}
55	s.Frame = s.buffer.frame
56	// A resize can split an in-flight escape sequence from the terminal state it
57	// was meant to mutate; keep the durable child state but discard partial bytes.
58	s.escapeBuf = s.escapeBuf[:0]
59	s.resetScrollRegion()
60	s.fullRedraw()
61}
62
63// cloneFrame produces an independent copy in canonical layout: it copies the
64// source's logical rows (via Row) into a fresh frame whose offsets are already
65// canonical, so a rotated source is normalized in the clone.
66func cloneFrame(frame renderer.Frame) renderer.Frame {
67	out := renderer.NewFrame(frame.Width, frame.Height)
68	for y := range frame.Height {
69		copy(out.Row(y), frame.Row(y))
70	}
71	return out
72}
73
74func clamp(v, lo, hi int) int {
75	if hi < lo {
76		return lo
77	}
78	if v < lo {
79		return lo
80	}
81	if v > hi {
82		return hi
83	}
84	return v
85}

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 12

Tags 11

↑↓ moveenter openesc close