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

keybind not working: delete_selection_noyank, search_prev #10050

Closed
timokoesters opened this issue Mar 30, 2024 · 4 comments · Fixed by #10132
Closed

keybind not working: delete_selection_noyank, search_prev #10050

timokoesters opened this issue Mar 30, 2024 · 4 comments · Fixed by #10132
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR

Comments

@timokoesters
Copy link

Summary

This should do the same as ?=<enter>. This works if I replace delete_selection_noyank with delete_selection.

"C-l" = [
  ":append-output echo -n =",
  "search_selection",
  "delete_selection_noyank",
  "search_prev",
]

The response on matrix was:

It could be the case that delete_selection_noyankkeeps the register at _ so search_prev tries looking at _ (which is the null register) so it doesn't do anything

https://matrix.to/#/!zMuVRxoqjyxyjSEBXc:matrix.org/$nt9EkBO1jiVDOp1LDJf0hBHk_MmipL6RttvCJMU1-es?via=matrix.org&via=tchncs.de&via=mozilla.org

Reproduction Steps

No response

Helix log

No response

Platform

Linux

Terminal Emulator

Alacritty

Installation Method

AUR

Helix Version

helix 23.10

@timokoesters timokoesters added the C-bug Category: This is a bug label Mar 30, 2024
@the-mikedavis
Copy link
Member

the-mikedavis commented Mar 31, 2024

The _noyank commands set the register to _ but the register isn't reset if the commands are run in a keymap sequence. These functions

fn delete_selection_noyank(cx: &mut Context) {
cx.register = Some('_');
delete_selection_impl(cx, Operation::Delete);
}
fn change_selection(cx: &mut Context) {
delete_selection_impl(cx, Operation::Change);
}
fn change_selection_noyank(cx: &mut Context) {
cx.register = Some('_');
delete_selection_impl(cx, Operation::Change);
}

could be updated to save the value of cx.register before cx.register = Some('_') and reset cx.register to that value after the deletion/change

EDIT: or instead, pass a boolean for wether to yank or not. Passing in the _ register is not much different than a boolean and is just less explicit

@the-mikedavis the-mikedavis added the E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR label Mar 31, 2024
@kirawi kirawi added A-helix-term Area: Helix term improvements E-good-first-issue Call for participation: Issues suitable for new contributors labels Mar 31, 2024
@voiceroy
Copy link
Contributor

voiceroy commented Apr 3, 2024

Something along these lines?

fn delete_selection_noyank(cx: &mut Context) {
    let old_register = cx.register;
    cx.register = Some('_');
    delete_selection_impl(cx, Operation::Delete);
    cx.register = old_register;
}

fn change_selection(cx: &mut Context) {
    // let old_register = cx.register;
    delete_selection_impl(cx, Operation::Change);
    // cx.register = old_register;
}

fn change_selection_noyank(cx: &mut Context) {
    let old_register = cx.register;
    cx.register = Some('_');
    delete_selection_impl(cx, Operation::Change);
    cx.register = old_register;
}

@the-mikedavis
Copy link
Member

On second thought I would prefer we introduce an extra parameter yank: bool to delete_selection_impl:

fn delete_selection(cx: &mut Context) {
    delete_selection_impl(cx, Operation::Delete, true);
}

fn delete_selection_noyank(cx: &mut Context) {
    delete_selection_impl(cx, Operation::Delete, false);
}

fn change_selection(cx: &mut Context) {
    delete_selection_impl(cx, Operation::Change, true);
}

fn change_selection_noyank(cx: &mut Context) {
    delete_selection_impl(cx, Operation::Change, false);
}

It would mean that we do an unnecessary allocation when you use "_d or "_c" but it's more explicit and simpler, and also fixes this issue.

@voiceroy
Copy link
Contributor

voiceroy commented Apr 3, 2024

I think

"C-l" = [
  ":append-output echo -n =",
  "search_selection",
  "delete_selection_noyank",
  "search_prev",
]

appends an = next to the current character and then selects it, then deletes it without yanking (assuming it's fixed), and then searches for a previous match which would be the = found at the initial 'run' of this keybind. Whenever the keybind C-l is run this would be the process. Hence not going to previous selection as N would do after ?=<enter>.

Eg:

Let the file contents be:

=    # line 1
test # line 2
=    # line 3
  1. test (line 2, pressed C-l)
  2. test= (= appended)
  3. test|=| (= selected)
  4. test (= deleted)
  5. = (found an = while doing search_prev at line 1)
  6. == (if pressed C-l again, appending =)
  7. =|=| (appended = selected)
  8. = (delete the selected =)
  9. = (search_prev, still at line 1 and not going to the = at line 3)
  10. and the whole thing from 6-9 repeats if C-l is pressed

Can anyone confirm that what I said above is correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants