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

Add pseudo_pending for ms/mr/md #3381

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4377,7 +4377,9 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
}

fn surround_add(cx: &mut Context) {
cx.editor.pseudo_pending = Some("ma".to_string());
cx.on_next_key(move |cx, event| {
cx.editor.pseudo_pending = None;
let ch = match event.char() {
Some(ch) => ch,
None => return,
Expand All @@ -4403,7 +4405,9 @@ fn surround_add(cx: &mut Context) {

fn surround_replace(cx: &mut Context) {
Copy link
Member

@the-mikedavis the-mikedavis Aug 14, 2022

Choose a reason for hiding this comment

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

Surround-replace has two cx.on_next_keys, one for the starting character and one for the replacement. Nested in the first cx.on_next_key, we should add the character from the event to the pseudo-pending and then clear it within the second

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll take a look at that.

let count = cx.count();
cx.editor.pseudo_pending = Some("mr".to_string());
cx.on_next_key(move |cx, event| {
cx.editor.pseudo_pending = None;
let surround_ch = match event.char() {
Some('m') => None, // m selects the closest surround pair
Some(ch) => Some(ch),
Expand Down Expand Up @@ -4443,7 +4447,9 @@ fn surround_replace(cx: &mut Context) {

fn surround_delete(cx: &mut Context) {
let count = cx.count();
cx.editor.pseudo_pending = Some("md".to_string());
cx.on_next_key(move |cx, event| {
cx.editor.pseudo_pending = None;
let surround_ch = match event.char() {
Some('m') => None, // m selects the closest surround pair
Some(ch) => Some(ch),
Expand Down