-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Improve return values of some actions + some improvements #3352
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
781f057
Improve Undo & Redo actions return values
dmaluka fc5d83f
Improve RemoveMultiCursor & RemoveAllMultiCursors actions return values
dmaluka e2e8baf
Improve misc actions return values
dmaluka 7e09a92
Make it clear that ClearStatus is the same as ClearInfo
dmaluka 2793c37
Fix SkipMultiCursor behavior when there is no selection
dmaluka aa9c476
Improve RemoveMultiCursor behavior
dmaluka 5c8bf6b
Improve RemoveAllMultiCursors behavior
dmaluka 765889f
Fix execution of {Spawn,Remove}MultiCursor in chained actions
dmaluka 0373a63
Refactor action execution code
dmaluka 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,29 +150,31 @@ func BufMapEvent(k Event, action string) { | |
| actionfns = append(actionfns, afn) | ||
| } | ||
| bufAction := func(h *BufPane, te *tcell.EventMouse) bool { | ||
| cursors := h.Buf.GetCursors() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cursors assignment would need to be moved 2 lines down into the actions loop. Otherwise you would still use the cursors of the original pane even though you switched to a new one in a next iteration. Line 170 updates the reference to |
||
| success := true | ||
| for i, a := range actionfns { | ||
| innerSuccess := true | ||
| for j, c := range cursors { | ||
| if c == nil { | ||
| continue | ||
| } | ||
| h.Buf.SetCurCursor(c.Num) | ||
| h.Cursor = c | ||
| if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') { | ||
| innerSuccess = innerSuccess && h.execAction(a, names[i], j, te) | ||
| } else { | ||
| break | ||
| var success bool | ||
| if _, ok := MultiActions[names[i]]; ok { | ||
| success = true | ||
| for _, c := range h.Buf.GetCursors() { | ||
| h.Buf.SetCurCursor(c.Num) | ||
| h.Cursor = c | ||
| success = success && h.execAction(a, names[i], te) | ||
| } | ||
| } else { | ||
| h.Buf.SetCurCursor(0) | ||
| h.Cursor = h.Buf.GetActiveCursor() | ||
| success = h.execAction(a, names[i], te) | ||
| } | ||
|
|
||
| // if the action changed the current pane, update the reference | ||
| h = MainTab().CurPane() | ||
| success = innerSuccess | ||
| if h == nil { | ||
| // stop, in case the current pane is not a BufPane | ||
| break | ||
| } | ||
|
|
||
| if (!success && types[i] == '&') || (success && types[i] == '|') { | ||
| break | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
@@ -562,36 +564,33 @@ func (h *BufPane) DoKeyEvent(e Event) bool { | |
| return more | ||
| } | ||
|
|
||
| func (h *BufPane) execAction(action BufAction, name string, cursor int, te *tcell.EventMouse) bool { | ||
| func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse) bool { | ||
| if name != "Autocomplete" && name != "CycleAutocompleteBack" { | ||
| h.Buf.HasSuggestions = false | ||
| } | ||
|
|
||
| _, isMulti := MultiActions[name] | ||
| if (!isMulti && cursor == 0) || isMulti { | ||
| if h.PluginCB("pre" + name) { | ||
| var success bool | ||
| switch a := action.(type) { | ||
| case BufKeyAction: | ||
| success = a(h) | ||
| case BufMouseAction: | ||
| success = a(h, te) | ||
| } | ||
| success = success && h.PluginCB("on"+name) | ||
| if !h.PluginCB("pre" + name) { | ||
| return false | ||
| } | ||
|
|
||
| if isMulti { | ||
| if recordingMacro { | ||
| if name != "ToggleMacro" && name != "PlayMacro" { | ||
| curmacro = append(curmacro, action) | ||
| } | ||
| } | ||
| } | ||
| var success bool | ||
| switch a := action.(type) { | ||
| case BufKeyAction: | ||
| success = a(h) | ||
| case BufMouseAction: | ||
| success = a(h, te) | ||
| } | ||
| success = success && h.PluginCB("on"+name) | ||
|
|
||
| return success | ||
| if _, ok := MultiActions[name]; ok { | ||
| if recordingMacro { | ||
| if name != "ToggleMacro" && name != "PlayMacro" { | ||
| curmacro = append(curmacro, action) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| return success | ||
| } | ||
|
|
||
| func (h *BufPane) completeAction(action string) { | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -242,6 +242,7 @@ ToggleDiffGutter | |
| ToggleRuler | ||
| JumpLine | ||
| ResetSearch | ||
| ClearInfo | ||
| ClearStatus | ||
| ShellMode | ||
| CommandMode | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing refactoring! It is way clearer now what the code is suppose to do. And you squashed a bug along the way. In the original implementation the correct cursors reference gets lost after switching to a different BufPane.