-
-
Notifications
You must be signed in to change notification settings - Fork 452
feat: modal to select a pinned directory #1345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robert-zaremba
wants to merge
6
commits into
yorukot:main
Choose a base branch
from
robert-zaremba:goto_pinned
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e58223
feat: pinned dirs select modal
robert-zaremba f8c0059
make the pinned dirs modal wider
robert-zaremba 1585665
Apply suggestions from code review
robert-zaremba e0877b1
review fixes
robert-zaremba 352c919
unify the ui with the goto interactive
robert-zaremba dce44ff
Fixed issue when the sidebar panel is nil
robert-zaremba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package pinnedmodal | ||
|
|
||
| const ( | ||
| pinnedModalHeadlineText = "Goto Pinned Directory" | ||
|
|
||
| PinnedModalMinWidth = 20 | ||
| PinnedModalMinHeight = 3 | ||
|
|
||
| maxVisibleResults = 5 | ||
|
|
||
| columnWidth = 15 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| package pinnedmodal | ||
|
|
||
| import ( | ||
| "slices" | ||
|
|
||
| tea "github.com/charmbracelet/bubbletea" | ||
|
|
||
| "github.com/yorukot/superfile/src/internal/common" | ||
| "github.com/yorukot/superfile/src/internal/utils" | ||
| ) | ||
|
|
||
| func DefaultModel(maxHeight int, width int) Model { | ||
| return GenerateModel(maxHeight, width) | ||
| } | ||
|
|
||
| func GenerateModel(maxHeight int, width int) Model { | ||
| m := Model{ | ||
| headline: pinnedModalHeadlineText, | ||
| open: false, | ||
| textInput: common.GeneratePromptTextInput(), | ||
| results: []Directory{}, | ||
| } | ||
| m.SetMaxHeight(maxHeight) | ||
| m.SetWidth(width) | ||
| m.textInput.Prompt = "" | ||
| return m | ||
| } | ||
|
|
||
| func (m *Model) HandleUpdate(msg tea.Msg) (common.ModelAction, tea.Cmd) { | ||
| var action common.ModelAction | ||
| action = common.NoAction{} | ||
| var cmd tea.Cmd | ||
| if !m.IsOpen() { | ||
| return action, cmd | ||
| } | ||
|
|
||
| switch msg := msg.(type) { | ||
| case tea.KeyMsg: | ||
| switch { | ||
| case slices.Contains(common.Hotkeys.ConfirmTyping, msg.String()): | ||
| action = m.handleConfirm() | ||
| m.Close() | ||
| case slices.Contains(common.Hotkeys.CancelTyping, msg.String()), | ||
| slices.Contains(common.Hotkeys.Quit, msg.String()): | ||
| m.Close() | ||
| case slices.Contains(common.Hotkeys.ListUp, msg.String()): | ||
| m.navigateUp() | ||
| case slices.Contains(common.Hotkeys.ListDown, msg.String()): | ||
| m.navigateDown() | ||
| case slices.Contains(common.Hotkeys.PageUp, msg.String()): | ||
| m.navigatePageUp() | ||
| case slices.Contains(common.Hotkeys.PageDown, msg.String()): | ||
| m.navigatePageDown() | ||
| case slices.Contains(common.Hotkeys.GotoPinned, msg.String()) && m.justOpened: | ||
| m.justOpened = false | ||
| default: | ||
| cmd = m.handleNormalKeyInput(msg) | ||
| } | ||
| default: | ||
| m.textInput, cmd = m.textInput.Update(msg) | ||
| } | ||
| return action, cmd | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| func (m *Model) handleConfirm() common.ModelAction { | ||
| if len(m.results) > 0 && m.cursor >= 0 && m.cursor < len(m.results) { | ||
| selectedDir := m.results[m.cursor] | ||
| return common.CDCurrentPanelAction{ | ||
| Location: selectedDir.Location, | ||
| } | ||
| } | ||
| return common.NoAction{} | ||
| } | ||
|
|
||
| func (m *Model) handleNormalKeyInput(msg tea.KeyMsg) tea.Cmd { | ||
| var cmd tea.Cmd | ||
| m.textInput, cmd = m.textInput.Update(msg) | ||
| return tea.Batch(cmd, m.GetQueryCmd(m.textInput.Value())) | ||
| } | ||
|
|
||
| func (m *Model) GetQueryCmd(query string) tea.Cmd { | ||
| reqID := m.reqCnt | ||
| allDirs := m.allDirs | ||
| m.reqCnt++ | ||
| return func() tea.Msg { | ||
| results := filterPinnedDirs(query, allDirs) | ||
| return NewUpdateMsg(query, results, reqID, "") | ||
| } | ||
| } | ||
|
|
||
| func filterPinnedDirs(query string, allDirs []Directory) []Directory { | ||
| if query == "" { | ||
| return allDirs | ||
| } | ||
|
|
||
| if len(allDirs) == 0 { | ||
| return []Directory{} | ||
| } | ||
|
|
||
| var filteredDirs []Directory | ||
|
|
||
| haystack := make([]string, len(allDirs)) | ||
| for i, dir := range allDirs { | ||
| searchText := dir.Name + " " + dir.Location | ||
| haystack[i] = searchText | ||
| } | ||
|
|
||
| for _, match := range utils.FzfSearch(query, haystack) { | ||
| if match.HayIndex >= 0 && int(match.HayIndex) < len(allDirs) { | ||
| filteredDirs = append(filteredDirs, allDirs[match.HayIndex]) | ||
| } | ||
| } | ||
|
|
||
| return filteredDirs | ||
| } | ||
|
|
||
| func (m *Model) LoadPinnedDirs(dirs []Directory) { | ||
| m.allDirs = dirs | ||
| m.results = dirs | ||
| m.cursor = 0 | ||
| m.renderIndex = 0 | ||
| } | ||
|
|
||
| func (m *Model) FilterPinnedDirs(query string) { | ||
| m.results = filterPinnedDirs(query, m.allDirs) | ||
| m.cursor = 0 | ||
| m.renderIndex = 0 | ||
| } | ||
|
|
||
| func (msg UpdateMsg) Apply(m *Model) tea.Cmd { | ||
| currentQuery := m.textInput.Value() | ||
| if msg.query != currentQuery { | ||
| return nil | ||
| } | ||
|
|
||
| m.results = msg.results | ||
| m.cursor = 0 | ||
| m.renderIndex = 0 | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.