|
|
@ -4111,15 +4111,16 @@ fn surround_add(cx: &mut Context) {
|
|
|
|
fn surround_replace(cx: &mut Context) {
|
|
|
|
fn surround_replace(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
let from = match event.char() {
|
|
|
|
let surround_ch = match event.char() {
|
|
|
|
Some(from) => from,
|
|
|
|
Some('m') => None, // m selects the closest surround pair
|
|
|
|
|
|
|
|
Some(ch) => Some(ch),
|
|
|
|
None => return,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
|
|
|
|
|
|
|
|
let change_pos = match surround::get_surround_pos(text, selection, from, count) {
|
|
|
|
let change_pos = match surround::get_surround_pos(text, selection, surround_ch, count) {
|
|
|
|
Ok(c) => c,
|
|
|
|
Ok(c) => c,
|
|
|
|
Err(err) => {
|
|
|
|
Err(err) => {
|
|
|
|
cx.editor.set_error(err.to_string());
|
|
|
|
cx.editor.set_error(err.to_string());
|
|
|
@ -4150,15 +4151,16 @@ fn surround_replace(cx: &mut Context) {
|
|
|
|
fn surround_delete(cx: &mut Context) {
|
|
|
|
fn surround_delete(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
let ch = match event.char() {
|
|
|
|
let surround_ch = match event.char() {
|
|
|
|
Some(ch) => ch,
|
|
|
|
Some('m') => None, // m selects the closest surround pair
|
|
|
|
|
|
|
|
Some(ch) => Some(ch),
|
|
|
|
None => return,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
|
|
|
|
|
|
|
|
let change_pos = match surround::get_surround_pos(text, selection, ch, count) {
|
|
|
|
let change_pos = match surround::get_surround_pos(text, selection, surround_ch, count) {
|
|
|
|
Ok(c) => c,
|
|
|
|
Ok(c) => c,
|
|
|
|
Err(err) => {
|
|
|
|
Err(err) => {
|
|
|
|
cx.editor.set_error(err.to_string());
|
|
|
|
cx.editor.set_error(err.to_string());
|
|
|
|