mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
refactoring for home and end keys, better Modifiers abstraction
This commit is contained in:
parent
d153e580a1
commit
fe916f0d03
7 changed files with 611 additions and 536 deletions
|
@ -408,20 +408,20 @@ fn begin_render_pass<'a>(
|
|||
|
||||
fn queue_editor_text(
|
||||
size: &PhysicalSize<u32>,
|
||||
_editor_lines: &str,
|
||||
editor_lines: &str,
|
||||
caret_pos: TextPos,
|
||||
config: &Config,
|
||||
glyph_brush: &mut GlyphBrush<()>,
|
||||
) {
|
||||
let area_bounds = (size.width as f32, size.height as f32).into();
|
||||
|
||||
// let code_text = Text {
|
||||
// position: CODE_TXT_XY.into(),
|
||||
// area_bounds,
|
||||
// text: editor_lines,
|
||||
// size: settings.code_font_size,
|
||||
// ..Default::default()
|
||||
// };
|
||||
let code_text = Text {
|
||||
position: CODE_TXT_XY.into(),
|
||||
area_bounds,
|
||||
text: editor_lines,
|
||||
size: config.code_font_size,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let s = format!("Ln {}, Col {}", caret_pos.line, caret_pos.column);
|
||||
let text = s.as_str();
|
||||
|
@ -438,7 +438,7 @@ fn queue_editor_text(
|
|||
queue_text_draw(&caret_pos_label, glyph_brush);
|
||||
|
||||
// TODO convert to ast and render with render_ast::render_expr2
|
||||
//queue_code_text_draw(&code_text, &ed_theme.syntax_high_map, settings, glyph_brush);
|
||||
queue_text_draw(&code_text, glyph_brush);
|
||||
}
|
||||
|
||||
fn _queue_no_file_text(
|
||||
|
|
|
@ -12,6 +12,7 @@ mod editor;
|
|||
mod graphics;
|
||||
pub mod lang; //TODO remove pub for unused warnings
|
||||
mod ui;
|
||||
mod window;
|
||||
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,7 @@ use super::selection::validate_selection;
|
|||
use super::selection::Selection;
|
||||
use super::text_pos::TextPos;
|
||||
use crate::ui::ui_error::UIResult;
|
||||
use winit::event::ModifiersState;
|
||||
use crate::window::keyboard_input::Modifiers;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CaretWSelect {
|
||||
|
@ -31,12 +31,12 @@ impl CaretWSelect {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn move_caret_w_mods(&mut self, new_pos: TextPos, mods: &ModifiersState) -> UIResult<()> {
|
||||
pub fn move_caret_w_mods(&mut self, new_pos: TextPos, mods: &Modifiers) -> UIResult<()> {
|
||||
let caret_pos = self.caret_pos;
|
||||
|
||||
// one does not simply move the caret
|
||||
let valid_sel_opt = if new_pos != caret_pos {
|
||||
if mods.shift() {
|
||||
if mods.shift {
|
||||
if let Some(old_sel) = self.selection_opt {
|
||||
if new_pos < old_sel.start_pos {
|
||||
if caret_pos > old_sel.start_pos {
|
||||
|
@ -55,7 +55,6 @@ impl CaretWSelect {
|
|||
} else if new_pos < caret_pos {
|
||||
mk_some_sel(old_sel.start_pos, new_pos)?
|
||||
} else {
|
||||
// TODO should this return none?
|
||||
None
|
||||
}
|
||||
} else if new_pos < self.caret_pos {
|
||||
|
|
|
@ -5,9 +5,10 @@ use crate::ui::text::{
|
|||
text_pos::TextPos,
|
||||
};
|
||||
use crate::ui::ui_error::UIResult;
|
||||
use crate::window::keyboard_input::Modifiers;
|
||||
use bumpalo::collections::String as BumpString;
|
||||
use bumpalo::Bump;
|
||||
use winit::event::{ModifiersState, VirtualKeyCode};
|
||||
use winit::event::{VirtualKeyCode};
|
||||
|
||||
pub trait Lines {
|
||||
fn get_line(&self, line_nr: usize) -> UIResult<&str>;
|
||||
|
@ -27,13 +28,17 @@ pub trait SelectableLines {
|
|||
|
||||
fn set_caret(&mut self, caret_pos: TextPos);
|
||||
|
||||
fn move_caret_left(&mut self, shift_pressed: bool) -> UIResult<()>;
|
||||
fn move_caret_left(&mut self, modifiers: &Modifiers) -> UIResult<()>;
|
||||
|
||||
fn move_caret_right(&mut self, shift_pressed: bool) -> UIResult<()>;
|
||||
fn move_caret_right(&mut self, modifiers: &Modifiers) -> UIResult<()>;
|
||||
|
||||
fn move_caret_up(&mut self, shift_pressed: bool) -> UIResult<()>;
|
||||
fn move_caret_up(&mut self, modifiers: &Modifiers) -> UIResult<()>;
|
||||
|
||||
fn move_caret_down(&mut self, shift_pressed: bool) -> UIResult<()>;
|
||||
fn move_caret_down(&mut self, modifiers: &Modifiers) -> UIResult<()>;
|
||||
|
||||
fn move_caret_home(&mut self, modifiers: &Modifiers) -> UIResult<()>;
|
||||
|
||||
fn move_caret_end(&mut self, modifiers: &Modifiers) -> UIResult<()>;
|
||||
|
||||
fn get_selection(&self) -> Option<Selection>;
|
||||
|
||||
|
@ -48,6 +53,12 @@ pub trait SelectableLines {
|
|||
fn select_all(&mut self) -> UIResult<()>;
|
||||
|
||||
fn last_text_pos(&self) -> TextPos;
|
||||
|
||||
fn handle_key_down(
|
||||
&mut self,
|
||||
modifiers: &Modifiers,
|
||||
virtual_keycode: VirtualKeyCode,
|
||||
) -> UIResult<()>;
|
||||
}
|
||||
|
||||
pub trait MutSelectableLines {
|
||||
|
@ -61,10 +72,4 @@ pub trait MutSelectableLines {
|
|||
fn pop_char(&mut self) -> UIResult<()>;
|
||||
|
||||
fn del_selection(&mut self) -> UIResult<()>;
|
||||
|
||||
fn handle_key_down(
|
||||
&mut self,
|
||||
modifiers: &ModifiersState,
|
||||
virtual_keycode: VirtualKeyCode,
|
||||
) -> UIResult<()>;
|
||||
}
|
||||
|
|
44
editor/src/window/keyboard_input.rs
Normal file
44
editor/src/window/keyboard_input.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
|
||||
pub struct Modifiers {
|
||||
pub shift: bool,
|
||||
pub ctrl: bool,
|
||||
pub alt: bool,
|
||||
pub logo: bool,
|
||||
}
|
||||
|
||||
impl Default for Modifiers {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
logo: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn no_mods() -> Modifiers {
|
||||
Modifiers {
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
logo: false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_winit(winit_mods: &winit::event::ModifiersState) -> Modifiers {
|
||||
Modifiers {
|
||||
shift: winit_mods.shift(),
|
||||
ctrl: winit_mods.ctrl(),
|
||||
alt: winit_mods.alt(),
|
||||
logo: winit_mods.logo(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shift_pressed() -> Modifiers {
|
||||
Modifiers {
|
||||
shift: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
1
editor/src/window/mod.rs
Normal file
1
editor/src/window/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod keyboard_input;
|
Loading…
Add table
Add a link
Reference in a new issue