Skip to content

Commit

Permalink
Merge pull request #498 from wassup05/page-up-down
Browse files Browse the repository at this point in the history
feat: add keys PageUp and PageDown for better navigation
  • Loading branch information
yorukot authored Nov 30, 2024
2 parents 8d9bfcc + a14d091 commit 870367d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/internal/config_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ type HotkeysType struct {
// movement
ListUp []string `toml:"list_up" comment:"movement"`
ListDown []string `toml:"list_down"`
PageUp []string `toml:"page_up"`
PageDown []string `toml:"page_down"`

CloseFilePanel []string `toml:"close_file_panel" comment:"file panel control"`
CreateNewFilePanel []string `toml:"create_new_file_panel"`
Expand Down
54 changes: 54 additions & 0 deletions src/internal/handle_panel_movement.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,60 @@ func (m *model) controlFilePanelListDown(wheel bool) {

}

func (m *model) controlFilePanelPgUp(){
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
panlen := len(panel.element)
panHeight := panelElementHeight(m.mainPanelHeight)
panCenter := panHeight / 2 // For making sure the cursor is at the center of the panel

if panlen == 0 {
return
}

if panHeight >= panlen {
panel.cursor = 0
} else {
if panel.cursor - panHeight <= 0 {
panel.cursor = 0
panel.render = 0
} else {
panel.cursor -= panHeight
panel.render = panel.cursor - panCenter

if panel.render < 0 {
panel.render = 0
}
}
}

m.fileModel.filePanels[m.filePanelFocusIndex] = panel
}

func (m *model) controlFilePanelPgDown(){
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
panlen := len(panel.element)
panHeight := panelElementHeight(m.mainPanelHeight)
panCenter := panHeight / 2 // For making sure the cursor is at the center of the panel

if panlen == 0 {
return
}

if panHeight >= panlen {
panel.cursor = panlen - 1
} else {
if panel.cursor + panHeight >= panlen {
panel.cursor = panlen - 1
panel.render = panel.cursor - panCenter
} else {
panel.cursor += panHeight
panel.render = panel.cursor - panCenter
}
}

m.fileModel.filePanels[m.filePanelFocusIndex] = panel
}

// Handles the action of selecting an item in the file panel upwards. (only work on select mode)
func (m *model) itemSelectUp(wheel bool) {
runTime := 1
Expand Down
6 changes: 6 additions & 0 deletions src/internal/key_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func (m *model) mainKey(msg string, cmd tea.Cmd) ( tea.Cmd) {
}()
}

case containsKey(msg, hotkeys.PageUp):
m.controlFilePanelPgUp()

case containsKey(msg, hotkeys.PageDown):
m.controlFilePanelPgDown()

case containsKey(msg, hotkeys.ChangePanelMode):
m.changeFilePanelMode()

Expand Down
2 changes: 2 additions & 0 deletions src/superfile_config/hotkeys.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ quit = ['q', 'esc']
# movement
list_up = ['up', 'k']
list_down = ['down', 'j']
page_up = ['pgup','']
page_down = ['pgdown','']
# file panel control
create_new_file_panel = ['n', '']
close_file_panel = ['w', '']
Expand Down
4 changes: 3 additions & 1 deletion src/superfile_config/vimHotkeys.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ quit = ['ctrl+c', ''] # also know as, theprimeagen troller
# movement
list_up = ['k', '']
list_down = ['j', '']
page_up = ['pgup','']
page_down = ['pgdown','']
# file panel control
create_new_file_panel = ['n', '']
close_file_panel = ['q', '']
Expand Down Expand Up @@ -53,4 +55,4 @@ search_bar = ['/', '']
# Select mode hotkeys (can conflict with other modes, cannot conflict with global hotkeys)
file_panel_select_mode_items_select_down = ['J', '']
file_panel_select_mode_items_select_up = ['K', '']
file_panel_select_all_items = ['A', '']
file_panel_select_all_items = ['A', '']

0 comments on commit 870367d

Please sign in to comment.