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

fix: surround delete <ret> #12496

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5733,7 +5733,8 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
cx.editor.autoinfo = Some(Info::new(title, &help_text));
}

static SURROUND_HELP_TEXT: [(&str, &str); 5] = [
static SURROUND_HELP_TEXT: [(&str, &str); 6] = [
("m", "Closest matching pair"),
("( or )", "Parentheses"),
("{ or }", "Curly braces"),
("< or >", "Angled brackets"),
Expand Down Expand Up @@ -5860,11 +5861,14 @@ fn surround_delete(cx: &mut Context) {
let count = cx.count();
cx.on_next_key(move |cx, event| {
cx.editor.autoinfo = None;
let surround_ch = match event.char() {
Some('m') => None, // m selects the closest surround pair
Some(ch) => Some(ch),
None => return,

let surround_ch = match (event.code, event.char()) {
(KeyCode::Enter, _) => Some('\n'), // special case for <ret>
Copy link
Member

Choose a reason for hiding this comment

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

Same as #12521 (comment) this needs to search for doc.line_ending.as_str() which means that some of the code in surround needs to be refactored to accept &strs rather than chars

Copy link
Contributor

Choose a reason for hiding this comment

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

another alternative, which would make for a simpler implementation would be to use line_to_char to delete line breaks at specific character indices. For example, it would be similar to what i did here

(_, Some('m')) => None, // m selects closest pair
(_, Some(ch)) => Some(ch),
_ => return,
};

let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
let selection = doc.selection(view.id);
Expand Down
Loading