From 9d55b158ebfeea6cd8c5d5837e1461ebdd21080f Mon Sep 17 00:00:00 2001 From: "supritsj@Arch" Date: Sat, 30 Nov 2024 10:54:51 +0530 Subject: [PATCH 1/2] implemented keys: PageUp and PageDown --- src/internal/handle_panel_movement.go | 54 +++++++++++++++++++++++++++ src/internal/key_function.go | 6 +++ 2 files changed, 60 insertions(+) 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..a2571d3 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 tea.KeyPgUp.String(): + m.controlFilePanelPgUp() + + case tea.KeyPgDown.String(): + m.controlFilePanelPgDown() + case containsKey(msg, hotkeys.ChangePanelMode): m.changeFilePanelMode() From a14d091200832ba31278b7336752da052bad5c52 Mon Sep 17 00:00:00 2001 From: "supritsj@Arch" Date: Sat, 30 Nov 2024 17:58:13 +0530 Subject: [PATCH 2/2] add hotkeys to respective conf files --- src/internal/config_type.go | 2 ++ src/internal/key_function.go | 4 ++-- src/superfile_config/hotkeys.toml | 2 ++ src/superfile_config/vimHotkeys.toml | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) 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/key_function.go b/src/internal/key_function.go index a2571d3..0d39b1a 100644 --- a/src/internal/key_function.go +++ b/src/internal/key_function.go @@ -49,10 +49,10 @@ func (m *model) mainKey(msg string, cmd tea.Cmd) ( tea.Cmd) { }() } - case tea.KeyPgUp.String(): + case containsKey(msg, hotkeys.PageUp): m.controlFilePanelPgUp() - case tea.KeyPgDown.String(): + case containsKey(msg, hotkeys.PageDown): m.controlFilePanelPgDown() case containsKey(msg, hotkeys.ChangePanelMode): 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', '']