Skip to content

Commit

Permalink
feat: vim-like arrow, scroll, and close filtering motions (wagoodman#501
Browse files Browse the repository at this point in the history
)

* 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]>
  • Loading branch information
3 people committed Nov 7, 2024
1 parent d9ad81b commit 6ca453c
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 42 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ Key Binding | Description
<kbd>Ctrl + C</kbd> or <kbd>Q</kbd> | Exit
<kbd>Tab</kbd> | Switch between the layer and filetree views
<kbd>Ctrl + F</kbd> | Filter files
<kbd>PageUp</kbd> | Scroll up a page
<kbd>PageDown</kbd> | Scroll down a page
<kbd>ESC</kbd> | Close filter files
<kbd>PageUp</kbd> or <kbd>U</kbd> | Scroll up a page
<kbd>PageDown</kbd> or <kbd>D</kbd> | Scroll down a page
<kbd>Up</kbd> or <kbd>K</kbd> | Move up one line within a page
<kbd>Down</kbd> or <kbd>J</kbd> | Move down one line within a page
<kbd>Ctrl + A</kbd> | Layer view: see aggregated image modifications
<kbd>Ctrl + L</kbd> | Layer view: see current layer modifications
<kbd>Space</kbd> | Filetree view: collapse/uncollapse a directory
Expand All @@ -263,8 +266,8 @@ Key Binding | Description
<kbd>Ctrl + M</kbd> | Filetree view: show/hide modified files
<kbd>Ctrl + U</kbd> | Filetree view: show/hide unmodified files
<kbd>Ctrl + B</kbd> | Filetree view: show/hide file attributes
<kbd>PageUp</kbd> | Filetree view: scroll up a page
<kbd>PageDown</kbd> | Filetree view: scroll down a page
<kbd>PageUp</kbd> or <kbd>U</kbd> | Filetree view: scroll up a page
<kbd>PageDown</kbd> or <kbd>D</kbd> | Filetree view: scroll down a page

## UI Configuration

Expand All @@ -286,6 +289,11 @@ keybinding:
quit: ctrl+c
toggle-view: tab
filter-files: ctrl+f, ctrl+slash
close-filter-files: esc
up: up,k
down: down,j
left: left,h
right: right,l

# Layer view specific bindings
compare-all: ctrl+a
Expand All @@ -299,8 +307,8 @@ keybinding:
toggle-modified-files: ctrl+m
toggle-unmodified-files: ctrl+u
toggle-filetree-attributes: ctrl+b
page-up: pgup
page-down: pgdn
page-up: pgup,u
page-down: pgdn,d

