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

[REQUEST] Restore the original selection after undoing the result of the execute-keys. #5257

Open
igor-ramazanov opened this issue Nov 16, 2024 · 1 comment

Comments

@igor-ramazanov
Copy link
Contributor

Feature

So, I'm not sure if that's a big deal.
Maybe the issue could be closed after some discussion.

Problem: it's not a trivial task to implement a surround (surrounding a selection with some characters) command which:

  1. Will extend the selection to include pre- and app- ended characters.
  2. On undo will revert both the changes and selection to the state before surrounding.

Example 1:

# 1. ☑️
# 2. ❌: on `u` will create 2 cursors: one for `P` and another for `p`.

def surround -params 2 %{
  eval -save-regs 'ab' %{
    reg a %arg{1}
    reg b %arg{2}
    exec 'Z"aP<a-z>uZ"bp<a-z>u<esc>'
  }
}

Example 2:

# 1. ☑️
# 2. ☑️: however, it relies on the `%val{selection}` which may be a problem on big chunks of text (important?).

def surround -params 2 %{
  eval -save-regs '"' %{
    reg dquote "%arg{1}%val{selection}%arg{2}"
    exec R
  }
}

Example 3:

# 1. ☑️
# 2. ☑️: however, it also relies on the meaningless `yr_R` change only to be registered in the `undo` group.

def surround -params 2 %{
  eval -save-regs 'ab' %{
    reg a %arg{1}
    reg b %arg{2}
    exec 'Z"aP<a-z>uZ"bp<a-z>uyr_R'
  }
}

Seems that the first example is the most obvious and economical, but it creates a second cursor.

Usecase

No response

@krobelus
Copy link
Contributor

krobelus commented Nov 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants