mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-28 21:20:23 +03:00
Introduce Selection::point.
This commit is contained in:
parent
55fa86248c
commit
f5981f72c2
@ -179,6 +179,11 @@ impl Selection {
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs a selection holding a single cursor.
|
||||
pub fn point(pos: usize) -> Self {
|
||||
Self::single(pos, pos)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
|
||||
fn normalize(mut ranges: SmallVec<[Range; 1]>, mut primary_index: usize) -> Selection {
|
||||
|
@ -93,7 +93,7 @@ pub fn move_next_word_start(view: &mut View, count: usize) {
|
||||
count,
|
||||
);
|
||||
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
|
||||
pub fn move_prev_word_start(view: &mut View, count: usize) {
|
||||
@ -104,7 +104,7 @@ pub fn move_prev_word_start(view: &mut View, count: usize) {
|
||||
count,
|
||||
);
|
||||
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
|
||||
pub fn move_next_word_end(view: &mut View, count: usize) {
|
||||
@ -114,11 +114,11 @@ pub fn move_next_word_end(view: &mut View, count: usize) {
|
||||
count,
|
||||
);
|
||||
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
|
||||
pub fn move_file_start(view: &mut View, _count: usize) {
|
||||
view.doc.set_selection(Selection::single(0, 0));
|
||||
view.doc.set_selection(Selection::point(0));
|
||||
|
||||
view.doc.mode = Mode::Normal;
|
||||
}
|
||||
@ -126,8 +126,7 @@ pub fn move_file_start(view: &mut View, _count: usize) {
|
||||
pub fn move_file_end(view: &mut View, _count: usize) {
|
||||
let text = &view.doc.text();
|
||||
let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
|
||||
view.doc
|
||||
.set_selection(Selection::single(last_line, last_line));
|
||||
view.doc.set_selection(Selection::point(last_line));
|
||||
|
||||
view.doc.mode = Mode::Normal;
|
||||
}
|
||||
@ -153,7 +152,7 @@ pub fn page_up(view: &mut View, _count: usize) {
|
||||
if !check_cursor_in_view(view) {
|
||||
let text = view.doc.text();
|
||||
let pos = text.line_to_char(view.last_line().saturating_sub(PADDING));
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +162,7 @@ pub fn page_down(view: &mut View, _count: usize) {
|
||||
if view.first_line < view.doc.text().len_lines() {
|
||||
let text = view.doc.text();
|
||||
let pos = text.line_to_char(view.first_line as usize);
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +176,7 @@ pub fn half_page_up(view: &mut View, _count: usize) {
|
||||
if !check_cursor_in_view(view) {
|
||||
let text = &view.doc.text();
|
||||
let pos = text.line_to_char(view.last_line() - PADDING);
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +188,7 @@ pub fn half_page_down(view: &mut View, _count: usize) {
|
||||
if !check_cursor_in_view(view) {
|
||||
let text = view.doc.text();
|
||||
let pos = text.line_to_char(view.first_line as usize);
|
||||
view.doc.set_selection(Selection::single(pos, pos));
|
||||
view.doc.set_selection(Selection::point(pos));
|
||||
}
|
||||
}
|
||||
// avoid select by default by having a visual mode switch that makes movements into selects
|
||||
|
Loading…
Reference in New Issue
Block a user