mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
put more things in the model
This commit is contained in:
parent
0556e61ca2
commit
103cccd61b
7 changed files with 81 additions and 60 deletions
|
@ -15,5 +15,5 @@ If you encounter an error like `gfx_backend_vulkan ... Failed to detect any vali
|
|||
We thank the following open source projects in particular for inspiring us when designing the Roc editor:
|
||||
- [learn-wgpu](https://github.com/sotrh/learn-wgpu)
|
||||
- [rgx](https://github.com/cloudhead/rgx)
|
||||
- [Elm](https://github.com/elm/compiler)
|
||||
- [elm-editor](https://github.com/jxxcarlson/elm-editor)
|
||||
- [iced](https://github.com/hecrj/iced)
|
|
@ -51,9 +51,15 @@ These are potentially inspirational resources for the editor's design.
|
|||
* [Blueprints](https://docs.unrealengine.com/en-US/Engine/Blueprints/index.html) visual scripting (not suggesting visual scripting for Roc)
|
||||
|
||||
* [Live Programing](https://www.microsoft.com/en-us/research/project/live-programming/?from=http%3A%2F%2Fresearch.microsoft.com%2Fen-us%2Fprojects%2Fliveprogramming%2Ftypography.aspx#!publications) by [Microsoft Research] it contains many interesting research papers.
|
||||
|
||||
### Productivity features
|
||||
|
||||
* When refactoring;
|
||||
- cutting and pasting code to a new file should automatically add imports to the new file and delete them from the old file.
|
||||
- When renaming a function for example, references in comments should be brought to the user's attention.
|
||||
* Automatically create all "arms" when pattern matching after entering `when var is` based on the type.
|
||||
- All `when ... is` should be updated if the type is changed, e.g. adding Indigo to the Color type should add an arm everywhere where `when color is` is used.
|
||||
|
||||
|
||||
### Non-Code Related Inspiration
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::rect::{Rect};
|
|||
use crate::error::{print_err};
|
||||
use crate::ortho::{init_ortho, update_ortho_buffer, OrthoResources};
|
||||
use crate::selection::{create_selection_rects};
|
||||
use crate::model::{RawSelection, Position};
|
||||
use crate::tea::model;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
@ -42,7 +42,7 @@ mod colors;
|
|||
pub mod error;
|
||||
mod vec_result;
|
||||
mod selection;
|
||||
mod model;
|
||||
mod tea;
|
||||
|
||||
/// The editor is actually launched from the CLI if you pass it zero arguments,
|
||||
/// or if you provide it 1 or more files or directories to open on launch.
|
||||
|
@ -116,7 +116,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
let mut glyph_brush = build_glyph_brush(&gpu_device, render_format)?;
|
||||
|
||||
let is_animating = true;
|
||||
let mut text_state = "aaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeee\nffffffff\ngggggggg".to_owned();//String::new();
|
||||
let mut ed_model = model::init_model();
|
||||
let mut keyboard_modifiers = ModifiersState::empty();
|
||||
|
||||
// Render loop
|
||||
|
@ -169,7 +169,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
event: event::WindowEvent::ReceivedCharacter(ch),
|
||||
..
|
||||
} => {
|
||||
update_text_state(&mut text_state, &ch);
|
||||
update_text_state(&mut ed_model, &ch);
|
||||
}
|
||||
//Keyboard Input
|
||||
Event::WindowEvent {
|
||||
|
@ -206,15 +206,11 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let glyph_bounds_rects = queue_all_text(
|
||||
&size,
|
||||
&text_state,
|
||||
&ed_model.file_text,
|
||||
&mut glyph_brush,
|
||||
);
|
||||
|
||||
let selection =
|
||||
RawSelection {
|
||||
start_pos: Position {line: 1, column: 3},
|
||||
end_pos: Position {line: 4, column: 2}
|
||||
};
|
||||
if let Some(selection) = ed_model.selection_opt {
|
||||
let selection_rects_res = create_selection_rects(selection, &glyph_bounds_rects);
|
||||
|
||||
match selection_rects_res {
|
||||
|
@ -245,6 +241,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
},
|
||||
Err(e) => print_err(&e) //TODO draw error text on screen
|
||||
}
|
||||
}
|
||||
|
||||
// draw all text
|
||||
glyph_brush
|
||||
|
@ -373,19 +370,19 @@ fn queue_all_text(
|
|||
text::queue_text_draw(&code_text, glyph_brush)
|
||||
}
|
||||
|
||||
fn update_text_state(text_state: &mut String, received_char: &char) {
|
||||
fn update_text_state(ed_model: &mut model::Model, received_char: &char) {
|
||||
match received_char {
|
||||
'\u{8}' | '\u{7f}' => {
|
||||
// In Linux, we get a '\u{8}' when you press backspace,
|
||||
// but in macOS we get '\u{7f}'.
|
||||
text_state.pop();
|
||||
ed_model.file_text.pop();
|
||||
}
|
||||
'\u{e000}'..='\u{f8ff}' | '\u{f0000}'..='\u{ffffd}' | '\u{100000}'..='\u{10fffd}' => {
|
||||
// These are private use characters; ignore them.
|
||||
// See http://www.unicode.org/faq/private_use.html
|
||||
}
|
||||
_ => {
|
||||
text_state.push(*received_char);
|
||||
ed_model.file_text.push(*received_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
pub struct Model {
|
||||
caret_pos: Position,
|
||||
selection: RawSelection
|
||||
}
|
||||
|
||||
//Is model.rs the right place for these structs?
|
||||
pub struct Position {
|
||||
pub line: usize,
|
||||
pub column: usize
|
||||
}
|
||||
|
||||
pub struct RawSelection {
|
||||
pub start_pos: Position,
|
||||
pub end_pos: Position
|
||||
}
|
|
@ -3,7 +3,7 @@ use crate::rect::{Rect};
|
|||
use crate::vec_result::{get_res};
|
||||
use crate::error::{EdResult, InvalidSelection};
|
||||
use crate::colors;
|
||||
use crate::model::{RawSelection};
|
||||
use crate::tea::model::{RawSelection};
|
||||
use snafu::ensure;
|
||||
|
||||
//using the "parse don't validate" pattern
|
||||
|
|
2
editor/src/tea/mod.rs
Normal file
2
editor/src/tea/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
pub mod model;
|
32
editor/src/tea/model.rs
Normal file
32
editor/src/tea/model.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#[derive(Debug)]
|
||||
pub struct Model {
|
||||
pub file_text: String,
|
||||
pub caret_pos: Position,
|
||||
pub selection_opt: Option<RawSelection>
|
||||
}
|
||||
|
||||
pub fn init_model() -> Model {
|
||||
Model {
|
||||
file_text:
|
||||
String::new(),
|
||||
caret_pos:
|
||||
Position {
|
||||
line: 0, column: 0
|
||||
},
|
||||
selection_opt:
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
//Is model.rs the right place for these structs?
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Position {
|
||||
pub line: usize,
|
||||
pub column: usize
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RawSelection {
|
||||
pub start_pos: Position,
|
||||
pub end_pos: Position
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue