mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
improvements based on PR feedback
This commit is contained in:
parent
862a85698c
commit
0a46c1d48f
5 changed files with 19 additions and 11 deletions
|
@ -67,6 +67,7 @@ itertools = "0.9.0"
|
|||
snafu = { version = "0.6", features = ["backtraces"] }
|
||||
colored = "2"
|
||||
|
||||
|
||||
[dependencies.bytemuck]
|
||||
version = "1.4"
|
||||
features = ["derive"]
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::rect::Rect;
|
||||
use crate::util::size_of_slice;
|
||||
use crate::vertex::Vertex;
|
||||
use bumpalo::collections::Vec as BumpVec;
|
||||
use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
||||
|
||||
pub struct QuadBufferBuilder {
|
||||
|
@ -87,7 +88,7 @@ pub struct RectBuffers {
|
|||
pub fn create_rect_buffers(
|
||||
gpu_device: &wgpu::Device,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
rects: &[Rect],
|
||||
rects: &BumpVec<Rect>,
|
||||
) -> RectBuffers {
|
||||
let nr_of_rects = rects.len() as u64;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ use crate::selection::create_selection_rects;
|
|||
use crate::tea::{model, update};
|
||||
use crate::text::{build_glyph_brush, is_newline, Text};
|
||||
use crate::vertex::Vertex;
|
||||
use bumpalo::Bump;
|
||||
use model::Position;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
|
@ -121,6 +122,8 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
let mut ed_model = model::init_model();
|
||||
let mut keyboard_modifiers = ModifiersState::empty();
|
||||
|
||||
let arena = Bump::new();
|
||||
|
||||
// Render loop
|
||||
window.request_redraw();
|
||||
|
||||
|
@ -216,7 +219,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
if let Some(selection) = ed_model.selection_opt {
|
||||
let selection_rects_res =
|
||||
create_selection_rects(selection, &glyph_bounds_rects);
|
||||
create_selection_rects(selection, &glyph_bounds_rects, &arena);
|
||||
|
||||
match selection_rects_res {
|
||||
Ok(selection_rects) => {
|
||||
|
|
|
@ -3,6 +3,8 @@ use crate::error::{EdResult, InvalidSelection};
|
|||
use crate::rect::Rect;
|
||||
use crate::tea::model::RawSelection;
|
||||
use crate::vec_result::get_res;
|
||||
use bumpalo::collections::Vec as BumpVec;
|
||||
use bumpalo::Bump;
|
||||
use snafu::ensure;
|
||||
|
||||
//using the "parse don't validate" pattern
|
||||
|
@ -39,14 +41,15 @@ fn validate_selection(selection: RawSelection) -> EdResult<ValidSelection> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn create_selection_rects(
|
||||
pub fn create_selection_rects<'a>(
|
||||
raw_sel: RawSelection,
|
||||
glyph_bound_rects: &[Vec<Rect>],
|
||||
) -> EdResult<Vec<Rect>> {
|
||||
arena: &'a Bump,
|
||||
) -> EdResult<BumpVec<'a, Rect>> {
|
||||
let valid_sel = validate_selection(raw_sel)?;
|
||||
let RawSelection { start_pos, end_pos } = valid_sel.selection;
|
||||
|
||||
let mut all_rects = Vec::new();
|
||||
let mut all_rects: BumpVec<Rect> = BumpVec::new_in(arena);
|
||||
|
||||
if start_pos.line == end_pos.line {
|
||||
let start_glyph_rect = get_res(
|
||||
|
|
|
@ -11,13 +11,13 @@ pub fn move_txt_cursor_left(
|
|||
let old_line_nr = old_txt_cursor_pos.line;
|
||||
let old_col_nr = old_txt_cursor_pos.column;
|
||||
|
||||
let (line_nr, col_nr) = if old_txt_cursor_pos.column == 0 {
|
||||
if old_txt_cursor_pos.line == 0 {
|
||||
let (line_nr, col_nr) = if old_col_nr == 0 {
|
||||
if old_line_nr == 0 {
|
||||
(0, 0)
|
||||
} else if let Some(curr_line) = lines.get(old_line_nr - 1) {
|
||||
(old_line_nr - 1, curr_line.len() - 1)
|
||||
} else {
|
||||
(0, 0) // this should never happen, should this method return Result?
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
(old_line_nr, old_col_nr - 1)
|
||||
|
@ -84,7 +84,7 @@ pub fn move_txt_cursor_right(
|
|||
(old_line_nr, old_col_nr)
|
||||
}
|
||||
} else {
|
||||
(0, 0) // this should never happen, should this method return Result?
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
let new_txt_cursor_pos = Position {
|
||||
|
@ -140,7 +140,7 @@ pub fn move_txt_cursor_up(
|
|||
(old_line_nr - 1, old_col_nr)
|
||||
}
|
||||
} else {
|
||||
(0, 0) // this should never happen, should this method return Result?
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
let new_txt_cursor_pos = Position {
|
||||
|
@ -195,7 +195,7 @@ pub fn move_txt_cursor_down(
|
|||
(old_line_nr + 1, old_col_nr)
|
||||
}
|
||||
} else {
|
||||
(0, 0) // this should never happen, should this method return Result?
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
let new_txt_cursor_pos = Position {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue