|
|
@ -1,11 +1,11 @@
|
|
|
|
use helix_core::{
|
|
|
|
use helix_core::{
|
|
|
|
comment, coords_at_pos, graphemes,
|
|
|
|
comment, coords_at_pos, graphemes,
|
|
|
|
indent::TAB_WIDTH,
|
|
|
|
indent::TAB_WIDTH,
|
|
|
|
movement, object, pos_at_coords,
|
|
|
|
movement::{self, Direction},
|
|
|
|
|
|
|
|
object, pos_at_coords,
|
|
|
|
regex::{self, Regex},
|
|
|
|
regex::{self, Regex},
|
|
|
|
register, search, selection,
|
|
|
|
register, search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection,
|
|
|
|
state::{Direction, Granularity},
|
|
|
|
Tendril, Transaction,
|
|
|
|
Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, Tendril, Transaction,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
@ -72,36 +72,64 @@ pub type Command = fn(cx: &mut Context);
|
|
|
|
pub fn move_char_left(cx: &mut Context) {
|
|
|
|
pub fn move_char_left(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.move_selection(Direction::Backward, Granularity::Character, count);
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
false, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn move_char_right(cx: &mut Context) {
|
|
|
|
pub fn move_char_right(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.move_selection(Direction::Forward, Granularity::Character, count);
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
false, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn move_line_up(cx: &mut Context) {
|
|
|
|
pub fn move_line_up(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.move_selection(Direction::Backward, Granularity::Line, count);
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
false, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn move_line_down(cx: &mut Context) {
|
|
|
|
pub fn move_line_down(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.move_selection(Direction::Forward, Granularity::Line, count);
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
false, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -409,36 +437,64 @@ pub fn half_page_down(cx: &mut Context) {
|
|
|
|
pub fn extend_char_left(cx: &mut Context) {
|
|
|
|
pub fn extend_char_left(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.extend_selection(Direction::Backward, Granularity::Character, count);
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
true, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn extend_char_right(cx: &mut Context) {
|
|
|
|
pub fn extend_char_right(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.extend_selection(Direction::Forward, Granularity::Character, count);
|
|
|
|
movement::move_horizontally(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
true, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn extend_line_up(cx: &mut Context) {
|
|
|
|
pub fn extend_line_up(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.extend_selection(Direction::Backward, Granularity::Line, count);
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Backward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
true, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn extend_line_down(cx: &mut Context) {
|
|
|
|
pub fn extend_line_down(cx: &mut Context) {
|
|
|
|
let count = cx.count;
|
|
|
|
let count = cx.count;
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let selection = doc
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
.state
|
|
|
|
let selection = doc.selection().transform(|range| {
|
|
|
|
.extend_selection(Direction::Forward, Granularity::Line, count);
|
|
|
|
movement::move_vertically(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
range,
|
|
|
|
|
|
|
|
Direction::Forward,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
true, /* extend */
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
doc.set_selection(selection);
|
|
|
|
doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|