cantino/mcfly

Issue : Deleting an entry makes the cursor go back to the top

dasebasto opened this issue · 3 comments

When cleaning-up history, it's frequent that we need to delete multiple contiguous lines/entries.

This could be super quick with repeated strokes on F2 (if delete_without_confirm is enabled).
Unfortunately, it's not convenient, because, after deletion, the cursor goes back to the top item.

Suggestion: after deletion of entry on line N, line N (and the corresponding entry) should stay selected (unless N was the last item, in which case line N-1 should be selected).
This is basically the standard behavior of all UX where user can select and delete items in a list using up/down arrows and Del.

By the way, is there a way to always enable delete_without_confirm on Ctrl-R ?

to always enable delete_without_confirm, set MCFLY_DELETE_WITHOUT_CONFIRM=true in your shell config

  • bash / zsh
export MCFLY_DELETE_WITHOUT_CONFIRM=true
  • fish
set -gx MCFLY_DELETE_WITHOUT_CONFIRM true

@cantino The quick fix to allowing this functionality is to remove self.selection = 0; from below.

    fn refresh_matches(&mut self) {
        self.selection = 0;
        self.matches = self.history.find_matches(
            &self.input.command,
            self.settings.results as i16,
            self.settings.fuzzy,
            &self.result_sort,
        );
    }

However, this would make any functionality that also call refresh_matches to not reset the selection to the top, i.e., changing result sort. What are your thoughts on this?

@navazjm Would be great to change the code a bit so that the selection tweak only applies when the delete hotkey is pressed.

Yes, I think it needs to be an option to refresh_matches and only set for deletion, not universally. I'm open to a PR for that change!