Update change-case commands to work with gap indexing.

pull/376/head
Nathan Vegdahl 3 years ago
parent a77274e8bb
commit 954314a7c9

@ -786,8 +786,11 @@ fn replace(cx: &mut Context) {
fn switch_case(cx: &mut Context) { fn switch_case(cx: &mut Context) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let transaction = let selection = doc
Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| { .selection(view.id)
.clone()
.min_width_1(doc.text().slice(..));
let transaction = Transaction::change_by_selection(doc.text(), &selection, |range| {
let text: Tendril = range let text: Tendril = range
.fragment(doc.text().slice(..)) .fragment(doc.text().slice(..))
.chars() .chars()
@ -802,7 +805,7 @@ fn switch_case(cx: &mut Context) {
}) })
.collect(); .collect();
(range.from(), range.to() + 1, Some(text)) (range.from(), range.to(), Some(text))
}); });
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
@ -811,11 +814,14 @@ fn switch_case(cx: &mut Context) {
fn switch_to_uppercase(cx: &mut Context) { fn switch_to_uppercase(cx: &mut Context) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let transaction = let selection = doc
Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| { .selection(view.id)
.clone()
.min_width_1(doc.text().slice(..));
let transaction = Transaction::change_by_selection(doc.text(), &selection, |range| {
let text: Tendril = range.fragment(doc.text().slice(..)).to_uppercase().into(); let text: Tendril = range.fragment(doc.text().slice(..)).to_uppercase().into();
(range.from(), range.to() + 1, Some(text)) (range.from(), range.to(), Some(text))
}); });
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
@ -824,11 +830,14 @@ fn switch_to_uppercase(cx: &mut Context) {
fn switch_to_lowercase(cx: &mut Context) { fn switch_to_lowercase(cx: &mut Context) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let transaction = let selection = doc
Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| { .selection(view.id)
.clone()
.min_width_1(doc.text().slice(..));
let transaction = Transaction::change_by_selection(doc.text(), &selection, |range| {
let text: Tendril = range.fragment(doc.text().slice(..)).to_lowercase().into(); let text: Tendril = range.fragment(doc.text().slice(..)).to_lowercase().into();
(range.from(), range.to() + 1, Some(text)) (range.from(), range.to(), Some(text))
}); });
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);

Loading…
Cancel
Save