diff:
# You can change the default files shown in the filetree (right pane). All diff types are shown by default.
Expand Down
9 changes: 7 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func initConfig() {
viper.SetDefault("keybinding.quit", "ctrl+c,q")
viper.SetDefault("keybinding.toggle-view", "tab")
viper.SetDefault("keybinding.filter-files", "ctrl+f, ctrl+slash")
viper.SetDefault("keybinding.close-filter-files", "esc")
// keybindings: layer view
viper.SetDefault("keybinding.compare-all", "ctrl+a")
viper.SetDefault("keybinding.compare-layer", "ctrl+l")
Expand All @@ -94,8 +95,12 @@ func initConfig() {
viper.SetDefault("keybinding.toggle-unmodified-files", "ctrl+u")
viper.SetDefault("keybinding.toggle-wrap-tree", "ctrl+p")
viper.SetDefault("keybinding.extract-file", "ctrl+e")
viper.SetDefault("keybinding.page-up", "pgup")
viper.SetDefault("keybinding.page-down", "pgdn")
viper.SetDefault("keybinding.page-up", "pgup,u")
viper.SetDefault("keybinding.page-down", "pgdn,d")
viper.SetDefault("keybinding.up", "up,k")
viper.SetDefault("keybinding.down", "down,j")
viper.SetDefault("keybinding.left", "left,h")
viper.SetDefault("keybinding.right", "right,l")

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

Expand Down
12 changes: 8 additions & 4 deletions runtime/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,23 @@ func newApp(gui *gocui.Gui, imageName string, resolver image.Resolver, analysis
Display: "Switch view",
},
{
Key: gocui.KeyArrowRight,
OnAction: controller.NextPane,
ConfigKeys: []string{"keybinding.right"},
OnAction: controller.NextPane,
},
{
Key: gocui.KeyArrowLeft,
OnAction: controller.PrevPane,
ConfigKeys: []string{"keybinding.left"},
OnAction: controller.PrevPane,
},
{
ConfigKeys: []string{"keybinding.filter-files"},
OnAction: controller.ToggleFilterView,
IsSelected: controller.views.Filter.IsVisible,
Display: "Filter",
},
{
ConfigKeys: []string{"keybinding.close-filter-files"},
OnAction: controller.CloseFilterView,
},
}

globalHelpKeys, err = key.GenerateBindings(gui, "", infos)
Expand Down
9 changes: 9 additions & 0 deletions runtime/ui/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ func (c *Controller) ToggleView() (err error) {
return c.UpdateAndRender()
}

func (c *Controller) CloseFilterView() error {
// filter view needs to be visible
if c.views.Filter.IsVisible() {
// toggle filter view
return c.ToggleFilterView()
}
return nil
}

func (c *Controller) ToggleFilterView() error {
// delete all user input from the tree view
err := c.views.Filter.ToggleVisible()
Expand Down
24 changes: 12 additions & 12 deletions runtime/ui/view/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ func (v *FileTree) Setup(view, header *gocui.View) error {
OnAction: v.PageDown,
},
{
Key: gocui.KeyArrowDown,
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
ConfigKeys: []string{"keybinding.down"},
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
},
{
Key: gocui.KeyArrowUp,
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
ConfigKeys: []string{"keybinding.up"},
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
},
{
Key: gocui.KeyArrowLeft,
Modifier: gocui.ModNone,
OnAction: v.CursorLeft,
ConfigKeys: []string{"keybinding.left"},
Modifier: gocui.ModNone,
OnAction: v.CursorLeft,
},
{
Key: gocui.KeyArrowRight,
Modifier: gocui.ModNone,
OnAction: v.CursorRight,
ConfigKeys: []string{"keybinding.right"},
Modifier: gocui.ModNone,
OnAction: v.CursorRight,
},
}

Expand Down
12 changes: 6 additions & 6 deletions runtime/ui/view/image_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func (v *ImageDetails) Setup(body, header *gocui.View) error {

var infos = []key.BindingInfo{
{
Key: gocui.KeyArrowDown,
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
ConfigKeys: []string{"keybinding.down"},
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
},
{
Key: gocui.KeyArrowUp,
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
ConfigKeys: []string{"keybinding.up"},
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
},
{
ConfigKeys: []string{"keybinding.page-up"},
Expand Down
12 changes: 6 additions & 6 deletions runtime/ui/view/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ func (v *Layer) Setup(body *gocui.View, header *gocui.View) error {
Display: "Show aggregated changes",
},
{
Key: gocui.KeyArrowDown,
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
ConfigKeys: []string{"keybinding.down"},
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
},
{
Key: gocui.KeyArrowUp,
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
ConfigKeys: []string{"keybinding.up"},
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
},
{
ConfigKeys: []string{"keybinding.page-up"},
Expand Down
12 changes: 6 additions & 6 deletions runtime/ui/view/layer_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func (v *LayerDetails) Setup(body, header *gocui.View) error {

var infos = []key.BindingInfo{
{
Key: gocui.KeyArrowDown,
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
ConfigKeys: []string{"keybinding.down"},
Modifier: gocui.ModNone,
OnAction: v.CursorDown,
},
{
Key: gocui.KeyArrowUp,
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
ConfigKeys: []string{"keybinding.up"},
Modifier: gocui.ModNone,
OnAction: v.CursorUp,
},
}

Expand Down

0 comments on commit 6ca453c

Please sign in to comment.