diff --git a/src/internal/config_type.go b/src/internal/config_type.go index 3cfcc65..1fc653d 100644 --- a/src/internal/config_type.go +++ b/src/internal/config_type.go @@ -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"` diff --git a/src/internal/handle_panel_movement.go b/src/internal/handle_panel_movement.go index 677d0d3..301950d 100644 --- a/src/internal/handle_panel_movement.go +++ b/src/internal/handle_panel_movement.go @@ -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 diff --git a/src/internal/key_function.go b/src/internal/key_function.go index 6fbf613..0d39b1a 100644 --- a/src/internal/key_function.go +++ b/src/internal/key_function.go @@ -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() diff --git a/src/superfile_config/hotkeys.toml b/src/superfile_config/hotkeys.toml index 8c2a78e..0ae79c3 100644 --- a/src/superfile_config/hotkeys.toml +++ b/src/superfile_config/hotkeys.toml @@ -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', ''] diff --git a/src/superfile_config/vimHotkeys.toml b/src/superfile_config/vimHotkeys.toml index ab9dd87..4486c5c 100644 --- a/src/superfile_config/vimHotkeys.toml +++ b/src/superfile_config/vimHotkeys.toml @@ -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', ''] @@ -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', ''] \ No newline at end of file +file_panel_select_all_items = ['A', '']