|
|
@ -36,7 +36,7 @@ use helix_core::{
|
|
|
|
textobject,
|
|
|
|
textobject,
|
|
|
|
unicode::width::UnicodeWidthChar,
|
|
|
|
unicode::width::UnicodeWidthChar,
|
|
|
|
visual_offset_from_block, Deletion, LineEnding, Position, Range, Rope, RopeGraphemes,
|
|
|
|
visual_offset_from_block, Deletion, LineEnding, Position, Range, Rope, RopeGraphemes,
|
|
|
|
RopeReader, RopeSlice, Selection, SmallVec, Syntax, Tendril, Transaction,
|
|
|
|
RopeReader, RopeSlice, Selection, SmallVec, SmartString, Syntax, Tendril, Transaction,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use helix_view::{
|
|
|
|
use helix_view::{
|
|
|
|
document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
|
|
|
|
document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
|
|
|
@ -5616,6 +5616,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
|
|
|
("a", "Argument/parameter (tree-sitter)"),
|
|
|
|
("a", "Argument/parameter (tree-sitter)"),
|
|
|
|
("c", "Comment (tree-sitter)"),
|
|
|
|
("c", "Comment (tree-sitter)"),
|
|
|
|
("T", "Test (tree-sitter)"),
|
|
|
|
("T", "Test (tree-sitter)"),
|
|
|
|
|
|
|
|
("x", "Tag (XML/HTML/JSX)"),
|
|
|
|
("e", "Data structure entry (tree-sitter)"),
|
|
|
|
("e", "Data structure entry (tree-sitter)"),
|
|
|
|
("m", "Closest surrounding pair (tree-sitter)"),
|
|
|
|
("m", "Closest surrounding pair (tree-sitter)"),
|
|
|
|
("g", "Change"),
|
|
|
|
("g", "Change"),
|
|
|
@ -5625,6 +5626,54 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
|
|
|
cx.editor.autoinfo = Some(Info::new(title, &help_text));
|
|
|
|
cx.editor.autoinfo = Some(Info::new(title, &help_text));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn create_surround_prompt(
|
|
|
|
|
|
|
|
editor: &Editor,
|
|
|
|
|
|
|
|
prefill: String,
|
|
|
|
|
|
|
|
history_register: Option<char>,
|
|
|
|
|
|
|
|
) -> Box<Prompt> {
|
|
|
|
|
|
|
|
let prompt = Prompt::new(
|
|
|
|
|
|
|
|
"tag name:".into(),
|
|
|
|
|
|
|
|
// TODO: change this to actually be history_register
|
|
|
|
|
|
|
|
Some('z'),
|
|
|
|
|
|
|
|
ui::completers::none,
|
|
|
|
|
|
|
|
move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.with_line("temp".into(), editor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(prompt)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn surround_add_impl(
|
|
|
|
|
|
|
|
doc: &mut Document,
|
|
|
|
|
|
|
|
// cx: &mut Context<'_>,
|
|
|
|
|
|
|
|
view: &mut View,
|
|
|
|
|
|
|
|
surround_len: usize,
|
|
|
|
|
|
|
|
open: Tendril,
|
|
|
|
|
|
|
|
close: Tendril,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
|
|
|
|
let mut changes = Vec::with_capacity(selection.len() * 2);
|
|
|
|
|
|
|
|
let mut ranges = SmallVec::with_capacity(selection.len());
|
|
|
|
|
|
|
|
let mut offs = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for range in selection.iter() {
|
|
|
|
|
|
|
|
changes.push((range.from(), range.from(), Some(open.clone())));
|
|
|
|
|
|
|
|
changes.push((range.to(), range.to(), Some(close.clone())));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ranges.push(
|
|
|
|
|
|
|
|
Range::new(offs + range.from(), offs + range.to() + surround_len)
|
|
|
|
|
|
|
|
.with_direction(range.direction()),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offs += surround_len;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let transaction = Transaction::change(doc.text(), changes.into_iter())
|
|
|
|
|
|
|
|
.with_selection(Selection::new(ranges, selection.primary_index()));
|
|
|
|
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
|
|
|
|
// exit_select_mode(cx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn surround_add(cx: &mut Context) {
|
|
|
|
fn surround_add(cx: &mut Context) {
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
@ -5633,20 +5682,23 @@ fn surround_add(cx: &mut Context) {
|
|
|
|
Some(ch) => {
|
|
|
|
Some(ch) => {
|
|
|
|
let mut open = Tendril::new();
|
|
|
|
let mut open = Tendril::new();
|
|
|
|
let mut close = Tendril::new();
|
|
|
|
let mut close = Tendril::new();
|
|
|
|
let length = if ch == 'x' {
|
|
|
|
// let length = if ch == 'x' {
|
|
|
|
let (o, c) = match_brackets::get_pair(ch);
|
|
|
|
// let prompt = create_surround_prompt(cx.editor, "none".into(), Some('z'));
|
|
|
|
open.push(o);
|
|
|
|
// cx.push_layer(prompt);
|
|
|
|
close.push(c);
|
|
|
|
|
|
|
|
// Any character other than "x" will cause 2 chars to get added
|
|
|
|
// let (o, c) = match_brackets::get_pair(ch);
|
|
|
|
2
|
|
|
|
// open.push(o);
|
|
|
|
} else {
|
|
|
|
// close.push(c);
|
|
|
|
|
|
|
|
// // Any character other than "x" will cause 2 chars to get added
|
|
|
|
|
|
|
|
// 2
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
let (o, c) = match_brackets::get_pair(ch);
|
|
|
|
let (o, c) = match_brackets::get_pair(ch);
|
|
|
|
open.push(o);
|
|
|
|
open.push(o);
|
|
|
|
close.push(c);
|
|
|
|
close.push(c);
|
|
|
|
// Any character other than "x" will cause 2 chars to get added
|
|
|
|
// Any character other than "x" will cause 2 chars to get added
|
|
|
|
2
|
|
|
|
// 2
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
(open, close, length)
|
|
|
|
(open, close, 2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None if event.code == KeyCode::Enter => (
|
|
|
|
None if event.code == KeyCode::Enter => (
|
|
|
|
doc.line_ending.as_str().into(),
|
|
|
|
doc.line_ending.as_str().into(),
|
|
|
@ -5656,27 +5708,30 @@ fn surround_add(cx: &mut Context) {
|
|
|
|
None => return,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
surround_add_impl(doc, view, surround_len, open, close);
|
|
|
|
let mut changes = Vec::with_capacity(selection.len() * 2);
|
|
|
|
exit_select_mode(cx);
|
|
|
|
let mut ranges = SmallVec::with_capacity(selection.len());
|
|
|
|
|
|
|
|
let mut offs = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for range in selection.iter() {
|
|
|
|
// let selection = doc.selection(view.id);
|
|
|
|
changes.push((range.from(), range.from(), Some(open.clone())));
|
|
|
|
// let mut changes = Vec::with_capacity(selection.len() * 2);
|
|
|
|
changes.push((range.to(), range.to(), Some(close.clone())));
|
|
|
|
// let mut ranges = SmallVec::with_capacity(selection.len());
|
|
|
|
|
|
|
|
// let mut offs = 0;
|
|
|
|
|
|
|
|
|
|
|
|
ranges.push(
|
|
|
|
// for range in selection.iter() {
|
|
|
|
Range::new(offs + range.from(), offs + range.to() + surround_len)
|
|
|
|
// changes.push((range.from(), range.from(), Some(open.clone())));
|
|
|
|
.with_direction(range.direction()),
|
|
|
|
// changes.push((range.to(), range.to(), Some(close.clone())));
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offs += surround_len;
|
|
|
|
// ranges.push(
|
|
|
|
}
|
|
|
|
// Range::new(offs + range.from(), offs + range.to() + surround_len)
|
|
|
|
|
|
|
|
// .with_direction(range.direction()),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
let transaction = Transaction::change(doc.text(), changes.into_iter())
|
|
|
|
// offs += surround_len;
|
|
|
|
.with_selection(Selection::new(ranges, selection.primary_index()));
|
|
|
|
// }
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
|
|
|
|
exit_select_mode(cx);
|
|
|
|
// let transaction = Transaction::change(doc.text(), changes.into_iter())
|
|
|
|
|
|
|
|
// .with_selection(Selection::new(ranges, selection.primary_index()));
|
|
|
|
|
|
|
|
// doc.apply(&transaction, view.id);
|
|
|
|
|
|
|
|
// exit_select_mode(cx);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|