|
|
@ -310,44 +310,77 @@ impl PartialEq for Command {
|
|
|
|
fn move_char_left(cx: &mut Context) {
|
|
|
|
fn move_char_left(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_horizontally(text, range, Direction::Backward, count, Movement::Move)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Move,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_char_right(cx: &mut Context) {
|
|
|
|
fn move_char_right(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_horizontally(text, range, Direction::Forward, count, Movement::Move)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Move,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_line_up(cx: &mut Context) {
|
|
|
|
fn move_line_up(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_vertically(text, range, Direction::Backward, count, Movement::Move)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Move,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_line_down(cx: &mut Context) {
|
|
|
|
fn move_line_down(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_vertically(text, range, Direction::Forward, count, Movement::Move)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Move,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_line_end(cx: &mut Context) {
|
|
|
|
fn move_line_end(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| {
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = doc.text();
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
let pos = line_end_char_index(&text.slice(..), line);
|
|
|
|
let pos = line_end_char_index(&text.slice(..), line);
|
|
|
@ -355,27 +388,31 @@ fn move_line_end(cx: &mut Context) {
|
|
|
|
let pos = range.head.max(pos).max(text.line_to_char(line));
|
|
|
|
let pos = range.head.max(pos).max(text.line_to_char(line));
|
|
|
|
|
|
|
|
|
|
|
|
Range::new(pos, pos)
|
|
|
|
Range::new(pos, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_line_start(cx: &mut Context) {
|
|
|
|
fn move_line_start(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| {
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = doc.text();
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
// adjust to start of the line
|
|
|
|
// adjust to start of the line
|
|
|
|
let pos = text.line_to_char(line);
|
|
|
|
let pos = text.line_to_char(line);
|
|
|
|
Range::new(pos, pos)
|
|
|
|
Range::new(pos, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_first_nonwhitespace(cx: &mut Context) {
|
|
|
|
fn move_first_nonwhitespace(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| {
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = doc.text();
|
|
|
|
let line_idx = text.char_to_line(range.head);
|
|
|
|
let line_idx = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(pos) = find_first_non_whitespace_char(text.line(line_idx)) {
|
|
|
|
if let Some(pos) = find_first_non_whitespace_char(text.line(line_idx)) {
|
|
|
@ -384,7 +421,8 @@ fn move_first_nonwhitespace(cx: &mut Context) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
range
|
|
|
|
range
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: move vs extend could take an extra type Extend/Move that would
|
|
|
|
// TODO: move vs extend could take an extra type Extend/Move that would
|
|
|
@ -395,48 +433,67 @@ fn move_next_word_start(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| movement::move_next_word_start(text, range, count));
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id)
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.transform(|range| movement::move_next_word_start(doc.text().slice(..), range, count)),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_prev_word_start(cx: &mut Context) {
|
|
|
|
fn move_prev_word_start(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| movement::move_prev_word_start(text, range, count));
|
|
|
|
doc.selection(view.id)
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.transform(|range| movement::move_prev_word_start(doc.text().slice(..), range, count)),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_next_word_end(cx: &mut Context) {
|
|
|
|
fn move_next_word_end(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| movement::move_next_word_end(text, range, count));
|
|
|
|
doc.selection(view.id)
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.transform(|range| movement::move_next_word_end(doc.text().slice(..), range, count)),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_next_long_word_start(cx: &mut Context) {
|
|
|
|
fn move_next_long_word_start(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| movement::move_next_long_word_start(text, range, count));
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
movement::move_next_long_word_start(doc.text().slice(..), range, count)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_prev_long_word_start(cx: &mut Context) {
|
|
|
|
fn move_prev_long_word_start(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| movement::move_prev_long_word_start(text, range, count));
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
movement::move_prev_long_word_start(doc.text().slice(..), range, count)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_next_long_word_end(cx: &mut Context) {
|
|
|
|
fn move_next_long_word_end(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| movement::move_next_long_word_end(text, range, count));
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
movement::move_next_long_word_end(doc.text().slice(..), range, count)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_file_start(cx: &mut Context) {
|
|
|
|
fn move_file_start(cx: &mut Context) {
|
|
|
@ -456,37 +513,40 @@ fn move_file_end(cx: &mut Context) {
|
|
|
|
fn extend_next_word_start(cx: &mut Context) {
|
|
|
|
fn extend_next_word_start(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|mut range| {
|
|
|
|
doc.selection(view.id).clone().transform(|mut range| {
|
|
|
|
let word = movement::move_next_word_start(text, range, count);
|
|
|
|
let word = movement::move_next_word_start(doc.text().slice(..), range, count);
|
|
|
|
let pos = word.head;
|
|
|
|
let pos = word.head;
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_prev_word_start(cx: &mut Context) {
|
|
|
|
fn extend_prev_word_start(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|mut range| {
|
|
|
|
doc.selection(view.id).clone().transform(|mut range| {
|
|
|
|
let word = movement::move_prev_word_start(text, range, count);
|
|
|
|
let word = movement::move_prev_word_start(doc.text().slice(..), range, count);
|
|
|
|
let pos = word.head;
|
|
|
|
let pos = word.head;
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_next_word_end(cx: &mut Context) {
|
|
|
|
fn extend_next_word_end(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|mut range| {
|
|
|
|
doc.selection(view.id).clone().transform(|mut range| {
|
|
|
|
let word = movement::move_next_word_end(text, range, count);
|
|
|
|
let word = movement::move_next_word_end(doc.text().slice(..), range, count);
|
|
|
|
let pos = word.head;
|
|
|
|
let pos = word.head;
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
@ -530,9 +590,12 @@ where
|
|
|
|
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|mut range| {
|
|
|
|
view.id,
|
|
|
|
search_fn(text, ch, range.head, count, inclusive).map_or(range, |pos| {
|
|
|
|
doc.selection(view.id).clone().transform(|mut range| {
|
|
|
|
|
|
|
|
search_fn(doc.text().slice(..), ch, range.head, count, inclusive).map_or(
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
|pos| {
|
|
|
|
if extend {
|
|
|
|
if extend {
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -540,8 +603,10 @@ where
|
|
|
|
Range::new(range.head, pos)
|
|
|
|
Range::new(range.head, pos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// or (pos, pos) to move to found val
|
|
|
|
// or (pos, pos) to move to found val
|
|
|
|
})
|
|
|
|
},
|
|
|
|
});
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -619,9 +684,10 @@ fn extend_prev_char(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_first_nonwhitespace(cx: &mut Context) {
|
|
|
|
fn extend_first_nonwhitespace(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| {
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = doc.text();
|
|
|
|
let line_idx = text.char_to_line(range.head);
|
|
|
|
let line_idx = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(pos) = find_first_non_whitespace_char(text.line(line_idx)) {
|
|
|
|
if let Some(pos) = find_first_non_whitespace_char(text.line(line_idx)) {
|
|
|
@ -630,7 +696,8 @@ fn extend_first_nonwhitespace(cx: &mut Context) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
range
|
|
|
|
range
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn replace(cx: &mut Context) {
|
|
|
|
fn replace(cx: &mut Context) {
|
|
|
@ -741,65 +808,101 @@ fn half_page_down(cx: &mut Context) {
|
|
|
|
fn extend_char_left(cx: &mut Context) {
|
|
|
|
fn extend_char_left(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_horizontally(text, range, Direction::Backward, count, Movement::Extend)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Extend,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_char_right(cx: &mut Context) {
|
|
|
|
fn extend_char_right(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_horizontally(text, range, Direction::Forward, count, Movement::Extend)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Extend,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_line_up(cx: &mut Context) {
|
|
|
|
fn extend_line_up(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_vertically(text, range, Direction::Backward, count, Movement::Extend)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Extend,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_line_down(cx: &mut Context) {
|
|
|
|
fn extend_line_down(cx: &mut Context) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
movement::move_vertically(text, range, Direction::Forward, count, Movement::Extend)
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
});
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
doc.text().slice(..),
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
Movement::Extend,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_line_end(cx: &mut Context) {
|
|
|
|
fn extend_line_end(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| {
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
let pos = line_end_char_index(&text.slice(..), line);
|
|
|
|
let pos = line_end_char_index(&text, line);
|
|
|
|
let pos = graphemes::nth_prev_grapheme_boundary(text.slice(..), pos, 1);
|
|
|
|
let pos = graphemes::nth_prev_grapheme_boundary(text, pos, 1);
|
|
|
|
let pos = range.head.max(pos).max(text.line_to_char(line));
|
|
|
|
let pos = range.head.max(pos).max(text.line_to_char(line));
|
|
|
|
|
|
|
|
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn extend_line_start(cx: &mut Context) {
|
|
|
|
fn extend_line_start(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.set_selection(
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
view.id,
|
|
|
|
selection.transform(|range| {
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = doc.text();
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
// adjust to start of the line
|
|
|
|
// adjust to start of the line
|
|
|
|
let pos = text.line_to_char(line);
|
|
|
|
let pos = text.line_to_char(line);
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn select_all(cx: &mut Context) {
|
|
|
|
fn select_all(cx: &mut Context) {
|
|
|
@ -993,15 +1096,23 @@ fn change_selection(cx: &mut Context) {
|
|
|
|
fn collapse_selection(cx: &mut Context) {
|
|
|
|
fn collapse_selection(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
doc.selection_mut(view.id)
|
|
|
|
doc.set_selection(
|
|
|
|
.transform(|range| Range::new(range.head, range.head));
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id)
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.transform(|range| Range::new(range.head, range.head)),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn flip_selections(cx: &mut Context) {
|
|
|
|
fn flip_selections(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
doc.selection_mut(view.id)
|
|
|
|
doc.set_selection(
|
|
|
|
.transform(|range| Range::new(range.head, range.anchor));
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id)
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.transform(|range| Range::new(range.head, range.anchor)),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn enter_insert_mode(doc: &mut Document) {
|
|
|
|
fn enter_insert_mode(doc: &mut Document) {
|
|
|
@ -1013,8 +1124,12 @@ fn insert_mode(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
|
|
|
|
doc.selection_mut(view.id)
|
|
|
|
doc.set_selection(
|
|
|
|
.transform(|range| Range::new(range.to(), range.from()));
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id)
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.transform(|range| Range::new(range.to(), range.from())),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// inserts at the end of each selection
|
|
|
|
// inserts at the end of each selection
|
|
|
@ -1023,15 +1138,14 @@ fn append_mode(cx: &mut Context) {
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
doc.restore_cursor = true;
|
|
|
|
doc.restore_cursor = true;
|
|
|
|
|
|
|
|
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
let selection = doc.selection(view.id).clone().transform(|range| {
|
|
|
|
selection.transform(|range| {
|
|
|
|
|
|
|
|
Range::new(
|
|
|
|
Range::new(
|
|
|
|
range.from(),
|
|
|
|
range.from(),
|
|
|
|
graphemes::next_grapheme_boundary(text, range.to()), // to() + next char
|
|
|
|
graphemes::next_grapheme_boundary(doc.text().slice(..), range.to()), // to() + next char
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let end = text.len_chars();
|
|
|
|
let end = doc.text().len_chars();
|
|
|
|
|
|
|
|
|
|
|
|
if selection.iter().any(|range| range.head == end) {
|
|
|
|
if selection.iter().any(|range| range.head == end) {
|
|
|
|
let transaction = Transaction::change(
|
|
|
|
let transaction = Transaction::change(
|
|
|
@ -1040,6 +1154,8 @@ fn append_mode(cx: &mut Context) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mod cmd {
|
|
|
|
mod cmd {
|
|
|
@ -1845,12 +1961,15 @@ fn append_to_line(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
let text = &doc.text().slice(..);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let pos = line_end_char_index(&text.slice(..), line);
|
|
|
|
let pos = line_end_char_index(text, line);
|
|
|
|
Range::new(pos, pos)
|
|
|
|
Range::new(pos, pos)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Sometimes when applying formatting changes we want to mark the buffer as unmodified, for
|
|
|
|
/// Sometimes when applying formatting changes we want to mark the buffer as unmodified, for
|
|
|
@ -1980,13 +2099,15 @@ fn normal_mode(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
// if leaving append mode, move cursor back by 1
|
|
|
|
// if leaving append mode, move cursor back by 1
|
|
|
|
if doc.restore_cursor {
|
|
|
|
if doc.restore_cursor {
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| {
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
Range::new(
|
|
|
|
Range::new(
|
|
|
|
range.from(),
|
|
|
|
range.from(),
|
|
|
|
graphemes::prev_grapheme_boundary(text, range.to()),
|
|
|
|
graphemes::prev_grapheme_boundary(doc.text().slice(..), range.to()),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
doc.restore_cursor = false;
|
|
|
|
doc.restore_cursor = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2619,8 +2740,12 @@ pub mod insert {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
let (text, selection) = doc.text_and_mut_selection(view.id);
|
|
|
|
doc.set_selection(
|
|
|
|
selection.transform(|range| movement::move_prev_word_start(text, range, count));
|
|
|
|
view.id,
|
|
|
|
|
|
|
|
doc.selection(view.id).clone().transform(|range| {
|
|
|
|
|
|
|
|
movement::move_prev_word_start(doc.text().slice(..), range, count)
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
delete_selection(cx)
|
|
|
|
delete_selection(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|