diff --git a/editor/README.md b/editor/README.md index 30ae0c19a6..e92385db90 100644 --- a/editor/README.md +++ b/editor/README.md @@ -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) \ No newline at end of file +- [elm-editor](https://github.com/jxxcarlson/elm-editor) +- [iced](https://github.com/hecrj/iced) \ No newline at end of file diff --git a/editor/editor-ideas.md b/editor/editor-ideas.md index 99ed5721cf..ab10bb43d1 100644 --- a/editor/editor-ideas.md +++ b/editor/editor-ideas.md @@ -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 diff --git a/editor/src/lib.rs b/editor/src/lib.rs index 7450f60e71..304c87d07d 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -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> { 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> { event: event::WindowEvent::ReceivedCharacter(ch), .. } => { - update_text_state(&mut text_state, &ch); + update_text_state(&mut ed_model, &ch); } //Keyboard Input Event::WindowEvent { @@ -206,44 +206,41 @@ fn run_event_loop() -> Result<(), Box> { 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} - }; - let selection_rects_res = create_selection_rects(selection, &glyph_bounds_rects); + if let Some(selection) = ed_model.selection_opt { + let selection_rects_res = create_selection_rects(selection, &glyph_bounds_rects); - match selection_rects_res { - Ok(selection_rects) => - if !selection_rects.is_empty() { - let rect_buffers = create_rect_buffers( - &gpu_device, - &mut encoder, - &selection_rects, - ); - - let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, - resolve_target: None, - ops: wgpu::Operations::default(), - }], - depth_stencil_attachment: None, - }); - - render_pass.set_pipeline(&rect_pipeline); - render_pass.set_bind_group(0, &ortho.bind_group, &[]); - render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..)); - render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..)); - render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1); - - drop(render_pass); - }, - Err(e) => print_err(&e) //TODO draw error text on screen + match selection_rects_res { + Ok(selection_rects) => + if !selection_rects.is_empty() { + let rect_buffers = create_rect_buffers( + &gpu_device, + &mut encoder, + &selection_rects, + ); + + let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { + attachment: &frame.view, + resolve_target: None, + ops: wgpu::Operations::default(), + }], + depth_stencil_attachment: None, + }); + + render_pass.set_pipeline(&rect_pipeline); + render_pass.set_bind_group(0, &ortho.bind_group, &[]); + render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..)); + render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..)); + render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1); + + drop(render_pass); + }, + Err(e) => print_err(&e) //TODO draw error text on screen + } } // draw all text @@ -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); } } } diff --git a/editor/src/model.rs b/editor/src/model.rs deleted file mode 100644 index b9caee7617..0000000000 --- a/editor/src/model.rs +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/editor/src/selection.rs b/editor/src/selection.rs index 063b13ddbc..487a14cece 100644 --- a/editor/src/selection.rs +++ b/editor/src/selection.rs @@ -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 diff --git a/editor/src/tea/mod.rs b/editor/src/tea/mod.rs new file mode 100644 index 0000000000..f94bc8aa92 --- /dev/null +++ b/editor/src/tea/mod.rs @@ -0,0 +1,2 @@ + +pub mod model; \ No newline at end of file diff --git a/editor/src/tea/model.rs b/editor/src/tea/model.rs new file mode 100644 index 0000000000..e571ff81d1 --- /dev/null +++ b/editor/src/tea/model.rs @@ -0,0 +1,32 @@ +#[derive(Debug)] +pub struct Model { + pub file_text: String, + pub caret_pos: Position, + pub selection_opt: Option +} + +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 +} \ No newline at end of file