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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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
+0.01% (target: -2.00%) 92.31%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (d8b3c0e) 50834 42840 84.27%
Head commit (5d3f2a0) 50952 (+118) 42943 (+103) 84.28% (+0.01%)

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

@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

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 6eef8f2 to f4231fd Compare May 17, 2024 16:14
@stefanhaller stefanhaller force-pushed the delete-and-edit-custom-commands-history-items branch 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
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