From 3c468531ea7b32c863380070f8495ebceee5421b Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 Aug 2022 14:17:25 -0700 Subject: [PATCH 1/3] =?UTF-8?q?Fixed=20cursor-over-=E5=A4=A7=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/terminal/README.md | 5 +++-- crates/terminal/src/connected_el.rs | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/terminal/README.md b/crates/terminal/README.md index c1e64726b26f64054f9156aabf7132005098927a..99ab583ebbf8590b0137c0acc066ba2f7f261313 100644 --- a/crates/terminal/README.md +++ b/crates/terminal/README.md @@ -1,8 +1,9 @@ Design notes: This crate is split into two conceptual halves: -- The terminal.rs file and the ./src/mappings/ folder, these contain the code for interacting with Alacritty and maintaining the pty event loop. Some behavior in this file is constrained by terminal protocols and standards. The Zed init function is also placed here. +- The terminal.rs file and the src/mappings/ folder, these contain the code for interacting with Alacritty and maintaining the pty event loop. Some behavior in this file is constrained by terminal protocols and standards. The Zed init function is also placed here. - Everything else. These other files integrate the `Terminal` struct created in terminal.rs into the rest of GPUI. The main entry point for GPUI is the terminal_view.rs file and the modal.rs file. Terminals are created externally, and so can fail in unexpected ways However, GPUI currently does not have an API for models than can fail to instantiate. `TerminalBuilder` solves this by using Rust's type system to split `Terminal` instantiation into a 2 step process: first attempt to create the file handles with `TerminalBuilder::new()`, check the result, then call `TerminalBuilder::subscribe(cx)` from within a model context. -The TerminalView struct abstracts over failed and successful terminals, and provides other constructs a standardized way of instantiating an always-successful terminal view. \ No newline at end of file +The TerminalView struct abstracts over failed and successful terminals, and provides a standardized way of instantiating an always-successful view of a terminal. + diff --git a/crates/terminal/src/connected_el.rs b/crates/terminal/src/connected_el.rs index 1a804b4154fb051f041e6afb988525cece8dc3e5..36d75e30b78aa493d7e49ea5520460f1dc77cc76 100644 --- a/crates/terminal/src/connected_el.rs +++ b/crates/terminal/src/connected_el.rs @@ -343,12 +343,14 @@ impl TerminalEl { text_fragment.width() }; + //Cursor should always surround as much of the text as possible, + //hence when on pixel boundaries round the origin down and the width up Some(( vec2f( - cursor_point.col() as f32 * size.cell_width(), - cursor_point.line() as f32 * size.line_height(), + (cursor_point.col() as f32 * size.cell_width()).floor(), + (cursor_point.line() as f32 * size.line_height()).floor(), ), - cursor_width, + cursor_width.ceil(), )) } else { None From 82ecb5923ed0bbe993296f1b4ebf80f4709b063d Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 Aug 2022 14:54:45 -0700 Subject: [PATCH 2/3] Much better rectangle fiddling --- crates/terminal/src/connected_el.rs | 31 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/terminal/src/connected_el.rs b/crates/terminal/src/connected_el.rs index 36d75e30b78aa493d7e49ea5520460f1dc77cc76..76def7dba037d71056af7b47f30bc054e9cd6fa2 100644 --- a/crates/terminal/src/connected_el.rs +++ b/crates/terminal/src/connected_el.rs @@ -53,6 +53,7 @@ pub struct LayoutState { display_offset: usize, } +#[derive(Debug)] struct IndexedCell { point: Point, cell: Cell, @@ -108,7 +109,14 @@ impl LayoutCell { visible_bounds: RectF, cx: &mut PaintContext, ) { - let pos = point_to_absolute(origin, self.point, layout); + let pos = { + let point = self.point; + vec2f( + (origin.x() + point.column as f32 * layout.size.cell_width).floor(), + origin.y() + point.line as f32 * layout.size.line_height, + ) + }; + self.text .paint(pos, visible_bounds, layout.size.line_height, cx); } @@ -139,10 +147,15 @@ impl LayoutRect { } fn paint(&self, origin: Vector2F, layout: &LayoutState, cx: &mut PaintContext) { - let position = point_to_absolute(origin, self.point, layout); - + let position = { + let point = self.point; + vec2f( + (origin.x() + point.column as f32 * layout.size.cell_width).floor(), + origin.y() + point.line as f32 * layout.size.line_height, + ) + }; let size = vec2f( - (layout.size.cell_width.ceil() * self.num_of_cells as f32).ceil(), + (layout.size.cell_width * self.num_of_cells as f32).ceil(), layout.size.line_height, ); @@ -155,13 +168,6 @@ impl LayoutRect { } } -fn point_to_absolute(origin: Vector2F, point: Point, layout: &LayoutState) -> Vector2F { - vec2f( - (origin.x() + point.column as f32 * layout.size.cell_width).floor(), - origin.y() + point.line as f32 * layout.size.line_height, - ) -} - #[derive(Clone, Debug, Default)] struct RelativeHighlightedRange { line_index: usize, @@ -325,7 +331,7 @@ impl TerminalEl { rects.push(cur_rect.take().unwrap()); } } - + dbg!(&rects); (cells, rects, highlight_ranges) } @@ -366,6 +372,7 @@ impl TerminalEl { font_cache: &FontCache, modal: bool, ) -> RunStyle { + dbg!(indexed); let flags = indexed.cell.flags; let fg = convert_color(&fg, &style.colors, modal); From 59feb7ab049a243887953da8185731f0fa153189 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 Aug 2022 15:03:03 -0700 Subject: [PATCH 3/3] Removed debugs --- crates/terminal/src/connected_el.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/terminal/src/connected_el.rs b/crates/terminal/src/connected_el.rs index 76def7dba037d71056af7b47f30bc054e9cd6fa2..b4369ab55e02a8a8c358a25bbed4de316e04d56a 100644 --- a/crates/terminal/src/connected_el.rs +++ b/crates/terminal/src/connected_el.rs @@ -331,7 +331,6 @@ impl TerminalEl { rects.push(cur_rect.take().unwrap()); } } - dbg!(&rects); (cells, rects, highlight_ranges) } @@ -372,7 +371,6 @@ impl TerminalEl { font_cache: &FontCache, modal: bool, ) -> RunStyle { - dbg!(indexed); let flags = indexed.cell.flags; let fg = convert_color(&fg, &style.colors, modal);