Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 0894ef3

Browse files
joschigwendolyngoetzmehmetumit
committed
feat: vim-like arrow, scroll, and close filtering motions (wagoodman#501)
* Adding configurable keybindings for up/down arrows (`k` and `j` vim motions can be used as alternative to up/down arrows). Thanks to @gwendolyngoetz for implementing this feature [Adding configurable keybindings for up/down arrows wagoodman#499](wagoodman#499) * Add configurable keybindings for left/right arrows (`h` and `l` vim motions can be used as alternative to left/right arrows) * Add `u` and `d` keys for page up/down alternatives (I didn't want to replace default `ctrl+u` toggle-unmodified-files keybinding so I used`u` and `d` like `Vimium` extension ) * Add `esc` key to close filtering (Implemented a new method by utilizing the existing toggle filter method, without touching its current behavior) Refs wagoodman#129 Refs wagoodman#415 Refs wagoodman#499 Co-authored-by: Gwendolyn Goetz <[email protected]> Co-authored-by: Mehmet Ümit Özden <[email protected]>
1 parent 10fa1dd commit 0894ef3

File tree

8 files changed

+68
-42
lines changed

8 files changed

+68
-42
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ Key Binding | Description
252252
<kbd>Ctrl + C</kbd> or <kbd>Q</kbd> | Exit
253253
<kbd>Tab</kbd> | Switch between the layer and filetree views
254254
<kbd>Ctrl + F</kbd> | Filter files
255-
<kbd>PageUp</kbd> | Scroll up a page
256-
<kbd>PageDown</kbd> | Scroll down a page
255+
<kbd>ESC</kbd> | Close filter files
256+
<kbd>PageUp</kbd> or <kbd>U</kbd> | Scroll up a page
257+
<kbd>PageDown</kbd> or <kbd>D</kbd> | Scroll down a page
258+
<kbd>Up</kbd> or <kbd>K</kbd> | Move up one line within a page
259+
<kbd>Down</kbd> or <kbd>J</kbd> | Move down one line within a page
257260
<kbd>Ctrl + A</kbd> | Layer view: see aggregated image modifications
258261
<kbd>Ctrl + L</kbd> | Layer view: see current layer modifications
259262
<kbd>Space</kbd> | Filetree view: collapse/uncollapse a directory
@@ -263,8 +266,8 @@ Key Binding | Description
263266
<kbd>Ctrl + M</kbd> | Filetree view: show/hide modified files
264267
<kbd>Ctrl + U</kbd> | Filetree view: show/hide unmodified files
265268
<kbd>Ctrl + B</kbd> | Filetree view: show/hide file attributes
266-
<kbd>PageUp</kbd> | Filetree view: scroll up a page
267-
<kbd>PageDown</kbd> | Filetree view: scroll down a page
269+
<kbd>PageUp</kbd> or <kbd>U</kbd> | Filetree view: scroll up a page
270+
<kbd>PageDown</kbd> or <kbd>D</kbd> | Filetree view: scroll down a page
268271

269272
## UI Configuration
270273

@@ -286,6 +289,11 @@ keybinding:
286289
quit: ctrl+c
287290
toggle-view: tab
288291
filter-files: ctrl+f, ctrl+slash
292+
close-filter-files: esc
293+
up: up,k
294+
down: down,j
295+
left: left,h
296+
right: right,l
289297

290298
# Layer view specific bindings
291299
compare-all: ctrl+a
@@ -299,8 +307,8 @@ keybinding:
299307
toggle-modified-files: ctrl+m
300308
toggle-unmodified-files: ctrl+u
301309
toggle-filetree-attributes: ctrl+b
302-
page-up: pgup
303-
page-down: pgdn
310+
page-up: pgup,u
311+
page-down: pgdn,d
304312

305313
diff:
306314
# You can change the default files shown in the filetree (right pane). All diff types are shown by default.

cmd/root.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func initConfig() {
8080
viper.SetDefault("keybinding.quit", "ctrl+c,q")
8181
viper.SetDefault("keybinding.toggle-view", "tab")
8282
viper.SetDefault("keybinding.filter-files", "ctrl+f, ctrl+slash")
83+
viper.SetDefault("keybinding.close-filter-files", "esc")
8384
// keybindings: layer view
8485
viper.SetDefault("keybinding.compare-all", "ctrl+a")
8586
viper.SetDefault("keybinding.compare-layer", "ctrl+l")
@@ -94,8 +95,12 @@ func initConfig() {
9495
viper.SetDefault("keybinding.toggle-unmodified-files", "ctrl+u")
9596
viper.SetDefault("keybinding.toggle-wrap-tree", "ctrl+p")
9697
viper.SetDefault("keybinding.extract-file", "ctrl+e")
97-
viper.SetDefault("keybinding.page-up", "pgup")
98-
viper.SetDefault("keybinding.page-down", "pgdn")
98+
viper.SetDefault("keybinding.page-up", "pgup,u")
99+
viper.SetDefault("keybinding.page-down", "pgdn,d")
100+
viper.SetDefault("keybinding.up", "up,k")
101+
viper.SetDefault("keybinding.down", "down,j")
102+
viper.SetDefault("keybinding.left", "left,h")
103+
viper.SetDefault("keybinding.right", "right,l")
99104

100105
viper.SetDefault("diff.hide", "")
101106

runtime/ui/app.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,23 @@ func newApp(gui *gocui.Gui, imageName string, resolver image.Resolver, analysis
7777
Display: "Switch view",
7878
},
7979
{
80-
Key: gocui.KeyArrowRight,
81-
OnAction: controller.NextPane,
80+
ConfigKeys: []string{"keybinding.right"},
81+
OnAction: controller.NextPane,
8282
},
8383
{
84-
Key: gocui.KeyArrowLeft,
85-
OnAction: controller.PrevPane,
84+
ConfigKeys: []string{"keybinding.left"},
85+
OnAction: controller.PrevPane,
8686
},
8787
{
8888
ConfigKeys: []string{"keybinding.filter-files"},
8989
OnAction: controller.ToggleFilterView,
9090
IsSelected: controller.views.Filter.IsVisible,
9191
Display: "Filter",
9292
},
93+
{
94+
ConfigKeys: []string{"keybinding.close-filter-files"},
95+
OnAction: controller.CloseFilterView,
96+
},
9397
}
9498

9599
globalHelpKeys, err = key.GenerateBindings(gui, "", infos)

runtime/ui/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ func (c *Controller) ToggleView() (err error) {
223223
return c.UpdateAndRender()
224224
}
225225

226+
func (c *Controller) CloseFilterView() error {
227+
// filter view needs to be visible
228+
if c.views.Filter.IsVisible() {
229+
// toggle filter view
230+
return c.ToggleFilterView()
231+
}
232+
return nil
233+
}
234+
226235
func (c *Controller) ToggleFilterView() error {
227236
// delete all user input from the tree view
228237
err := c.views.Filter.ToggleVisible()

runtime/ui/view/filetree.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,24 @@ func (v *FileTree) Setup(view, header *gocui.View) error {
160160
OnAction: v.PageDown,
161161
},
162162
{
163-
Key: gocui.KeyArrowDown,
164-
Modifier: gocui.ModNone,
165-
OnAction: v.CursorDown,
163+
ConfigKeys: []string{"keybinding.down"},
164+
Modifier: gocui.ModNone,
165+
OnAction: v.CursorDown,
166166
},
167167
{
168-
Key: gocui.KeyArrowUp,
169-
Modifier: gocui.ModNone,
170-
OnAction: v.CursorUp,
168+
ConfigKeys: []string{"keybinding.up"},
169+
Modifier: gocui.ModNone,
170+
OnAction: v.CursorUp,
171171
},
172172
{
173-
Key: gocui.KeyArrowLeft,
174-
Modifier: gocui.ModNone,
175-
OnAction: v.CursorLeft,
173+
ConfigKeys: []string{"keybinding.left"},
174+
Modifier: gocui.ModNone,
175+
OnAction: v.CursorLeft,
176176
},
177177
{
178-
Key: gocui.KeyArrowRight,
179-
Modifier: gocui.ModNone,
180-
OnAction: v.CursorRight,
178+
ConfigKeys: []string{"keybinding.right"},
179+
Modifier: gocui.ModNone,
180+
OnAction: v.CursorRight,
181181
},
182182
}
183183

runtime/ui/view/image_details.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ func (v *ImageDetails) Setup(body, header *gocui.View) error {
4444

4545
var infos = []key.BindingInfo{
4646
{
47-
Key: gocui.KeyArrowDown,
48-
Modifier: gocui.ModNone,
49-
OnAction: v.CursorDown,
47+
ConfigKeys: []string{"keybinding.down"},
48+
Modifier: gocui.ModNone,
49+
OnAction: v.CursorDown,
5050
},
5151
{
52-
Key: gocui.KeyArrowUp,
53-
Modifier: gocui.ModNone,
54-
OnAction: v.CursorUp,
52+
ConfigKeys: []string{"keybinding.up"},
53+
Modifier: gocui.ModNone,
54+
OnAction: v.CursorUp,
5555
},
5656
{
5757
ConfigKeys: []string{"keybinding.page-up"},

runtime/ui/view/layer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ func (v *Layer) Setup(body *gocui.View, header *gocui.View) error {
116116
Display: "Show aggregated changes",
117117
},
118118
{
119-
Key: gocui.KeyArrowDown,
120-
Modifier: gocui.ModNone,
121-
OnAction: v.CursorDown,
119+
ConfigKeys: []string{"keybinding.down"},
120+
Modifier: gocui.ModNone,
121+
OnAction: v.CursorDown,
122122
},
123123
{
124-
Key: gocui.KeyArrowUp,
125-
Modifier: gocui.ModNone,
126-
OnAction: v.CursorUp,
124+
ConfigKeys: []string{"keybinding.up"},
125+
Modifier: gocui.ModNone,
126+
OnAction: v.CursorUp,
127127
},
128128
{
129129
ConfigKeys: []string{"keybinding.page-up"},

runtime/ui/view/layer_details.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ func (v *LayerDetails) Setup(body, header *gocui.View) error {
4040

4141
var infos = []key.BindingInfo{
4242
{
43-
Key: gocui.KeyArrowDown,
44-
Modifier: gocui.ModNone,
45-
OnAction: v.CursorDown,
43+
ConfigKeys: []string{"keybinding.down"},
44+
Modifier: gocui.ModNone,
45+
OnAction: v.CursorDown,
4646
},
4747
{
48-
Key: gocui.KeyArrowUp,
49-
Modifier: gocui.ModNone,
50-
OnAction: v.CursorUp,
48+
ConfigKeys: []string{"keybinding.up"},
49+
Modifier: gocui.ModNone,
50+
OnAction: v.CursorUp,
5151
},
5252
}
5353

0 commit comments

Comments
 (0)