Shift Arrow Selection
Fixed issues where shift + arrow keys would not select text. This creates an issue with cursor movements after using shift + arrow keys. Further cursor movements retain the selection mode and allow selecting. Cursor movements should clear the active selection. However, this would invalidate the ability for selecting via marking selection (v). Selection marking will be refactored, which will fix this inconsistency.
This commit is contained in:
parent
3c3d43034f
commit
e239573903
|
@ -201,15 +201,8 @@ impl EditorData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_up(&mut self) {
|
pub fn select_up(&mut self) {
|
||||||
let line_idx = self.content.char_to_line(self.cursor_pos);
|
self.start_selection();
|
||||||
|
self.cursor_up();
|
||||||
if line_idx > 0 {
|
|
||||||
let start_of_current_line = self.content.line_to_char(line_idx);
|
|
||||||
let line_pos = self.cursor_pos - start_of_current_line;
|
|
||||||
let up_line_start = self.content.line_to_char(line_idx - 1);
|
|
||||||
let up_line = self.content.line(line_idx - 1);
|
|
||||||
self.cursor_pos = up_line_start + line_pos.min(up_line.len_chars() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_down(&mut self) {
|
pub fn cursor_down(&mut self) {
|
||||||
|
@ -225,17 +218,8 @@ impl EditorData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_down(&mut self) {
|
pub fn select_down(&mut self) {
|
||||||
//12 -> 11
|
self.start_selection();
|
||||||
let line_idx = self.content.char_to_line(self.cursor_pos);
|
self.cursor_down();
|
||||||
if line_idx < self.content.len_lines() - 1 {
|
|
||||||
let start_of_current_line = self.content.line_to_char(line_idx);
|
|
||||||
let line_pos = self.cursor_pos - start_of_current_line;
|
|
||||||
let start_of_next_line = self.content.line_to_char(line_idx + 1) + 1;
|
|
||||||
let next_line_len = self.content.line(line_idx + 1).len_chars();
|
|
||||||
|
|
||||||
self.cursor_pos =
|
|
||||||
(start_of_next_line + line_pos.min(next_line_len)).min(start_of_next_line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_right(&mut self) {
|
pub fn cursor_right(&mut self) {
|
||||||
|
@ -287,15 +271,13 @@ impl EditorData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_left(&mut self) {
|
pub fn select_left(&mut self) {
|
||||||
if self.cursor_pos > 0 {
|
self.start_selection();
|
||||||
self.cursor_pos -= 1
|
self.cursor_left();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_right(&mut self) {
|
pub fn select_right(&mut self) {
|
||||||
if self.cursor_pos < self.content.len_chars() {
|
self.start_selection();
|
||||||
self.cursor_pos += 1;
|
self.cursor_right();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_line(&self) -> ropey::RopeSlice {
|
pub fn current_line(&self) -> ropey::RopeSlice {
|
||||||
|
@ -310,6 +292,12 @@ impl EditorData {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn start_selection(&mut self) {
|
||||||
|
if self.selection_pos.is_none() {
|
||||||
|
self.selection_pos = Some(self.cursor_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn current_line_index(&self) -> usize {
|
pub fn current_line_index(&self) -> usize {
|
||||||
self.content.char_to_line(self.cursor_pos)
|
self.content.char_to_line(self.cursor_pos)
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,7 +414,6 @@ impl Widget<EditorData> for AbacusEditor {
|
||||||
|
|
||||||
druid::keyboard_types::Key::ArrowUp if e.mods.shift() => {
|
druid::keyboard_types::Key::ArrowUp if e.mods.shift() => {
|
||||||
data.select_up();
|
data.select_up();
|
||||||
data.deselect();
|
|
||||||
}
|
}
|
||||||
druid::keyboard_types::Key::ArrowDown if e.mods.shift() => {
|
druid::keyboard_types::Key::ArrowDown if e.mods.shift() => {
|
||||||
data.select_down();
|
data.select_down();
|
||||||
|
|
Loading…
Reference in New Issue