From 30160c869294b984834bd87829b58c27af29deb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 16:20:08 +0100 Subject: [PATCH 1/9] Replace Delete with Backspace --- src/buffer.rs | 52 ++++++++++++++++++++++++++++++--------------------- src/main.rs | 6 +++--- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index cd629e6..ea2ab24 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -24,10 +24,7 @@ struct Location { impl Location { fn new() -> Location { - Location { - row: 0, - col: 0, - } + Location { row: 0, col: 0 } } } @@ -51,7 +48,9 @@ impl Span { } fn get_char_indices_for_line(&self, line: usize, line_length: usize) -> Option<(usize, usize)> { - if !self.contains_line(line) { return None; } + if !self.contains_line(line) { + return None; + } // 4 Cases: // Start/End line @@ -60,9 +59,9 @@ impl Span { // End line if self.start.row == self.end.row { - Some((self.start.col, self.end.col)) + Some((self.start.col, self.end.col)) } else if self.start.row == line { - Some((self.start.col, line_length)) + Some((self.start.col, line_length)) } else if self.end.row == line { Some((0, self.end.col)) } else { @@ -86,7 +85,7 @@ impl Cursor { selection_start: None, } } - + fn set_row(&mut self, row: usize) { self.location.row = row; } @@ -276,22 +275,32 @@ impl Buffer { } pub fn handle_char_input(&mut self, input: char) { + dbg!("input: {:?}", input); if input == '\n' || input == '\r' { let new_line = self.lines[self.cursor.location.row].split_off(self.cursor.location.col); self.cursor.set_row(self.cursor.location.row + 1); self.lines.insert(self.cursor.location.row, new_line); self.cursor.set_col_with_affinity(0); - } else if input == 127 as char { + // this is Delete + //} else if input == '\u{7f}' { + // this is Backspace + } else if input == '\u{8}' { + dbg!("first"); if self.cursor.location.col > 0 { + dbg!("second"); self.lines[self.cursor.location.row].remove(self.cursor.location.col - 1); - self.cursor.set_col_with_affinity(self.cursor.location.col - 1); + self.cursor + .set_col_with_affinity(self.cursor.location.col - 1); } else if self.cursor.location.row > 0 { + dbg!("third"); let remaining = self.lines.remove(self.cursor.location.row); self.cursor.set_row(self.cursor.location.row - 1); - self.cursor.set_col_with_affinity(self.lines[self.cursor.location.row].len()); + self.cursor + .set_col_with_affinity(self.lines[self.cursor.location.row].len()); self.lines[self.cursor.location.row].push_str(&remaining); } } else { + dbg!("four"); self.lines[self.cursor.location.row].insert(self.cursor.location.col, input); self.cursor.set_col(self.cursor.location.col + 1); } @@ -325,9 +334,7 @@ impl Buffer { let row = (self.cursor.location.row as isize - 1) .max(0) .min(self.lines.len() as isize) as usize; - let col = self.lines[row] - .len() - .min(self.cursor.col_affinity); + let col = self.lines[row].len().min(self.cursor.col_affinity); self.cursor.set_row(row); self.cursor.set_col(col); } @@ -336,9 +343,7 @@ impl Buffer { let row = (self.cursor.location.row as isize + 1) .max(0) .min(self.lines.len() as isize - 1) as usize; - let col = self.lines[row] - .len() - .min(self.cursor.col_affinity); + let col = self.lines[row].len().min(self.cursor.col_affinity); self.cursor.set_row(row); self.cursor.set_col(col); } @@ -347,10 +352,12 @@ impl Buffer { if self.cursor.location.col == 0 { if self.cursor.location.row > 0 { self.cursor.set_row(self.cursor.location.row - 1); - self.cursor.set_col_with_affinity(self.lines[self.cursor.location.row].len()); + self.cursor + .set_col_with_affinity(self.lines[self.cursor.location.row].len()); } } else { - self.cursor.set_col_with_affinity(self.cursor.location.col - 1); + self.cursor + .set_col_with_affinity(self.cursor.location.col - 1); } } VirtualKeyCode::Right => { @@ -361,7 +368,8 @@ impl Buffer { self.cursor.set_col_with_affinity(0); } } else { - self.cursor.set_col_with_affinity(self.cursor.location.col + 1); + self.cursor + .set_col_with_affinity(self.cursor.location.col + 1); } } _ => {} @@ -411,7 +419,9 @@ impl Buffer { let mut line_no_color = [0.4, 0.4, 0.4, 1.0]; // Paint selection boxes - if let Some((start, end)) = selection_span.and_then(|span| span.get_char_indices_for_line(index, line.len())) { + if let Some((start, end)) = + selection_span.and_then(|span| span.get_char_indices_for_line(index, line.len())) + { // TODO: Gah, we should not do this. We should do a single layout pass and add some // methods that lets us query glyph locations. let layout = glyph_brush.fonts().first().unwrap().layout( diff --git a/src/main.rs b/src/main.rs index 7b51181..b2910ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// TODO List + // TODO List // * Do better text layout and more easily track metrics? (helpful for hit-testing) // * Text selections // * Support mouse up/down/move in editor/buffer @@ -58,8 +58,8 @@ fn main() -> Result<(), Box> { ); // TODO: Dynamically load fonts or something? - let inconsolata: &[u8] = - include_bytes!("/Users/connor/Library/Fonts/InconsolataGo-Regular.ttf"); + let inconsolata: &[u8] = include_bytes!("/usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf"); + // /Users/connor/Library/Fonts/InconsolataGo-Regular.ttf"); let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(inconsolata).build(&mut device, render_format); From dd7b516ac368676cd1aa1f8f4853816a92c81d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 16:46:16 +0100 Subject: [PATCH 2/9] Change from LWin to LControl for quit and save --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index b2910ba..24ddc62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ - // TODO List +// TODO List // * Do better text layout and more easily track metrics? (helpful for hit-testing) // * Text selections // * Support mouse up/down/move in editor/buffer @@ -84,17 +84,17 @@ fn main() -> Result<(), Box> { event: WindowEvent::KeyboardInput { input, .. }, .. } => { - if input.virtual_keycode == Some(VirtualKeyCode::LWin) { + if input.virtual_keycode == Some(VirtualKeyCode::LControl) { modifier_pressed = input.state == ElementState::Pressed; } match (input.virtual_keycode, input.modifiers) { // Quit - (Some(VirtualKeyCode::Q), ModifiersState { logo: true, .. }) => { + (Some(VirtualKeyCode::Q), ModifiersState { ctrl: true, .. }) => { *control_flow = ControlFlow::Exit } // Save - (Some(VirtualKeyCode::S), ModifiersState { logo: true, .. }) => { + (Some(VirtualKeyCode::S), ModifiersState { ctrl: true, .. }) => { editor.save(); } From 37d215c19d5fe7d14df5e78a592f2516a5cba76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 16:59:02 +0100 Subject: [PATCH 3/9] Delete works --- src/buffer.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index ea2ab24..86c5e0c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -281,8 +281,6 @@ impl Buffer { self.cursor.set_row(self.cursor.location.row + 1); self.lines.insert(self.cursor.location.row, new_line); self.cursor.set_col_with_affinity(0); - // this is Delete - //} else if input == '\u{7f}' { // this is Backspace } else if input == '\u{8}' { dbg!("first"); @@ -299,6 +297,13 @@ impl Buffer { .set_col_with_affinity(self.lines[self.cursor.location.row].len()); self.lines[self.cursor.location.row].push_str(&remaining); } + // this is Delete + } else if input == '\u{7f}' { + dbg!("delete first"); + dbg!("{}", &self.lines[self.cursor.location.row]); + if self.lines[self.cursor.location.row].len() > self.cursor.location.col { + self.lines[self.cursor.location.row].remove(self.cursor.location.col); + } } else { dbg!("four"); self.lines[self.cursor.location.row].insert(self.cursor.location.col, input); From f107f2a47d4942a3e2cff8b1dc318cb149b09dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 17:03:24 +0100 Subject: [PATCH 4/9] Do nothing when Tab is pressed --- src/buffer.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/buffer.rs b/src/buffer.rs index 86c5e0c..52f7030 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -304,6 +304,10 @@ impl Buffer { if self.lines[self.cursor.location.row].len() > self.cursor.location.col { self.lines[self.cursor.location.row].remove(self.cursor.location.col); } + } else if input == '\t' { + // Do nothing, unless we consider how to display tab, + // because now cursor should be moved to right one character when deleting + // Also, now when there is \t in the file, it will not be displayed correctly } else { dbg!("four"); self.lines[self.cursor.location.row].insert(self.cursor.location.col, input); From 43cf51008ce2f20f1326a9b5413e70dd00803c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 17:19:13 +0100 Subject: [PATCH 5/9] wip --- Cargo.lock | 9 +++++---- Cargo.toml | 2 +- src/buffer.rs | 14 +++++++------- src/editor.rs | 12 ++++++------ 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e94d1ff..7a211d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ dependencies = [ "syntect 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "wgpu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "wgpu_glyph 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winit 0.20.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)", + "winit 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1635,12 +1635,11 @@ dependencies = [ [[package]] name = "winit" -version = "0.20.0-alpha5" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "calloop 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1650,6 +1649,8 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1927,7 +1928,7 @@ dependencies = [ "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" -"checksum winit 0.20.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)" = "14fbf7c84c8c1ff9d72982cb382c1a78fbe0f7556f49b1ca98de212d018c5b82" +"checksum winit 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba128780050481f453bec2a115b916dbc6ae79c303dee9bad8b9080bdccd4f5" "checksum wio 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39697e3123f715483d311b5826e254b6f3cfebdd83cf7ef3358f579c3d68e235" diff --git a/Cargo.toml b/Cargo.toml index ddd5335..7f8d825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ edition = "2018" syntect = "3.3" wgpu = "0.4.0" wgpu_glyph = "0.6.0" -winit = "0.20.0-alpha5" # TODO: Update once out of alpha +winit = "0.20.0" diff --git a/src/buffer.rs b/src/buffer.rs index 52f7030..ab75c1c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -121,7 +121,7 @@ pub struct Buffer { scroll: f32, cursor: Cursor, dragging: bool, - size: PhysicalSize, + size: PhysicalSize, path: PathBuf, // TODO: Move those to editor? syntax_set: SyntaxSet, @@ -162,7 +162,7 @@ fn generate_highlight_info( } impl Buffer { - pub fn new(size: PhysicalSize, file_name: String) -> Buffer { + pub fn new(size: PhysicalSize, file_name: String) -> Buffer { let path = Path::new(&file_name); let file = std::fs::read_to_string(path).expect("Failed to read file."); // TODO: Not sure if just splitting '\n' is right here. @@ -193,7 +193,7 @@ impl Buffer { std::fs::write(&self.path, self.lines.join("\n")).expect("Failed to save file."); } - pub fn update_size(&mut self, size: PhysicalSize) { + pub fn update_size(&mut self, size: PhysicalSize) { self.size = size; } @@ -223,7 +223,7 @@ impl Buffer { &mut self, button: MouseButton, state: ElementState, - position: PhysicalPosition, + position: PhysicalPosition, ) { if button == MouseButton::Left { if state == ElementState::Pressed { @@ -238,7 +238,7 @@ impl Buffer { } } - pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { + pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { if self.dragging { if self.cursor.selection_start.is_none() { self.cursor.selection_start = Some(self.cursor.location); @@ -249,7 +249,7 @@ impl Buffer { } } - fn hit_test(&self, position: PhysicalPosition) -> Location { + fn hit_test(&self, position: PhysicalPosition) -> Location { let x_pad = 10.0; let digit_count = self.lines.len().to_string().chars().count(); let gutter_offset = x_pad + 30.0 + digit_count as f32 * (SCALE / 2.0); @@ -388,7 +388,7 @@ impl Buffer { pub fn draw( &self, - size: PhysicalSize, + size: PhysicalSize, glyph_brush: &mut GlyphBrush<()>, rect_brush: &mut RectangleBrush, ) { diff --git a/src/editor.rs b/src/editor.rs index ec18efe..79acaf8 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -9,11 +9,11 @@ use winit::{ pub struct Editor { buffers: Vec, active_buffer: usize, - size: PhysicalSize, + size: PhysicalSize, } impl Editor { - pub fn new(size: PhysicalSize, file_name: String) -> Editor { + pub fn new(size: PhysicalSize, file_name: String) -> Editor { Editor { buffers: vec![Buffer::new(size, file_name)], active_buffer: 0, @@ -25,7 +25,7 @@ impl Editor { self.buffers[self.active_buffer].save(); } - pub fn update_size(&mut self, size: PhysicalSize) { + pub fn update_size(&mut self, size: PhysicalSize) { self.size = size; for buffer in &mut self.buffers { buffer.update_size(size); @@ -44,18 +44,18 @@ impl Editor { &mut self, button: MouseButton, state: ElementState, - position: PhysicalPosition, + position: PhysicalPosition, ) { self.buffers[self.active_buffer].handle_mouse_input(button, state, position); } - pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { + pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { self.buffers[self.active_buffer].handle_mouse_move(position); } pub fn draw( &self, - size: PhysicalSize, + size: PhysicalSize, glyph_brush: &mut GlyphBrush<()>, rect_brush: &mut RectangleBrush, ) { From e60b15b3c1bc3caf02119fa072c575018dfb67cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 18:02:14 +0100 Subject: [PATCH 6/9] Compiles but the window is just black background --- src/buffer.rs | 10 +++++----- src/editor.rs | 4 ++-- src/main.rs | 32 ++++++++++++++------------------ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index ab75c1c..d21bc5a 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -223,7 +223,7 @@ impl Buffer { &mut self, button: MouseButton, state: ElementState, - position: PhysicalPosition, + position: PhysicalPosition, ) { if button == MouseButton::Left { if state == ElementState::Pressed { @@ -238,7 +238,7 @@ impl Buffer { } } - pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { + pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { if self.dragging { if self.cursor.selection_start.is_none() { self.cursor.selection_start = Some(self.cursor.location); @@ -249,14 +249,14 @@ impl Buffer { } } - fn hit_test(&self, position: PhysicalPosition) -> Location { + fn hit_test(&self, position: PhysicalPosition) -> Location { let x_pad = 10.0; let digit_count = self.lines.len().to_string().chars().count(); let gutter_offset = x_pad + 30.0 + digit_count as f32 * (SCALE / 2.0); let abs_position = PhysicalPosition::new( - (position.x - gutter_offset as f64).max(0.0), - position.y + self.scroll as f64, + (position.x as f32 - gutter_offset).max(0.0), + position.y as f32 + self.scroll, ); let line = (abs_position.y / 40.0).floor() as usize; diff --git a/src/editor.rs b/src/editor.rs index 79acaf8..2e2c8d7 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -44,12 +44,12 @@ impl Editor { &mut self, button: MouseButton, state: ElementState, - position: PhysicalPosition, + position: PhysicalPosition, ) { self.buffers[self.active_buffer].handle_mouse_input(button, state, position); } - pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { + pub fn handle_mouse_move(&mut self, position: PhysicalPosition) { self.buffers[self.active_buffer].handle_mouse_move(position); } diff --git a/src/main.rs b/src/main.rs index 24ddc62..1d5b684 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ fn main() -> Result<(), Box> { let window = WindowBuilder::new() .with_title("brewcode") .build(&event_loop)?; - let mut size = window.inner_size().to_physical(window.hidpi_factor()); + let mut size = window.inner_size(); let surface = wgpu::Surface::create(&window); let adapter = wgpu::Adapter::request(&wgpu::RequestAdapterOptions { @@ -51,8 +51,8 @@ fn main() -> Result<(), Box> { &wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, format: render_format, - width: size.width.round() as u32, - height: size.height.round() as u32, + width: size.width, + height: size.height, present_mode: wgpu::PresentMode::Vsync, }, ); @@ -72,7 +72,7 @@ fn main() -> Result<(), Box> { let mut last_frame = std::time::Instant::now(); let mut modifier_pressed = false; - let mut cursor_position = PhysicalPosition::new(0.0, 0.0); + let mut cursor_position: PhysicalPosition = PhysicalPosition::new(0, 0); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { @@ -89,12 +89,12 @@ fn main() -> Result<(), Box> { } match (input.virtual_keycode, input.modifiers) { // Quit - (Some(VirtualKeyCode::Q), ModifiersState { ctrl: true, .. }) => { + (Some(VirtualKeyCode::Q), ModifiersState::CTRL) => { *control_flow = ControlFlow::Exit } // Save - (Some(VirtualKeyCode::S), ModifiersState { ctrl: true, .. }) => { + (Some(VirtualKeyCode::S), ModifiersState::CTRL) => { editor.save(); } @@ -121,7 +121,7 @@ fn main() -> Result<(), Box> { event: WindowEvent::CursorMoved { position, .. }, .. } => { - cursor_position = position.to_physical(window.hidpi_factor()); + cursor_position = position; editor.handle_mouse_move(cursor_position); window.request_redraw(); } @@ -152,16 +152,15 @@ fn main() -> Result<(), Box> { event: WindowEvent::Resized(new_size), .. } => { - size = new_size.to_physical(window.hidpi_factor()); - editor.update_size(size); + editor.update_size(new_size); swap_chain = device.create_swap_chain( &surface, &wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, format: render_format, - width: size.width.round() as u32, - height: size.height.round() as u32, + width: size.width, + height: size.height, present_mode: wgpu::PresentMode::Vsync, }, ); @@ -169,10 +168,7 @@ fn main() -> Result<(), Box> { window.request_redraw(); } - Event::WindowEvent { - event: WindowEvent::RedrawRequested, - .. - } => { + Event::RedrawRequested(_) => { let dt = last_frame.elapsed().as_millis(); let fps = 1.0 / ((dt as f32) / 1000.0); last_frame = std::time::Instant::now(); @@ -204,7 +200,7 @@ fn main() -> Result<(), Box> { &device, &mut encoder, &frame.view, - (size.width, size.height), + (size.width as f64, size.height as f64), ); glyph_brush.queue(Section { @@ -220,8 +216,8 @@ fn main() -> Result<(), Box> { &mut device, &mut encoder, &frame.view, - size.width.round() as u32, - size.height.round() as u32, + size.width, + size.height, ) .expect("Failed to draw queued text."); From 100edb2b64228c0a98d28b46e7af88153d474272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 21:43:53 +0100 Subject: [PATCH 7/9] Remove dbg --- src/buffer.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index d21bc5a..46a7d91 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -275,7 +275,6 @@ impl Buffer { } pub fn handle_char_input(&mut self, input: char) { - dbg!("input: {:?}", input); if input == '\n' || input == '\r' { let new_line = self.lines[self.cursor.location.row].split_off(self.cursor.location.col); self.cursor.set_row(self.cursor.location.row + 1); @@ -283,14 +282,11 @@ impl Buffer { self.cursor.set_col_with_affinity(0); // this is Backspace } else if input == '\u{8}' { - dbg!("first"); if self.cursor.location.col > 0 { - dbg!("second"); self.lines[self.cursor.location.row].remove(self.cursor.location.col - 1); self.cursor .set_col_with_affinity(self.cursor.location.col - 1); } else if self.cursor.location.row > 0 { - dbg!("third"); let remaining = self.lines.remove(self.cursor.location.row); self.cursor.set_row(self.cursor.location.row - 1); self.cursor @@ -299,8 +295,6 @@ impl Buffer { } // this is Delete } else if input == '\u{7f}' { - dbg!("delete first"); - dbg!("{}", &self.lines[self.cursor.location.row]); if self.lines[self.cursor.location.row].len() > self.cursor.location.col { self.lines[self.cursor.location.row].remove(self.cursor.location.col); } @@ -309,7 +303,6 @@ impl Buffer { // because now cursor should be moved to right one character when deleting // Also, now when there is \t in the file, it will not be displayed correctly } else { - dbg!("four"); self.lines[self.cursor.location.row].insert(self.cursor.location.col, input); self.cursor.set_col(self.cursor.location.col + 1); } From 8236848f9985379978f36659c3a126b73596f4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 21:52:17 +0100 Subject: [PATCH 8/9] Remove mut from size --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1d5b684..49b126a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ fn main() -> Result<(), Box> { let window = WindowBuilder::new() .with_title("brewcode") .build(&event_loop)?; - let mut size = window.inner_size(); + let size = window.inner_size(); let surface = wgpu::Surface::create(&window); let adapter = wgpu::Adapter::request(&wgpu::RequestAdapterOptions { From 7ad1e16b86aa4683eddf8100cb04900d18ef4c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 14 Jan 2020 21:55:08 +0100 Subject: [PATCH 9/9] Update size --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 49b126a..d333509 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ fn main() -> Result<(), Box> { let window = WindowBuilder::new() .with_title("brewcode") .build(&event_loop)?; - let size = window.inner_size(); + let mut size = window.inner_size(); let surface = wgpu::Surface::create(&window); let adapter = wgpu::Adapter::request(&wgpu::RequestAdapterOptions { @@ -152,7 +152,8 @@ fn main() -> Result<(), Box> { event: WindowEvent::Resized(new_size), .. } => { - editor.update_size(new_size); + size = new_size; + editor.update_size(size); swap_chain = device.create_swap_chain( &surface,