mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
renamed txt_cursor to caret
This commit is contained in:
parent
dcee932495
commit
fb66312a69
4 changed files with 56 additions and 56 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::tea::model::Model;
|
use crate::tea::model::Model;
|
||||||
use crate::tea::update::{
|
use crate::tea::update::{
|
||||||
move_txt_cursor_down, move_txt_cursor_left, move_txt_cursor_right, move_txt_cursor_up,
|
move_caret_down, move_caret_left, move_caret_right, move_caret_up,
|
||||||
};
|
};
|
||||||
use winit::event::{ElementState, ModifiersState, VirtualKeyCode};
|
use winit::event::{ElementState, ModifiersState, VirtualKeyCode};
|
||||||
|
|
||||||
|
@ -18,43 +18,43 @@ pub fn handle_keydown(
|
||||||
|
|
||||||
match virtual_keycode {
|
match virtual_keycode {
|
||||||
Left => {
|
Left => {
|
||||||
let (new_txt_cursor_pos, new_selection_opt) = move_txt_cursor_left(
|
let (new_caret_pos, new_selection_opt) = move_caret_left(
|
||||||
model.txt_cursor_pos,
|
model.caret_pos,
|
||||||
model.selection_opt,
|
model.selection_opt,
|
||||||
modifiers.shift(),
|
modifiers.shift(),
|
||||||
&model.lines,
|
&model.lines,
|
||||||
);
|
);
|
||||||
model.txt_cursor_pos = new_txt_cursor_pos;
|
model.caret_pos = new_caret_pos;
|
||||||
model.selection_opt = new_selection_opt;
|
model.selection_opt = new_selection_opt;
|
||||||
}
|
}
|
||||||
Up => {
|
Up => {
|
||||||
let (new_txt_cursor_pos, new_selection_opt) = move_txt_cursor_up(
|
let (new_caret_pos, new_selection_opt) = move_caret_up(
|
||||||
model.txt_cursor_pos,
|
model.caret_pos,
|
||||||
model.selection_opt,
|
model.selection_opt,
|
||||||
modifiers.shift(),
|
modifiers.shift(),
|
||||||
&model.lines,
|
&model.lines,
|
||||||
);
|
);
|
||||||
model.txt_cursor_pos = new_txt_cursor_pos;
|
model.caret_pos = new_caret_pos;
|
||||||
model.selection_opt = new_selection_opt;
|
model.selection_opt = new_selection_opt;
|
||||||
}
|
}
|
||||||
Right => {
|
Right => {
|
||||||
let (new_txt_cursor_pos, new_selection_opt) = move_txt_cursor_right(
|
let (new_caret_pos, new_selection_opt) = move_caret_right(
|
||||||
model.txt_cursor_pos,
|
model.caret_pos,
|
||||||
model.selection_opt,
|
model.selection_opt,
|
||||||
modifiers.shift(),
|
modifiers.shift(),
|
||||||
&model.lines,
|
&model.lines,
|
||||||
);
|
);
|
||||||
model.txt_cursor_pos = new_txt_cursor_pos;
|
model.caret_pos = new_caret_pos;
|
||||||
model.selection_opt = new_selection_opt;
|
model.selection_opt = new_selection_opt;
|
||||||
}
|
}
|
||||||
Down => {
|
Down => {
|
||||||
let (new_txt_cursor_pos, new_selection_opt) = move_txt_cursor_down(
|
let (new_caret_pos, new_selection_opt) = move_caret_down(
|
||||||
model.txt_cursor_pos,
|
model.caret_pos,
|
||||||
model.selection_opt,
|
model.selection_opt,
|
||||||
modifiers.shift(),
|
modifiers.shift(),
|
||||||
&model.lines,
|
&model.lines,
|
||||||
);
|
);
|
||||||
model.txt_cursor_pos = new_txt_cursor_pos;
|
model.caret_pos = new_caret_pos;
|
||||||
model.selection_opt = new_selection_opt;
|
model.selection_opt = new_selection_opt;
|
||||||
}
|
}
|
||||||
Copy => {
|
Copy => {
|
||||||
|
@ -122,7 +122,7 @@ pub fn handle_keydown(
|
||||||
// Escape | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | F13 | F14 | F15
|
// Escape | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | F13 | F14 | F15
|
||||||
// | F16 | F17 | F18 | F19 | F20 | F21 | F22 | F23 | F24 | Snapshot | Scroll | Pause
|
// | F16 | F17 | F18 | F19 | F20 | F21 | F22 | F23 | F24 | Snapshot | Scroll | Pause
|
||||||
// | Insert | Home | Delete | End | PageDown | PageUp | Left | Up | Right | Down | Compose
|
// | Insert | Home | Delete | End | PageDown | PageUp | Left | Up | Right | Down | Compose
|
||||||
// | txt_cursor | Numlock | AbntC1 | AbntC2 | Ax | Calculator | Capital | Convert | Kana
|
// | caret | Numlock | AbntC1 | AbntC2 | Ax | Calculator | Capital | Convert | Kana
|
||||||
// | Kanji | LAlt | LBracket | LControl | LShift | LWin | Mail | MediaSelect | PlayPause
|
// | Kanji | LAlt | LBracket | LControl | LShift | LWin | Mail | MediaSelect | PlayPause
|
||||||
// | Power | PrevTrack | MediaStop | Mute | MyComputer | NavigateForward
|
// | Power | PrevTrack | MediaStop | Mute | MyComputer | NavigateForward
|
||||||
// | NavigateBackward | NextTrack | NoConvert | OEM102 | RAlt | Sysrq | RBracket
|
// | NavigateBackward | NextTrack | NoConvert | OEM102 | RAlt | Sysrq | RBracket
|
||||||
|
|
|
@ -214,7 +214,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
||||||
let glyph_bounds_rects = queue_all_text(
|
let glyph_bounds_rects = queue_all_text(
|
||||||
&size,
|
&size,
|
||||||
&ed_model.lines,
|
&ed_model.lines,
|
||||||
ed_model.txt_cursor_pos,
|
ed_model.caret_pos,
|
||||||
&mut glyph_brush,
|
&mut glyph_brush,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ fn create_render_pipeline(
|
||||||
fn queue_all_text(
|
fn queue_all_text(
|
||||||
size: &winit::dpi::PhysicalSize<u32>,
|
size: &winit::dpi::PhysicalSize<u32>,
|
||||||
lines: &[String],
|
lines: &[String],
|
||||||
txt_cursor_pos: Position,
|
caret_pos: Position,
|
||||||
glyph_brush: &mut wgpu_glyph::GlyphBrush<()>,
|
glyph_brush: &mut wgpu_glyph::GlyphBrush<()>,
|
||||||
) -> Vec<Vec<Rect>> {
|
) -> Vec<Vec<Rect>> {
|
||||||
let area_bounds = (size.width as f32, size.height as f32).into();
|
let area_bounds = (size.width as f32, size.height as f32).into();
|
||||||
|
@ -394,18 +394,18 @@ fn queue_all_text(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let txt_cursor_pos_label = Text {
|
let caret_pos_label = Text {
|
||||||
position: (30.0, 530.0).into(),
|
position: (30.0, 530.0).into(),
|
||||||
area_bounds,
|
area_bounds,
|
||||||
color: (0.4666, 0.2, 1.0, 1.0).into(),
|
color: (0.4666, 0.2, 1.0, 1.0).into(),
|
||||||
text: format!("Ln {}, Col {}", txt_cursor_pos.line, txt_cursor_pos.column),
|
text: format!("Ln {}, Col {}", caret_pos.line, caret_pos.column),
|
||||||
size: 30.0,
|
size: 30.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
text::queue_text_draw(&main_label, glyph_brush);
|
text::queue_text_draw(&main_label, glyph_brush);
|
||||||
|
|
||||||
text::queue_text_draw(&txt_cursor_pos_label, glyph_brush);
|
text::queue_text_draw(&caret_pos_label, glyph_brush);
|
||||||
|
|
||||||
text::queue_text_draw(&code_text, glyph_brush)
|
text::queue_text_draw(&code_text, glyph_brush)
|
||||||
}
|
}
|
||||||
|
@ -423,8 +423,8 @@ fn update_text_state(ed_model: &mut model::Model, received_char: &char) {
|
||||||
} else if ed_model.lines.len() > 1 {
|
} else if ed_model.lines.len() > 1 {
|
||||||
ed_model.lines.pop();
|
ed_model.lines.pop();
|
||||||
}
|
}
|
||||||
ed_model.txt_cursor_pos = update::move_txt_cursor_left(
|
ed_model.caret_pos = update::move_caret_left(
|
||||||
ed_model.txt_cursor_pos,
|
ed_model.caret_pos,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
&ed_model.lines,
|
&ed_model.lines,
|
||||||
|
@ -441,8 +441,8 @@ fn update_text_state(ed_model: &mut model::Model, received_char: &char) {
|
||||||
last_line.push(*received_char)
|
last_line.push(*received_char)
|
||||||
}
|
}
|
||||||
ed_model.lines.push(String::new());
|
ed_model.lines.push(String::new());
|
||||||
ed_model.txt_cursor_pos = Position {
|
ed_model.caret_pos = Position {
|
||||||
line: ed_model.txt_cursor_pos.line + 1,
|
line: ed_model.caret_pos.line + 1,
|
||||||
column: 0,
|
column: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -454,7 +454,7 @@ fn update_text_state(ed_model: &mut model::Model, received_char: &char) {
|
||||||
if let Some(last_line) = ed_model.lines.last_mut() {
|
if let Some(last_line) = ed_model.lines.last_mut() {
|
||||||
last_line.push(*received_char);
|
last_line.push(*received_char);
|
||||||
|
|
||||||
ed_model.txt_cursor_pos = Position {
|
ed_model.caret_pos = Position {
|
||||||
line: nr_lines - 1,
|
line: nr_lines - 1,
|
||||||
column: last_line.len(),
|
column: last_line.len(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,14 +3,14 @@ use std::cmp::Ordering;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
pub lines: Vec<String>,
|
pub lines: Vec<String>,
|
||||||
pub txt_cursor_pos: Position,
|
pub caret_pos: Position,
|
||||||
pub selection_opt: Option<RawSelection>,
|
pub selection_opt: Option<RawSelection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_model() -> Model {
|
pub fn init_model() -> Model {
|
||||||
Model {
|
Model {
|
||||||
lines: vec![String::new()],
|
lines: vec![String::new()],
|
||||||
txt_cursor_pos: Position { line: 0, column: 0 },
|
caret_pos: Position { line: 0, column: 0 },
|
||||||
selection_opt: None,
|
selection_opt: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,14 @@ use crate::tea::model::{Position, RawSelection};
|
||||||
use crate::text::is_newline;
|
use crate::text::is_newline;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
pub fn move_txt_cursor_left(
|
pub fn move_caret_left(
|
||||||
old_txt_cursor_pos: Position,
|
old_caret_pos: Position,
|
||||||
old_selection_opt: Option<RawSelection>,
|
old_selection_opt: Option<RawSelection>,
|
||||||
shift_pressed: bool,
|
shift_pressed: bool,
|
||||||
lines: &[String],
|
lines: &[String],
|
||||||
) -> (Position, Option<RawSelection>) {
|
) -> (Position, Option<RawSelection>) {
|
||||||
let old_line_nr = old_txt_cursor_pos.line;
|
let old_line_nr = old_caret_pos.line;
|
||||||
let old_col_nr = old_txt_cursor_pos.column;
|
let old_col_nr = old_caret_pos.column;
|
||||||
|
|
||||||
let (line_nr, col_nr) = if old_col_nr == 0 {
|
let (line_nr, col_nr) = if old_col_nr == 0 {
|
||||||
if old_line_nr == 0 {
|
if old_line_nr == 0 {
|
||||||
|
@ -23,7 +23,7 @@ pub fn move_txt_cursor_left(
|
||||||
(old_line_nr, old_col_nr - 1)
|
(old_line_nr, old_col_nr - 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_txt_cursor_pos = Position {
|
let new_caret_pos = Position {
|
||||||
line: line_nr,
|
line: line_nr,
|
||||||
column: col_nr,
|
column: col_nr,
|
||||||
};
|
};
|
||||||
|
@ -55,17 +55,17 @@ pub fn move_txt_cursor_left(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
(new_txt_cursor_pos, new_selection_opt)
|
(new_caret_pos, new_selection_opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_txt_cursor_right(
|
pub fn move_caret_right(
|
||||||
old_txt_cursor_pos: Position,
|
old_caret_pos: Position,
|
||||||
old_selection_opt: Option<RawSelection>,
|
old_selection_opt: Option<RawSelection>,
|
||||||
shift_pressed: bool,
|
shift_pressed: bool,
|
||||||
lines: &[String],
|
lines: &[String],
|
||||||
) -> (Position, Option<RawSelection>) {
|
) -> (Position, Option<RawSelection>) {
|
||||||
let old_line_nr = old_txt_cursor_pos.line;
|
let old_line_nr = old_caret_pos.line;
|
||||||
let old_col_nr = old_txt_cursor_pos.column;
|
let old_col_nr = old_caret_pos.column;
|
||||||
|
|
||||||
let (line_nr, col_nr) = if let Some(curr_line) = lines.get(old_line_nr) {
|
let (line_nr, col_nr) = if let Some(curr_line) = lines.get(old_line_nr) {
|
||||||
if let Some(last_char) = curr_line.chars().last() {
|
if let Some(last_char) = curr_line.chars().last() {
|
||||||
|
@ -87,7 +87,7 @@ pub fn move_txt_cursor_right(
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_txt_cursor_pos = Position {
|
let new_caret_pos = Position {
|
||||||
line: line_nr,
|
line: line_nr,
|
||||||
column: col_nr,
|
column: col_nr,
|
||||||
};
|
};
|
||||||
|
@ -119,17 +119,17 @@ pub fn move_txt_cursor_right(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
(new_txt_cursor_pos, new_selection_opt)
|
(new_caret_pos, new_selection_opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_txt_cursor_up(
|
pub fn move_caret_up(
|
||||||
old_txt_cursor_pos: Position,
|
old_caret_pos: Position,
|
||||||
old_selection_opt: Option<RawSelection>,
|
old_selection_opt: Option<RawSelection>,
|
||||||
shift_pressed: bool,
|
shift_pressed: bool,
|
||||||
lines: &[String],
|
lines: &[String],
|
||||||
) -> (Position, Option<RawSelection>) {
|
) -> (Position, Option<RawSelection>) {
|
||||||
let old_line_nr = old_txt_cursor_pos.line;
|
let old_line_nr = old_caret_pos.line;
|
||||||
let old_col_nr = old_txt_cursor_pos.column;
|
let old_col_nr = old_caret_pos.column;
|
||||||
|
|
||||||
let (line_nr, col_nr) = if old_line_nr == 0 {
|
let (line_nr, col_nr) = if old_line_nr == 0 {
|
||||||
(old_line_nr, old_col_nr)
|
(old_line_nr, old_col_nr)
|
||||||
|
@ -143,7 +143,7 @@ pub fn move_txt_cursor_up(
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_txt_cursor_pos = Position {
|
let new_caret_pos = Position {
|
||||||
line: line_nr,
|
line: line_nr,
|
||||||
column: col_nr,
|
column: col_nr,
|
||||||
};
|
};
|
||||||
|
@ -151,13 +151,13 @@ pub fn move_txt_cursor_up(
|
||||||
let new_selection_opt = if shift_pressed {
|
let new_selection_opt = if shift_pressed {
|
||||||
if let Some(old_selection) = old_selection_opt {
|
if let Some(old_selection) = old_selection_opt {
|
||||||
Some(RawSelection {
|
Some(RawSelection {
|
||||||
start_pos: new_txt_cursor_pos,
|
start_pos: new_caret_pos,
|
||||||
end_pos: old_selection.end_pos,
|
end_pos: old_selection.end_pos,
|
||||||
})
|
})
|
||||||
} else if !(old_line_nr == line_nr && old_col_nr == col_nr) {
|
} else if !(old_line_nr == line_nr && old_col_nr == col_nr) {
|
||||||
Some(RawSelection {
|
Some(RawSelection {
|
||||||
start_pos: min(old_txt_cursor_pos, new_txt_cursor_pos),
|
start_pos: min(old_caret_pos, new_caret_pos),
|
||||||
end_pos: max(old_txt_cursor_pos, new_txt_cursor_pos),
|
end_pos: max(old_caret_pos, new_caret_pos),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -166,17 +166,17 @@ pub fn move_txt_cursor_up(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
(new_txt_cursor_pos, new_selection_opt)
|
(new_caret_pos, new_selection_opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_txt_cursor_down(
|
pub fn move_caret_down(
|
||||||
old_txt_cursor_pos: Position,
|
old_caret_pos: Position,
|
||||||
old_selection_opt: Option<RawSelection>,
|
old_selection_opt: Option<RawSelection>,
|
||||||
shift_pressed: bool,
|
shift_pressed: bool,
|
||||||
lines: &[String],
|
lines: &[String],
|
||||||
) -> (Position, Option<RawSelection>) {
|
) -> (Position, Option<RawSelection>) {
|
||||||
let old_line_nr = old_txt_cursor_pos.line;
|
let old_line_nr = old_caret_pos.line;
|
||||||
let old_col_nr = old_txt_cursor_pos.column;
|
let old_col_nr = old_caret_pos.column;
|
||||||
|
|
||||||
let (line_nr, col_nr) = if old_line_nr + 1 >= lines.len() {
|
let (line_nr, col_nr) = if old_line_nr + 1 >= lines.len() {
|
||||||
(old_line_nr, old_col_nr)
|
(old_line_nr, old_col_nr)
|
||||||
|
@ -198,7 +198,7 @@ pub fn move_txt_cursor_down(
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_txt_cursor_pos = Position {
|
let new_caret_pos = Position {
|
||||||
line: line_nr,
|
line: line_nr,
|
||||||
column: col_nr,
|
column: col_nr,
|
||||||
};
|
};
|
||||||
|
@ -207,12 +207,12 @@ pub fn move_txt_cursor_down(
|
||||||
if let Some(old_selection) = old_selection_opt {
|
if let Some(old_selection) = old_selection_opt {
|
||||||
Some(RawSelection {
|
Some(RawSelection {
|
||||||
start_pos: old_selection.start_pos,
|
start_pos: old_selection.start_pos,
|
||||||
end_pos: new_txt_cursor_pos,
|
end_pos: new_caret_pos,
|
||||||
})
|
})
|
||||||
} else if !(old_line_nr == line_nr && old_col_nr == col_nr) {
|
} else if !(old_line_nr == line_nr && old_col_nr == col_nr) {
|
||||||
Some(RawSelection {
|
Some(RawSelection {
|
||||||
start_pos: min(old_txt_cursor_pos, new_txt_cursor_pos),
|
start_pos: min(old_caret_pos, new_caret_pos),
|
||||||
end_pos: max(old_txt_cursor_pos, new_txt_cursor_pos),
|
end_pos: max(old_caret_pos, new_caret_pos),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -221,5 +221,5 @@ pub fn move_txt_cursor_down(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
(new_txt_cursor_pos, new_selection_opt)
|
(new_caret_pos, new_selection_opt)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue