mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-10 18:08:55 +03:00
fmt
This commit is contained in:
parent
aa01eb787b
commit
1c1568929a
@ -1,7 +1,7 @@
|
||||
use crate::ui::text::lines::Lines;
|
||||
use crate::ui::text::selection::Selection;
|
||||
use crate::ui::text::text_pos::TextPos;
|
||||
use crate::ui::ui_error::{UIResult, OutOfBounds};
|
||||
use crate::ui::ui_error::{OutOfBounds, UIResult};
|
||||
use crate::ui::util::slice_get;
|
||||
use crate::ui::util::slice_get_mut;
|
||||
use bumpalo::collections::String as BumpString;
|
||||
@ -46,10 +46,7 @@ impl CodeLines {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_empty_line(
|
||||
&mut self,
|
||||
line_nr: usize
|
||||
) -> UIResult<()> {
|
||||
pub fn insert_empty_line(&mut self, line_nr: usize) -> UIResult<()> {
|
||||
if line_nr <= self.lines.len() {
|
||||
self.lines.insert(line_nr, String::new());
|
||||
|
||||
@ -59,8 +56,9 @@ impl CodeLines {
|
||||
index: line_nr,
|
||||
collection_name: "code_lines.lines".to_owned(),
|
||||
len: self.lines.len(),
|
||||
}.fail()
|
||||
}
|
||||
}
|
||||
.fail()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn del_at_line(&mut self, line_nr: usize, index: usize) -> UIResult<()> {
|
||||
@ -91,16 +89,14 @@ impl CodeLines {
|
||||
|
||||
TextPos {
|
||||
line: last_line,
|
||||
column: self.line_len(last_line).unwrap() // safe because we just calculated last_line
|
||||
column: self.line_len(last_line).unwrap(), // safe because we just calculated last_line
|
||||
}
|
||||
}
|
||||
|
||||
pub fn line_is_only_newline(&self, line_nr: usize) -> UIResult<bool> {
|
||||
let line = self.get_line(line_nr)?;
|
||||
|
||||
Ok(
|
||||
(*line).eq("\n")
|
||||
)
|
||||
Ok((*line).eq("\n"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +136,6 @@ impl Lines for CodeLines {
|
||||
fn last_char(&self, line_nr: usize) -> UIResult<Option<char>> {
|
||||
Ok(self.get_line(line_nr)?.chars().last())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl fmt::Display for CodeLines {
|
||||
|
@ -9,7 +9,7 @@ use crate::editor::util::index_of;
|
||||
use crate::lang::ast::ExprId;
|
||||
use crate::ui::text::selection::Selection;
|
||||
use crate::ui::text::text_pos::TextPos;
|
||||
use crate::ui::ui_error::{UIResult, OutOfBounds};
|
||||
use crate::ui::ui_error::{OutOfBounds, UIResult};
|
||||
use crate::ui::util::{slice_get, slice_get_mut};
|
||||
use snafu::OptionExt;
|
||||
use std::fmt;
|
||||
@ -50,10 +50,7 @@ impl GridNodeMap {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_empty_line(
|
||||
&mut self,
|
||||
line_nr: usize
|
||||
) -> UIResult<()> {
|
||||
pub fn insert_empty_line(&mut self, line_nr: usize) -> UIResult<()> {
|
||||
if line_nr <= self.lines.len() {
|
||||
self.lines.insert(line_nr, Vec::new());
|
||||
|
||||
@ -63,8 +60,9 @@ impl GridNodeMap {
|
||||
index: line_nr,
|
||||
collection_name: "code_lines.lines".to_owned(),
|
||||
len: self.lines.len(),
|
||||
}.fail()
|
||||
}
|
||||
}
|
||||
.fail()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn del_at_line(&mut self, line_nr: usize, index: usize) -> UIResult<()> {
|
||||
|
@ -157,8 +157,14 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
||||
);
|
||||
|
||||
let ed_model_opt = {
|
||||
let ed_model_res =
|
||||
ed_model::init_model(&code_str, file_path, env, loaded_module, &code_arena, CaretPos::End);
|
||||
let ed_model_res = ed_model::init_model(
|
||||
&code_str,
|
||||
file_path,
|
||||
env,
|
||||
loaded_module,
|
||||
&code_arena,
|
||||
CaretPos::End,
|
||||
);
|
||||
|
||||
match ed_model_res {
|
||||
Ok(mut ed_model) => {
|
||||
@ -418,7 +424,7 @@ fn read_file(file_path_opt: Option<&Path>) -> (&Path, String) {
|
||||
{:?}
|
||||
|
||||
to file {:?}, but it failed."#,
|
||||
HELLO_WORLD, untitled_file
|
||||
HELLO_WORLD, untitled_file
|
||||
)
|
||||
});
|
||||
|
||||
|
@ -225,17 +225,17 @@ impl MarkupNode {
|
||||
|
||||
pub fn has_newline_at_end(&self) -> bool {
|
||||
match self {
|
||||
MarkupNode::Nested { newline_at_end,.. } => *newline_at_end,
|
||||
MarkupNode::Text { newline_at_end,.. } => *newline_at_end,
|
||||
MarkupNode::Blank { newline_at_end,.. } => *newline_at_end,
|
||||
MarkupNode::Nested { newline_at_end, .. } => *newline_at_end,
|
||||
MarkupNode::Text { newline_at_end, .. } => *newline_at_end,
|
||||
MarkupNode::Blank { newline_at_end, .. } => *newline_at_end,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_newline_at_end(&mut self) {
|
||||
match self {
|
||||
MarkupNode::Nested { newline_at_end,.. } => *newline_at_end = true,
|
||||
MarkupNode::Text { newline_at_end,.. } => *newline_at_end = true,
|
||||
MarkupNode::Blank { newline_at_end,.. } => *newline_at_end = true,
|
||||
MarkupNode::Nested { newline_at_end, .. } => *newline_at_end = true,
|
||||
MarkupNode::Text { newline_at_end, .. } => *newline_at_end = true,
|
||||
MarkupNode::Blank { newline_at_end, .. } => *newline_at_end = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,12 +76,8 @@ pub fn init_model<'a>(
|
||||
|
||||
let caret = match caret_pos {
|
||||
CaretPos::Start => CaretWSelect::default(),
|
||||
CaretPos::Exact(txt_pos) => {
|
||||
CaretWSelect::new(txt_pos, None)
|
||||
},
|
||||
CaretPos::End => {
|
||||
CaretWSelect::new(code_lines.end_txt_pos(), None)
|
||||
},
|
||||
CaretPos::Exact(txt_pos) => CaretWSelect::new(txt_pos, None),
|
||||
CaretPos::End => CaretWSelect::new(code_lines.end_txt_pos(), None),
|
||||
};
|
||||
|
||||
Ok(EdModel {
|
||||
@ -194,9 +190,9 @@ pub mod test_ed_model {
|
||||
use crate::editor::resources::strings::HELLO_WORLD;
|
||||
use crate::lang::expr::Env;
|
||||
use crate::lang::pool::Pool;
|
||||
use crate::ui::text::caret_w_select::CaretPos;
|
||||
use crate::ui::text::caret_w_select::test_caret_w_select::convert_dsl_to_selection;
|
||||
use crate::ui::text::caret_w_select::test_caret_w_select::convert_selection_to_dsl;
|
||||
use crate::ui::text::caret_w_select::CaretPos;
|
||||
use crate::ui::text::lines::SelectableLines;
|
||||
use crate::ui::ui_error::UIResult;
|
||||
use bumpalo::Bump;
|
||||
@ -234,7 +230,14 @@ pub mod test_ed_model {
|
||||
exposed_ident_ids,
|
||||
);
|
||||
|
||||
ed_model::init_model(code_str, file_path, env, loaded_module, code_arena, CaretPos::End)
|
||||
ed_model::init_model(
|
||||
code_str,
|
||||
file_path,
|
||||
env,
|
||||
loaded_module,
|
||||
code_arena,
|
||||
CaretPos::End,
|
||||
)
|
||||
}
|
||||
|
||||
pub struct EdModelRefs {
|
||||
|
@ -104,15 +104,13 @@ impl<'a> EdModel<'a> {
|
||||
|
||||
// disregards EdModel.code_lines because the caller knows the resulting caret position will be valid.
|
||||
// allows us to prevent multiple updates to EdModel.code_lines
|
||||
pub fn simple_move_caret_down(&mut self, old_caret_pos:TextPos, repeat: usize) {
|
||||
pub fn simple_move_caret_down(&mut self, old_caret_pos: TextPos, repeat: usize) {
|
||||
for caret_tup in self.caret_w_select_vec.iter_mut() {
|
||||
|
||||
if caret_tup.0.caret_pos == old_caret_pos {
|
||||
caret_tup.0.caret_pos.column = 0;
|
||||
caret_tup.0.caret_pos.line += repeat;
|
||||
caret_tup.1 = None;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +189,6 @@ impl<'a> EdModel<'a> {
|
||||
for child_id in node.get_children_ids() {
|
||||
EdModel::build_markup_string(child_id, all_code_string, markup_node_pool)?;
|
||||
}
|
||||
|
||||
} else {
|
||||
let node_content_str = node.get_content();
|
||||
|
||||
@ -245,10 +242,7 @@ impl<'a> EdModel<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_empty_line(
|
||||
&mut self,
|
||||
line_nr: usize,
|
||||
) -> UIResult<()> {
|
||||
pub fn insert_empty_line(&mut self, line_nr: usize) -> UIResult<()> {
|
||||
self.code_lines.insert_empty_line(line_nr)?;
|
||||
self.grid_node_map.insert_empty_line(line_nr)
|
||||
}
|
||||
@ -447,7 +441,7 @@ impl<'a> EdModel<'a> {
|
||||
attributes: Attributes::new(),
|
||||
syn_high_style: HighlightStyle::Blank,
|
||||
parent_id_opt: expr2_level_mark_node.get_parent_id_opt(),
|
||||
newline_at_end
|
||||
newline_at_end,
|
||||
};
|
||||
|
||||
self.markup_node_pool
|
||||
@ -903,7 +897,7 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
|
||||
if *received_char == '\r' {
|
||||
// TODO move to separate file
|
||||
let carets = ed_model.get_carets();
|
||||
|
||||
|
||||
for caret_pos in carets.iter() {
|
||||
|
||||
let caret_line_nr = caret_pos.line;
|
||||
@ -944,15 +938,15 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
|
||||
ed_model.simple_move_carets_down(2); // one blank line between top level definitions
|
||||
|
||||
InputOutcome::Accepted
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
let prev_mark_node_id_opt = ed_model.get_prev_mark_node_id()?;
|
||||
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
|
||||
let prev_mark_node = ed_model.markup_node_pool.get(prev_mark_node_id);
|
||||
|
||||
|
||||
let prev_ast_node = ed_model.module.env.pool.get(prev_mark_node.get_ast_node_id());
|
||||
|
||||
|
||||
match prev_ast_node {
|
||||
Expr2::SmallInt{ .. } => {
|
||||
update_int(ed_model, prev_mark_node_id, ch)?
|
||||
@ -999,9 +993,9 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
|
||||
)?;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
handle_new_char(received_char, ed_model)?
|
||||
|
@ -61,7 +61,10 @@ pub fn model_to_wgpu<'a>(
|
||||
|
||||
let mut all_rendered = RenderedWgpu::new();
|
||||
|
||||
let tip_txt_coords = (txt_coords.x, txt_coords.y - (START_TIP.matches('\n').count() as f32 + 1.0) * config.code_font_size);
|
||||
let tip_txt_coords = (
|
||||
txt_coords.x,
|
||||
txt_coords.y - (START_TIP.matches('\n').count() as f32 + 1.0) * config.code_font_size,
|
||||
);
|
||||
|
||||
let start_tip_text = owned_section_from_text(&Text {
|
||||
position: tip_txt_coords.into(),
|
||||
|
@ -73,7 +73,8 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<
|
||||
|
||||
let equals_mn_id = ed_model.add_mark_node(new_equals_mn(ast_node_id, Some(curr_mark_node_id)));
|
||||
|
||||
let body_mn_id = ed_model.add_mark_node(new_blank_mn_w_nl(val_expr_id, Some(curr_mark_node_id)));
|
||||
let body_mn_id =
|
||||
ed_model.add_mark_node(new_blank_mn_w_nl(val_expr_id, Some(curr_mark_node_id)));
|
||||
|
||||
let val_mark_node = MarkupNode::Nested {
|
||||
ast_node_id,
|
||||
|
@ -94,7 +94,6 @@ fn markup_to_wgpu_helper<'a>(
|
||||
txt_row_col: &mut (usize, usize),
|
||||
markup_node_pool: &'a SlowPool,
|
||||
) -> EdResult<()> {
|
||||
|
||||
match markup_node {
|
||||
MarkupNode::Nested {
|
||||
ast_node_id: _,
|
||||
@ -196,6 +195,5 @@ fn markup_to_wgpu_helper<'a>(
|
||||
}
|
||||
|
||||
fn newline(font_size: f32) -> glyph_brush::OwnedText {
|
||||
glyph_brush::OwnedText::new("\n")
|
||||
.with_scale(font_size)
|
||||
glyph_brush::OwnedText::new("\n").with_scale(font_size)
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ pub fn build_debug_graphics(
|
||||
|
||||
let debug_txt_coords: Vector2<f32> = (txt_coords.x, txt_coords.y * 3.0).into();
|
||||
|
||||
let carets_text = glyph_brush::OwnedText::new(format!("carets: {:?}\n\n", ed_model.get_carets()))
|
||||
.with_color(colors::to_slice(from_hsb(0, 0, 100)))
|
||||
.with_scale(config.code_font_size);
|
||||
let carets_text =
|
||||
glyph_brush::OwnedText::new(format!("carets: {:?}\n\n", ed_model.get_carets()))
|
||||
.with_color(colors::to_slice(from_hsb(0, 0, 100)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
let grid_node_map_text = glyph_brush::OwnedText::new(format!("{}", ed_model.grid_node_map))
|
||||
.with_color(colors::to_slice(from_hsb(20, 41, 100)))
|
||||
@ -35,7 +36,8 @@ pub fn build_debug_graphics(
|
||||
|
||||
let mut mark_node_trees_string = "\nmark node trees:".to_owned();
|
||||
|
||||
for mark_id in ed_model.markup_ids[1..].iter() { // 1.. -> skip header
|
||||
for mark_id in ed_model.markup_ids[1..].iter() {
|
||||
// 1.. -> skip header
|
||||
mark_node_trees_string.push_str(&tree_as_string(*mark_id, &ed_model.markup_node_pool));
|
||||
|
||||
mark_node_trees_string.push('\n');
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub const NOTHING_OPENED: &str = "Execute `cargo run edit` from the root folder of the repo to try the editor.";
|
||||
pub const START_TIP: &str =
|
||||
r#"Currently supported: lists, records, string, numbers and value definitions.
|
||||
pub const NOTHING_OPENED: &str =
|
||||
"Execute `cargo run edit` from the root folder of the repo to try the editor.";
|
||||
pub const START_TIP: &str = r#"Currently supported: lists, records, string, numbers and value definitions.
|
||||
|
||||
Use `Ctrl+Shift+Up` or `Cmd+Shift+Up` to select surrounding expression.
|
||||
Use backspace after `Ctrl+Shift+Up` to delete the selected expression.
|
||||
@ -17,4 +17,3 @@ app "test-app"
|
||||
|
||||
main = "Hello, world!"
|
||||
"#;
|
||||
|
||||
|
@ -15,7 +15,7 @@ pub struct CaretWSelect {
|
||||
pub enum CaretPos {
|
||||
Start,
|
||||
Exact(TextPos),
|
||||
End
|
||||
End,
|
||||
}
|
||||
|
||||
fn mk_some_sel(start_pos: TextPos, end_pos: TextPos) -> UIResult<Option<Selection>> {
|
||||
|
Loading…
Reference in New Issue
Block a user