v0.2.0 13c6a90

constraint_frame_test.go RawHistoryFolder

1package core
2
3import (
4	"context"
5	"testing"
6
7	"github.com/bnema/neferwl/internal/ports"
8)
9
10// partlyShown has window 2 straddling the left edge of a 100x100 viewport:
11// its client is x 75..125 of the monitor (1075..1125 globally) and only
12// 100..125 shows.
13func partlyShown(t *testing.T) *Core {
14	t.Helper()
15	var cfg ports.Config
16	cfg.Keyboard.CmdKey = "super"
17	cfg.Layout.MaxColumns = 2
18	c, err := New(cfg, Channels{
19		Scenes: make(chan []ports.Scene, 1), Layouts: make(chan ports.Layout, 1), Constraints: make(chan ports.PointerConstraint, 1),
20		State: make(chan ports.State, 1), Workspaces: make(chan ports.Workspaces, 1), Commands: make(chan ports.ClientCommand, 16),
21	})
22	if err != nil {
23		t.Fatal(err)
24	}
25	c.addScreen(ports.OutputInfo{Name: "A", Width: 300, Height: 200})
26	s := c.screens[0]
27	s.x = 1000
28	s.mon.SetNamed([]NamedWorkspace{{Name: "s", Size: [2]int{100, 100}}})
29	s.mon.ToggleNamed("s")
30	for id := WindowID(1); id <= 3; id++ {
31		s.mon.AddWindow(id)
32	}
33	s.mon.Current().ViewX += 25
34	return c
35}
36
37// A constraint region is window-local: it starts at the whole client's
38// origin, not at the visible part's, and is then cut to the viewport.
39func TestConstraintRegionUsesFullClientOrigin(t *testing.T) {
40	c := partlyShown(t)
41	full, vis, ok := c.shownClient(2)
42	if !ok || full != (Rect{X: 1075, Y: 50, W: 50, H: 100}) || vis != (Rect{X: 1100, Y: 50, W: 25, H: 100}) {
43		t.Fatalf("full %+v visible %+v %v", full, vis, ok)
44	}
45	c.constrained = ports.PointerConstrained{ID: 2, PointerConstraint: ports.PointerConstraint{Mode: ports.ConstraintConfine, Rect: Rect{X: 30, Y: 10, W: 20, H: 20}}}
46	c.resolveConstraint()
47	// Local x 30..50 is global 1105..1125, all inside the visible part.
48	if want := (Rect{X: 1105, Y: 60, W: 20, H: 20}); c.constraint.Rect != want {
49		t.Fatalf("region %+v want %+v", c.constraint.Rect, want)
50	}
51	// A region straddling the viewport edge is cut to it: local 10..40 is 1085..1115.
52	c.constrained.PointerConstraint.Rect = Rect{X: 10, Y: 0, W: 30, H: 100}
53	c.resolveConstraint()
54	if want := (Rect{X: 1100, Y: 50, W: 15, H: 100}); c.constraint.Rect != want {
55		t.Fatalf("straddling region %+v want %+v", c.constraint.Rect, want)
56	}
57}
58
59// A warp target is computed from the whole client origin and refused when it
60// falls outside the viewport.
61func TestWarpUsesFullClientOriginAndFrame(t *testing.T) {
62	c := partlyShown(t)
63	c.pointer = 2
64	ctx := context.Background()
65	// Local 10 is global 1085: the hidden part of the window.
66	if err := c.warpPointer(ctx, ports.PointerWarp{ID: 2, X: 10, Y: 5}); err != nil {
67		t.Fatal(err)
68	}
69	if c.cursorX != 0 || c.cursorY != 0 {
70		t.Fatalf("warped into the hidden part: %v,%v", c.cursorX, c.cursorY)
71	}
72	// Local 30 is global 1105: shown.
73	if err := c.warpPointer(ctx, ports.PointerWarp{ID: 2, X: 30, Y: 5}); err != nil {
74		t.Fatal(err)
75	}
76	if c.cursorX != 1105 || c.cursorY != 55 {
77		t.Fatalf("cursor %v,%v want 1105,55", c.cursorX, c.cursorY)
78	}
79}

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 25

Tags 10

↑↓ moveenter openesc close