Skip to content
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

Delete and edit custom commands history items #3534

Merged
merged 3 commits into from May 19, 2024

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Apr 27, 2024

  • PR Description

Allow deleting and editing custom command history items. Deleting is done by hitting d on a suggestion; editing is done by hitting e, which fills the selected item into the command prompt for further editing.

Closes #2528.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • Docs (specifically docs/Config.md) have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller
Copy link
Collaborator Author

Marking this as a draft for now because I didn't add tests yet. Before I spend time on that I first wanted to confirm that we want this. (I find it pretty useful myself.)

@stefanhaller stefanhaller added the enhancement New feature or request label Apr 27, 2024
Copy link

codacy-production bot commented Apr 27, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 269d0121 92.31%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (269d012) Report Missing Report Missing Report Missing
Head commit (010b0ae) 50964 42960 84.29%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3534) 130 120 92.31%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@mark2185
Copy link
Collaborator

Just for future reference, this will close #2528 .

@stefanhaller stefanhaller force-pushed the delete-and-edit-custom-commands-history-items branch from e4a68b8 to 6eef8f2 Compare May 15, 2024 11:32
Handler: func() error { return self.c.ReplaceContext(self.c.Contexts().Confirmation) },
Key: opts.GetKey(opts.Config.Universal.TogglePanel),
Handler: func() error {
if self.context().State.FillInTextOnTogglePanel {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this returns false, we should still replace the context, right?

EDIT: wait that's exactly what's happening: I misread the indentation

@stefanhaller stefanhaller mentioned this pull request May 15, 2024
@stefanhaller stefanhaller force-pushed the delete-and-edit-custom-commands-history-items branch 2 times, most recently from f4231fd to 5d3f2a0 Compare May 17, 2024 16:15
@stefanhaller stefanhaller marked this pull request as ready for review May 17, 2024 16:18
@stefanhaller
Copy link
Collaborator Author

@jesseduffield I changed the keybinding for editing a history command from tab to "e", as discussed; and added a commit that shows the keybindings in the subtitle of the suggestions panel (only if it is focused).

// are also editable, so we show both keybindings
subtitle = fmt.Sprintf(self.c.Tr.SuggestionsSubtitle,
self.c.UserConfig.Keybinding.Universal.Remove, self.c.UserConfig.Keybinding.Universal.Edit)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jesseduffield I'm showing the keybindings when the suggestions panel gets the focus (and remove it again in the opposite handler in SuggestionsController). I would have preferred not to do this here, but in GetOnFocus/GetOnFocusLost, so that it is reliably called no matter how we switch focus (maybe we want to make it possible some day to click on a suggestion to select it).

But that's not possible right now because ContextMgr.Replace only calls Activate on the new context, but not deactivate on the old one. I tried to "fix" that, but that's not possible because the GetOnFocusLost of both ConfirmationController and SuggestionsController destroys the panel.

I'm not sure how to solve this cleanly; let me know if you have any suggestions. For now we just put it here in the tab handler, which works fine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I am not sure how to solve that cleanly. Happy to use your stopgap solution

@stefanhaller stefanhaller added this to the v0.42 milestone May 18, 2024
Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stefanhaller stefanhaller force-pushed the delete-and-edit-custom-commands-history-items branch from 5d3f2a0 to 00f7c3d Compare May 19, 2024 05:02
In the custom commands panel you can now tab to the suggestions and hit 'd' to
delete items from there. Useful if you mistyped a command and don't want it to
appear in your history any more.
For custom commands it is useful to select an earlier command and have it copied
to the prompt for further editing. This can be done by hitting 'e' now.

For other types of suggestion panels we don't enable this behavior, as you can't
create arbitrary new items there that don't already exist as a suggestion.
@stefanhaller stefanhaller force-pushed the delete-and-edit-custom-commands-history-items branch from 00f7c3d to 010b0ae Compare May 19, 2024 05:06
@stefanhaller stefanhaller merged commit 866e805 into master May 19, 2024
14 checks passed
@stefanhaller stefanhaller deleted the delete-and-edit-custom-commands-history-items branch May 19, 2024 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command to remove command history
3 participants