From a6910584b61f82873ee18908fdc642ab35455998 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 12 Oct 2022 00:39:56 -0400 Subject: [PATCH 01/18] Something's happening, nothing correct, but something --- crates/editor/src/element.rs | 135 ++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 42 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 587133e9dd703b04beef2d8f51e602cfd609f446..97d29a404a5b36da5125db7fcfa805096f6f6918 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -48,6 +48,11 @@ use std::{ }; use theme::DiffStyle; +struct DiffHunkLayout { + visual_range: Range, + status: DiffHunkStatus, +} + struct SelectionLayout { head: DisplayPoint, range: Range, @@ -539,17 +544,17 @@ impl EditorElement { } fn diff_quad( - hunk: &DiffHunk, + hunk: &DiffHunkLayout, gutter_layout: &GutterLayout, diff_style: &DiffStyle, ) -> Quad { - let color = match hunk.status() { + let color = match hunk.status { DiffHunkStatus::Added => diff_style.inserted, DiffHunkStatus::Modified => diff_style.modified, //TODO: This rendering is entirely a horrible hack DiffHunkStatus::Removed => { - let row = hunk.buffer_range.start; + let row = hunk.visual_range.start; let offset = gutter_layout.line_height / 2.; let start_y = @@ -570,8 +575,8 @@ impl EditorElement { } }; - let start_row = hunk.buffer_range.start; - let end_row = hunk.buffer_range.end; + let start_row = hunk.visual_range.start; + let end_row = hunk.visual_range.end; let start_y = start_row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; let end_y = end_row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; @@ -613,7 +618,13 @@ impl EditorElement { GitGutter::TrackedFiles ); - // line is `None` when there's a line wrap + if show_gutter { + for hunk in &layout.hunk_layouts { + let quad = diff_quad(hunk, &gutter_layout, diff_style); + cx.scene.push_quad(quad); + } + } + for (ix, line) in layout.line_number_layouts.iter().enumerate() { if let Some(line) = line { let line_origin = bounds.origin() @@ -624,38 +635,9 @@ impl EditorElement { ); line.paint(line_origin, visible_bounds, gutter_layout.line_height, cx); - - if show_gutter { - //This line starts a buffer line, so let's do the diff calculation - let new_hunk = get_hunk(diff_layout.buffer_row, &layout.diff_hunks); - - let (is_ending, is_starting) = match (diff_layout.last_diff, new_hunk) { - (Some(old_hunk), Some(new_hunk)) if new_hunk == old_hunk => (false, false), - (a, b) => (a.is_some(), b.is_some()), - }; - - if is_ending { - let last_hunk = diff_layout.last_diff.take().unwrap(); - cx.scene - .push_quad(diff_quad(last_hunk, &gutter_layout, diff_style)); - } - - if is_starting { - let new_hunk = new_hunk.unwrap(); - diff_layout.last_diff = Some(new_hunk); - }; - - diff_layout.buffer_row += 1; - } } } - // If we ran out with a diff hunk still being prepped, paint it now - if let Some(last_hunk) = diff_layout.last_diff { - cx.scene - .push_quad(diff_quad(last_hunk, &gutter_layout, diff_style)) - } - if let Some((row, indicator)) = layout.code_actions_indicator.as_mut() { let mut x = bounds.width() - layout.gutter_padding; let mut y = *row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; @@ -1013,6 +995,78 @@ impl EditorElement { .width() } + fn layout_diff_hunk( + hunk: &DiffHunk, + buffer_rows: &mut std::iter::Peekable>>, + ) -> DiffHunkLayout { + //This should start with a row which is contained in the hunk's buffer range + let visual_start = buffer_rows.peek().unwrap().unwrap(); + + let mut visual_count = 0; + while let Some(&buffer_row) = buffer_rows.peek() { + if let Some(buffer_row) = buffer_row { + if buffer_row == hunk.buffer_range.end { + visual_count += 1; + break; + } else if buffer_row > hunk.buffer_range.end { + break; + } + visual_count += 1; + buffer_rows.next(); + } + } + + DiffHunkLayout { + visual_range: visual_start..visual_start + visual_count, + status: hunk.status(), + } + } + + //Folds contained in a hunk are ignored apart from shrinking visual size + //If a fold contains any hunks then that fold line is marked as modified + fn layout_git_gutters( + &self, + rows: Range, + snapshot: &EditorSnapshot, + ) -> Vec { + let mut diff_hunks = snapshot + .buffer_snapshot + .git_diff_hunks_in_range(rows.clone()) + .peekable(); + + //Some number followed by Nones for wrapped lines + //Jump in number for folded lines + let mut buffer_rows = snapshot + .buffer_rows(rows.start) + .take((rows.end - rows.start) as usize) + .peekable(); + + let mut layouts = Vec::new(); + + while let Some(buffer_row) = buffer_rows.next() { + let buffer_row = buffer_row.unwrap(); + + if let Some(hunk) = diff_hunks.peek() { + if hunk.buffer_range.contains(&buffer_row) { + layouts.push(Self::layout_diff_hunk(hunk, &mut buffer_rows)); + diff_hunks.next(); + } else if hunk.buffer_range.end < buffer_row { + //A hunk that was missed due to being entirely contained in a fold + //We can safely assume that the previous visual row is the fold + //TODO: If there is another hunk that ends inside the fold then + //this will overlay over, but right now that seems fine + layouts.push(DiffHunkLayout { + visual_range: buffer_row - 1..buffer_row, + status: DiffHunkStatus::Modified, + }); + diff_hunks.next(); + } + } + } + + layouts + } + fn layout_line_numbers( &self, rows: Range, @@ -1367,7 +1421,7 @@ impl EditorElement { /// Get the hunk that contains buffer_line, starting from start_idx /// Returns none if there is none found, and -fn get_hunk(buffer_line: u32, hunks: &[DiffHunk]) -> Option<&DiffHunk> { +fn get_hunk(hunks: &[DiffHunk], buffer_line: u32) -> Option<&DiffHunk> { for i in 0..hunks.len() { // Safety: Index out of bounds is handled by the check above let hunk = hunks.get(i).unwrap(); @@ -1561,10 +1615,7 @@ impl Element for EditorElement { let line_number_layouts = self.layout_line_numbers(start_row..end_row, &active_rows, &snapshot, cx); - let diff_hunks = snapshot - .buffer_snapshot - .git_diff_hunks_in_range(start_row..end_row) - .collect(); + let hunk_layouts = self.layout_git_gutters(start_row..end_row, &snapshot); let mut max_visible_line_width = 0.0; let line_layouts = self.layout_lines(start_row..end_row, &snapshot, cx); @@ -1714,7 +1765,7 @@ impl Element for EditorElement { highlighted_rows, highlighted_ranges, line_number_layouts, - diff_hunks, + hunk_layouts, blocks, selections, context_menu, @@ -1848,11 +1899,11 @@ pub struct LayoutState { active_rows: BTreeMap, highlighted_rows: Option>, line_number_layouts: Vec>, + hunk_layouts: Vec, blocks: Vec, highlighted_ranges: Vec<(Range, Color)>, selections: Vec<(ReplicaId, Vec)>, context_menu: Option<(DisplayPoint, ElementBox)>, - diff_hunks: Vec>, code_actions_indicator: Option<(u32, ElementBox)>, hover_popovers: Option<(DisplayPoint, Vec)>, } From e744520d90883e0431b869772388808ac00a395f Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 12 Oct 2022 16:40:19 -0400 Subject: [PATCH 02/18] Correctly offset diff hunk layouts --- crates/editor/src/element.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 97d29a404a5b36da5125db7fcfa805096f6f6918..b2cf6a19f3843a8271da4075d7dd057001a18d7e 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -997,14 +997,16 @@ impl EditorElement { fn layout_diff_hunk( hunk: &DiffHunk, - buffer_rows: &mut std::iter::Peekable>>, + start_row: u32, + buffer_rows: &mut std::iter::Peekable)>>, ) -> DiffHunkLayout { - //This should start with a row which is contained in the hunk's buffer range - let visual_start = buffer_rows.peek().unwrap().unwrap(); + //`buffer_rows` should start with a row which is contained in the hunk's buffer range + //The `usize` field is 1-index so we have to sub to move it into 0-offset to match actual rows + let visual_start = start_row + buffer_rows.peek().unwrap().0 as u32 - 1; let mut visual_count = 0; while let Some(&buffer_row) = buffer_rows.peek() { - if let Some(buffer_row) = buffer_row { + if let (_, Some(buffer_row)) = buffer_row { if buffer_row == hunk.buffer_range.end { visual_count += 1; break; @@ -1039,16 +1041,17 @@ impl EditorElement { let mut buffer_rows = snapshot .buffer_rows(rows.start) .take((rows.end - rows.start) as usize) + .enumerate() .peekable(); let mut layouts = Vec::new(); - while let Some(buffer_row) = buffer_rows.next() { + while let Some((_, buffer_row)) = buffer_rows.next() { let buffer_row = buffer_row.unwrap(); if let Some(hunk) = diff_hunks.peek() { if hunk.buffer_range.contains(&buffer_row) { - layouts.push(Self::layout_diff_hunk(hunk, &mut buffer_rows)); + layouts.push(Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows)); diff_hunks.next(); } else if hunk.buffer_range.end < buffer_row { //A hunk that was missed due to being entirely contained in a fold @@ -1060,7 +1063,7 @@ impl EditorElement { status: DiffHunkStatus::Modified, }); diff_hunks.next(); - } + } } } From e75dcc853b2327119c7cc0aeefd7c40d7e2295e5 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 13 Oct 2022 00:42:53 -0400 Subject: [PATCH 03/18] Include deletion hunks in fold regardless of end --- crates/editor/src/element.rs | 51 +++++++++++++++++++++++++++--------- crates/git/src/diff.rs | 3 ++- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index b2cf6a19f3843a8271da4075d7dd057001a18d7e..853aeec01adcad9ff8f4cb80c4df312b008303ce 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -558,7 +558,7 @@ impl EditorElement { let offset = gutter_layout.line_height / 2.; let start_y = - row as f32 * gutter_layout.line_height + offset - gutter_layout.scroll_top; + row as f32 * gutter_layout.line_height - offset - gutter_layout.scroll_top; let end_y = start_y + gutter_layout.line_height; let width = diff_style.removed_width_em * gutter_layout.line_height; @@ -1045,26 +1045,51 @@ impl EditorElement { .peekable(); let mut layouts = Vec::new(); + let mut previous_buffer_row = None; - while let Some((_, buffer_row)) = buffer_rows.next() { + while let Some((idx, buffer_row)) = buffer_rows.next() { let buffer_row = buffer_row.unwrap(); - - if let Some(hunk) = diff_hunks.peek() { - if hunk.buffer_range.contains(&buffer_row) { - layouts.push(Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows)); + let is_start_of_fold = previous_buffer_row + .map(|prev| buffer_row > prev + 1) + .unwrap_or(false); + + if is_start_of_fold { + //Consume all hunks within fold + let mut consumed_hunks = false; + while let Some(hunk) = diff_hunks.peek() { + let is_past = hunk.buffer_range.start > buffer_row; + let is_removal = hunk.status() == DiffHunkStatus::Removed; + let is_on_next_line = hunk.buffer_range.start == buffer_row + 1; + let is_removal_inside = is_removal && is_on_next_line; + + if is_past && !is_removal_inside { + break; + } diff_hunks.next(); - } else if hunk.buffer_range.end < buffer_row { - //A hunk that was missed due to being entirely contained in a fold - //We can safely assume that the previous visual row is the fold - //TODO: If there is another hunk that ends inside the fold then - //this will overlay over, but right now that seems fine + consumed_hunks = true; + } + + //And mark fold as modified if there were any + if consumed_hunks { + let current_visual_row = rows.start + idx as u32 - 1; layouts.push(DiffHunkLayout { - visual_range: buffer_row - 1..buffer_row, + visual_range: current_visual_row..current_visual_row + 1, status: DiffHunkStatus::Modified, }); - diff_hunks.next(); + } + } else { + //Not the start of a fold + if let Some(hunk) = diff_hunks.peek() { + if hunk.buffer_range.contains(&buffer_row) + || hunk.buffer_range.start == buffer_row + { + layouts.push(Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows)); + diff_hunks.next(); + } } } + + previous_buffer_row = Some(buffer_row); } layouts diff --git a/crates/git/src/diff.rs b/crates/git/src/diff.rs index 4191e5d260ad41e0e4f86a66d639f5702d37eecb..3fcaaa64968b2862d09fc4d7def9a53f04473c7b 100644 --- a/crates/git/src/diff.rs +++ b/crates/git/src/diff.rs @@ -191,7 +191,6 @@ impl BufferDiff { } if kind == GitDiffLineType::Deletion { - *buffer_row_divergence -= 1; let end = content_offset + content_len; match &mut head_byte_range { @@ -204,6 +203,8 @@ impl BufferDiff { let row = old_row as i64 + *buffer_row_divergence; first_deletion_buffer_row = Some(row as u32); } + + *buffer_row_divergence -= 1; } } From a6a7e85894e569f0a0919c5d30e078c140f22016 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 13 Oct 2022 02:02:29 -0400 Subject: [PATCH 04/18] Misc fixes, still broken soft wrap --- crates/editor/src/element.rs | 50 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 853aeec01adcad9ff8f4cb80c4df312b008303ce..17dfabe57601c4e71591ad7857df3f6add628025 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -48,6 +48,7 @@ use std::{ }; use theme::DiffStyle; +#[derive(Debug)] struct DiffHunkLayout { visual_range: Range, status: DiffHunkStatus, @@ -995,18 +996,26 @@ impl EditorElement { .width() } + //-> (layout, buffer row advancement) fn layout_diff_hunk( hunk: &DiffHunk, start_row: u32, buffer_rows: &mut std::iter::Peekable)>>, - ) -> DiffHunkLayout { + ) -> (Option, u32) { //`buffer_rows` should start with a row which is contained in the hunk's buffer range + let first_buffer_rows = match buffer_rows.peek() { + Some(first_buffer_rows) => first_buffer_rows, + None => return (None, 0), + }; + //The `usize` field is 1-index so we have to sub to move it into 0-offset to match actual rows - let visual_start = start_row + buffer_rows.peek().unwrap().0 as u32 - 1; + let visual_start = start_row + first_buffer_rows.0 as u32 - 1; let mut visual_count = 0; + let mut buffer_row_advancement = 0; while let Some(&buffer_row) = buffer_rows.peek() { if let (_, Some(buffer_row)) = buffer_row { + buffer_row_advancement += 1; if buffer_row == hunk.buffer_range.end { visual_count += 1; break; @@ -1014,14 +1023,16 @@ impl EditorElement { break; } visual_count += 1; - buffer_rows.next(); } + + buffer_rows.next(); } - DiffHunkLayout { + let layout = DiffHunkLayout { visual_range: visual_start..visual_start + visual_count, status: hunk.status(), - } + }; + (Some(layout), buffer_row_advancement) } //Folds contained in a hunk are ignored apart from shrinking visual size @@ -1048,10 +1059,15 @@ impl EditorElement { let mut previous_buffer_row = None; while let Some((idx, buffer_row)) = buffer_rows.next() { - let buffer_row = buffer_row.unwrap(); + let buffer_row = match buffer_row { + Some(buffer_row) => buffer_row, + None => continue, + }; + let is_start_of_fold = previous_buffer_row .map(|prev| buffer_row > prev + 1) .unwrap_or(false); + previous_buffer_row = Some(buffer_row); if is_start_of_fold { //Consume all hunks within fold @@ -1077,19 +1093,21 @@ impl EditorElement { status: DiffHunkStatus::Modified, }); } - } else { - //Not the start of a fold - if let Some(hunk) = diff_hunks.peek() { - if hunk.buffer_range.contains(&buffer_row) - || hunk.buffer_range.start == buffer_row - { - layouts.push(Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows)); - diff_hunks.next(); + } else if let Some(hunk) = diff_hunks.peek() { + let row_inside_hunk = hunk.buffer_range.contains(&buffer_row); + let starts_on_row = hunk.buffer_range.start == buffer_row; + if row_inside_hunk || starts_on_row { + let (layout, buffer_row_advancement) = + Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows); + previous_buffer_row = Some(buffer_row + buffer_row_advancement); + + if let Some(layout) = layout { + layouts.push(layout); } + + diff_hunks.next(); } } - - previous_buffer_row = Some(buffer_row); } layouts From 9c47325c25f7b3aa30f33d9decf3d0c5d8d7313e Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 13 Oct 2022 13:52:44 -0400 Subject: [PATCH 05/18] Use correct range to get diff hunks in the presence of wrapped lines --- crates/editor/src/display_map/block_map.rs | 1 + crates/editor/src/display_map/fold_map.rs | 1 + crates/editor/src/display_map/wrap_map.rs | 1 + crates/editor/src/element.rs | 18 +++++++++++++++--- crates/editor/src/multi_buffer.rs | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index 210daccac26b54e057947457b52c4c749e2adb61..c60610997fb088320aec6908a3c24022a0d83d6b 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -157,6 +157,7 @@ pub struct BlockChunks<'a> { max_output_row: u32, } +#[derive(Clone)] pub struct BlockBufferRows<'a> { transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>, input_buffer_rows: wrap_map::WrapBufferRows<'a>, diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index c17cfa39f2a7292198a1c953339e315824fe73b8..756fb35950384f9f61c39db38456475557b4b85d 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -987,6 +987,7 @@ impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize { } } +#[derive(Clone)] pub struct FoldBufferRows<'a> { cursor: Cursor<'a, Transform, (FoldPoint, Point)>, input_buffer_rows: MultiBufferRows<'a>, diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index ee6ce2860ded8f830481258e5a8e4c59d7bbeba9..52f26ef2589c043877a56360934d072c14d15944 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -62,6 +62,7 @@ pub struct WrapChunks<'a> { transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>, } +#[derive(Clone)] pub struct WrapBufferRows<'a> { input_buffer_rows: fold_map::FoldBufferRows<'a>, input_buffer_row: Option, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 17dfabe57601c4e71591ad7857df3f6add628025..5b752e05447b1d0ccba5209745bcd0e683371d24 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1042,15 +1042,27 @@ impl EditorElement { rows: Range, snapshot: &EditorSnapshot, ) -> Vec { + let buffer_rows = snapshot.buffer_rows(rows.start); + let start_actual_row = match buffer_rows + .clone() + .take((rows.end - rows.start) as usize) + .find_map(|b| b) + { + Some(start_actual_row) => start_actual_row, + None => return Vec::new(), + }; + + //Get all hunks after our starting actual buffer row + //The loop is in terms of visual buffer rows so we simply + //return before touching any hunks past the end of the view let mut diff_hunks = snapshot .buffer_snapshot - .git_diff_hunks_in_range(rows.clone()) + .git_diff_hunks_in_range(start_actual_row..u32::MAX) .peekable(); //Some number followed by Nones for wrapped lines //Jump in number for folded lines - let mut buffer_rows = snapshot - .buffer_rows(rows.start) + let mut buffer_rows = buffer_rows .take((rows.end - rows.start) as usize) .enumerate() .peekable(); diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index a0eedb850c03b04ed9ccf879484f96553d13ac90..b2635712d96981653dfd49d6eb87f1cfc6fcce1d 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -143,6 +143,7 @@ struct ExcerptSummary { text: TextSummary, } +#[derive(Clone)] pub struct MultiBufferRows<'a> { buffer_row_range: Range, excerpts: Cursor<'a, Excerpt, Point>, From 16f854b63613c132f96f82a5c452542b66c46abf Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 13 Oct 2022 14:05:57 -0400 Subject: [PATCH 06/18] Expand diff gutter indicator to cover all of a wrapped line --- crates/editor/src/element.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 5b752e05447b1d0ccba5209745bcd0e683371d24..e5367e54f0a2055773a25beae09d44c71509d8a9 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1023,6 +1023,8 @@ impl EditorElement { break; } visual_count += 1; + } else { + visual_count += 1; } buffer_rows.next(); From 8d609959f1254e217b9cdd636d749f326691f4c5 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 13 Oct 2022 15:23:41 -0400 Subject: [PATCH 07/18] Clean --- crates/editor/src/element.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e5367e54f0a2055773a25beae09d44c71509d8a9..054c34515d3686bac5eaf0cf14f58ebaef728f43 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -539,11 +539,6 @@ impl EditorElement { bounds: RectF, } - struct DiffLayout<'a> { - buffer_row: u32, - last_diff: Option<&'a DiffHunk>, - } - fn diff_quad( hunk: &DiffHunkLayout, gutter_layout: &GutterLayout, @@ -605,11 +600,6 @@ impl EditorElement { } }; - let mut diff_layout = DiffLayout { - buffer_row: scroll_position.y() as u32, - last_diff: None, - }; - let diff_style = &cx.global::().theme.editor.diff.clone(); let show_gutter = matches!( &cx.global::() From dde3dfdbf6a334331735d9ea2de9dd9f62f0b5c5 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 13 Oct 2022 16:34:34 -0400 Subject: [PATCH 08/18] Quick cut of using display point conversion to layout hunks Co-Authored-By: Max Brunsfeld --- crates/editor/src/element.rs | 227 ++++++++++++++++------------------- 1 file changed, 106 insertions(+), 121 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 054c34515d3686bac5eaf0cf14f58ebaef728f43..e6f876028aecaaedcba29a1c7a51a0d37137d899 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -35,7 +35,7 @@ use gpui::{ WeakViewHandle, }; use json::json; -use language::{Bias, DiagnosticSeverity, OffsetUtf16, Selection}; +use language::{Bias, DiagnosticSeverity, OffsetUtf16, Point, Selection}; use project::ProjectPath; use settings::{GitGutter, Settings}; use smallvec::SmallVec; @@ -52,6 +52,7 @@ use theme::DiffStyle; struct DiffHunkLayout { visual_range: Range, status: DiffHunkStatus, + is_folded: bool, } struct SelectionLayout { @@ -544,12 +545,12 @@ impl EditorElement { gutter_layout: &GutterLayout, diff_style: &DiffStyle, ) -> Quad { - let color = match hunk.status { - DiffHunkStatus::Added => diff_style.inserted, - DiffHunkStatus::Modified => diff_style.modified, + let color = match (hunk.status, hunk.is_folded) { + (DiffHunkStatus::Added, false) => diff_style.inserted, + (DiffHunkStatus::Modified, false) => diff_style.modified, //TODO: This rendering is entirely a horrible hack - DiffHunkStatus::Removed => { + (DiffHunkStatus::Removed, false) => { let row = hunk.visual_range.start; let offset = gutter_layout.line_height / 2.; @@ -569,6 +570,24 @@ impl EditorElement { corner_radius: 1. * gutter_layout.line_height, }; } + + (_, true) => { + let row = hunk.visual_range.start; + let start_y = row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; + let end_y = start_y + gutter_layout.line_height; + + let width = diff_style.removed_width_em * gutter_layout.line_height; + let highlight_origin = gutter_layout.bounds.origin() + vec2f(-width, start_y); + let highlight_size = vec2f(width * 2., end_y - start_y); + let highlight_bounds = RectF::new(highlight_origin, highlight_size); + + return Quad { + bounds: highlight_bounds, + background: Some(diff_style.modified), + border: Border::new(0., Color::transparent_black()), + corner_radius: 1. * gutter_layout.line_height, + }; + } }; let start_row = hunk.visual_range.start; @@ -986,47 +1005,6 @@ impl EditorElement { .width() } - //-> (layout, buffer row advancement) - fn layout_diff_hunk( - hunk: &DiffHunk, - start_row: u32, - buffer_rows: &mut std::iter::Peekable)>>, - ) -> (Option, u32) { - //`buffer_rows` should start with a row which is contained in the hunk's buffer range - let first_buffer_rows = match buffer_rows.peek() { - Some(first_buffer_rows) => first_buffer_rows, - None => return (None, 0), - }; - - //The `usize` field is 1-index so we have to sub to move it into 0-offset to match actual rows - let visual_start = start_row + first_buffer_rows.0 as u32 - 1; - - let mut visual_count = 0; - let mut buffer_row_advancement = 0; - while let Some(&buffer_row) = buffer_rows.peek() { - if let (_, Some(buffer_row)) = buffer_row { - buffer_row_advancement += 1; - if buffer_row == hunk.buffer_range.end { - visual_count += 1; - break; - } else if buffer_row > hunk.buffer_range.end { - break; - } - visual_count += 1; - } else { - visual_count += 1; - } - - buffer_rows.next(); - } - - let layout = DiffHunkLayout { - visual_range: visual_start..visual_start + visual_count, - status: hunk.status(), - }; - (Some(layout), buffer_row_advancement) - } - //Folds contained in a hunk are ignored apart from shrinking visual size //If a fold contains any hunks then that fold line is marked as modified fn layout_git_gutters( @@ -1034,87 +1012,94 @@ impl EditorElement { rows: Range, snapshot: &EditorSnapshot, ) -> Vec { - let buffer_rows = snapshot.buffer_rows(rows.start); - let start_actual_row = match buffer_rows - .clone() - .take((rows.end - rows.start) as usize) - .find_map(|b| b) - { - Some(start_actual_row) => start_actual_row, - None => return Vec::new(), - }; - - //Get all hunks after our starting actual buffer row - //The loop is in terms of visual buffer rows so we simply - //return before touching any hunks past the end of the view - let mut diff_hunks = snapshot - .buffer_snapshot - .git_diff_hunks_in_range(start_actual_row..u32::MAX) - .peekable(); - - //Some number followed by Nones for wrapped lines - //Jump in number for folded lines - let mut buffer_rows = buffer_rows - .take((rows.end - rows.start) as usize) - .enumerate() - .peekable(); + let start_row = DisplayPoint::new(rows.start, 0).to_point(snapshot).row; + let end_row = DisplayPoint::new(rows.end, 0).to_point(snapshot).row; let mut layouts = Vec::new(); - let mut previous_buffer_row = None; - - while let Some((idx, buffer_row)) = buffer_rows.next() { - let buffer_row = match buffer_row { - Some(buffer_row) => buffer_row, - None => continue, - }; - - let is_start_of_fold = previous_buffer_row - .map(|prev| buffer_row > prev + 1) - .unwrap_or(false); - previous_buffer_row = Some(buffer_row); - - if is_start_of_fold { - //Consume all hunks within fold - let mut consumed_hunks = false; - while let Some(hunk) = diff_hunks.peek() { - let is_past = hunk.buffer_range.start > buffer_row; - let is_removal = hunk.status() == DiffHunkStatus::Removed; - let is_on_next_line = hunk.buffer_range.start == buffer_row + 1; - let is_removal_inside = is_removal && is_on_next_line; - - if is_past && !is_removal_inside { - break; - } - diff_hunks.next(); - consumed_hunks = true; - } - - //And mark fold as modified if there were any - if consumed_hunks { - let current_visual_row = rows.start + idx as u32 - 1; - layouts.push(DiffHunkLayout { - visual_range: current_visual_row..current_visual_row + 1, - status: DiffHunkStatus::Modified, - }); - } - } else if let Some(hunk) = diff_hunks.peek() { - let row_inside_hunk = hunk.buffer_range.contains(&buffer_row); - let starts_on_row = hunk.buffer_range.start == buffer_row; - if row_inside_hunk || starts_on_row { - let (layout, buffer_row_advancement) = - Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows); - previous_buffer_row = Some(buffer_row + buffer_row_advancement); - - if let Some(layout) = layout { - layouts.push(layout); - } + for hunk in snapshot + .buffer_snapshot + .git_diff_hunks_in_range(start_row..end_row) + { + let start = Point::new(hunk.buffer_range.start, 0).to_display_point(snapshot); + let end = Point::new(hunk.buffer_range.end, 0).to_display_point(snapshot); + let is_folded = start == end && snapshot.is_line_folded(start.row()); - diff_hunks.next(); - } + if let Some(hunk) = layouts.last_mut() { + // } + + layouts.push(DiffHunkLayout { + visual_range: start.row()..end.row(), + status: hunk.status(), + is_folded, + }); } - layouts + return layouts; + + //Some number followed by Nones for wrapped lines + //Jump in number for folded lines + // let mut buffer_rows = buffer_rows + // .take((rows.end - rows.start) as usize) + // .enumerate() + // .peekable(); + + // let mut layouts = Vec::new(); + // let mut previous_buffer_row = None; + + // while let Some((idx, buffer_row)) = buffer_rows.next() { + // let buffer_row = match buffer_row { + // Some(buffer_row) => buffer_row, + // None => continue, + // }; + + // let is_start_of_fold = previous_buffer_row + // .map(|prev| buffer_row > prev + 1) + // .unwrap_or(false); + // previous_buffer_row = Some(buffer_row); + + // if is_start_of_fold { + // //Consume all hunks within fold + // let mut consumed_hunks = false; + // while let Some(hunk) = diff_hunks.peek() { + // let is_past = hunk.buffer_range.start > buffer_row; + // let is_removal = hunk.status() == DiffHunkStatus::Removed; + // let is_on_next_line = hunk.buffer_range.start == buffer_row + 1; + // let is_removal_inside = is_removal && is_on_next_line; + + // if is_past && !is_removal_inside { + // break; + // } + // diff_hunks.next(); + // consumed_hunks = true; + // } + + // //And mark fold as modified if there were any + // if consumed_hunks { + // let current_visual_row = rows.start + idx as u32 - 1; + // layouts.push(DiffHunkLayout { + // visual_range: current_visual_row..current_visual_row + 1, + // status: DiffHunkStatus::Modified, + // }); + // } + // } else if let Some(hunk) = diff_hunks.peek() { + // let row_inside_hunk = hunk.buffer_range.contains(&buffer_row); + // let starts_on_row = hunk.buffer_range.start == buffer_row; + // if row_inside_hunk || starts_on_row { + // let (layout, buffer_row_advancement) = + // Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows); + // previous_buffer_row = Some(buffer_row + buffer_row_advancement); + + // if let Some(layout) = layout { + // layouts.push(layout); + // } + + // diff_hunks.next(); + // } + // } + // } + + // layouts } fn layout_line_numbers( From b3eb5f7cdf0b2b1875050524895f92048e1bb3e7 Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 14 Oct 2022 17:14:33 -0400 Subject: [PATCH 09/18] WIP Co-Authored-By: Kay Simmons --- crates/editor/src/element.rs | 103 +++++++++-------------------------- 1 file changed, 27 insertions(+), 76 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e6f876028aecaaedcba29a1c7a51a0d37137d899..e4b8a762de77f743e1d8681bea0a4f210eba02b1 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -12,7 +12,7 @@ use crate::{ CmdShiftChanged, GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink, }, mouse_context_menu::DeployMouseContextMenu, - EditorStyle, + AnchorRangeExt, EditorStyle, ToOffset, }; use clock::ReplicaId; use collections::{BTreeMap, HashMap}; @@ -1020,86 +1020,37 @@ impl EditorElement { .buffer_snapshot .git_diff_hunks_in_range(start_row..end_row) { - let start = Point::new(hunk.buffer_range.start, 0).to_display_point(snapshot); - let end = Point::new(hunk.buffer_range.end, 0).to_display_point(snapshot); - let is_folded = start == end && snapshot.is_line_folded(start.row()); - - if let Some(hunk) = layouts.last_mut() { - // - } + let start = Point::new(hunk.buffer_range.start, 0); + let hunk_content_end_row = hunk + .buffer_range + .end + .saturating_sub(1) + .max(hunk.buffer_range.start); + let hunk_content_end = Point::new( + hunk_content_end_row, + snapshot.buffer_snapshot.line_len(hunk_content_end_row), + ); + let end = Point::new(hunk.buffer_range.end, 0); + + let is_folded = snapshot + .folds_in_range(start..end) + .any(|fold_range| { + let fold_point_range = fold_range.to_point(&snapshot.buffer_snapshot); + dbg!(&fold_point_range); + fold_point_range.contains(dbg!(&start)) + && fold_point_range.contains(dbg!(&hunk_content_end)) + || fold_point_range.end == hunk_content_end + }); - layouts.push(DiffHunkLayout { - visual_range: start.row()..end.row(), + layouts.push(dbg!(DiffHunkLayout { + visual_range: start.to_display_point(snapshot).row() + ..end.to_display_point(snapshot).row(), status: hunk.status(), is_folded, - }); + })); } - return layouts; - - //Some number followed by Nones for wrapped lines - //Jump in number for folded lines - // let mut buffer_rows = buffer_rows - // .take((rows.end - rows.start) as usize) - // .enumerate() - // .peekable(); - - // let mut layouts = Vec::new(); - // let mut previous_buffer_row = None; - - // while let Some((idx, buffer_row)) = buffer_rows.next() { - // let buffer_row = match buffer_row { - // Some(buffer_row) => buffer_row, - // None => continue, - // }; - - // let is_start_of_fold = previous_buffer_row - // .map(|prev| buffer_row > prev + 1) - // .unwrap_or(false); - // previous_buffer_row = Some(buffer_row); - - // if is_start_of_fold { - // //Consume all hunks within fold - // let mut consumed_hunks = false; - // while let Some(hunk) = diff_hunks.peek() { - // let is_past = hunk.buffer_range.start > buffer_row; - // let is_removal = hunk.status() == DiffHunkStatus::Removed; - // let is_on_next_line = hunk.buffer_range.start == buffer_row + 1; - // let is_removal_inside = is_removal && is_on_next_line; - - // if is_past && !is_removal_inside { - // break; - // } - // diff_hunks.next(); - // consumed_hunks = true; - // } - - // //And mark fold as modified if there were any - // if consumed_hunks { - // let current_visual_row = rows.start + idx as u32 - 1; - // layouts.push(DiffHunkLayout { - // visual_range: current_visual_row..current_visual_row + 1, - // status: DiffHunkStatus::Modified, - // }); - // } - // } else if let Some(hunk) = diff_hunks.peek() { - // let row_inside_hunk = hunk.buffer_range.contains(&buffer_row); - // let starts_on_row = hunk.buffer_range.start == buffer_row; - // if row_inside_hunk || starts_on_row { - // let (layout, buffer_row_advancement) = - // Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows); - // previous_buffer_row = Some(buffer_row + buffer_row_advancement); - - // if let Some(layout) = layout { - // layouts.push(layout); - // } - - // diff_hunks.next(); - // } - // } - // } - - // layouts + layouts } fn layout_line_numbers( From f1ff557a25d244929f438771d86585b084625d35 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Sun, 16 Oct 2022 17:31:19 -0700 Subject: [PATCH 10/18] Rearranged mouse handling --- crates/terminal/src/terminal.rs | 76 +++++++++++++++------------------ 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 5485fb50ca2a94ad43d6e5dab5e7423be4946e3c..735b00ca62faf3be18d858cd0695b48fdc53decf 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -1018,55 +1018,34 @@ impl Terminal { self.last_content.size, self.last_content.display_offset, ); - // let side = mouse_side(position, self.last_content.size); if self.mouse_mode(e.shift) { if let Some(bytes) = mouse_button_report(point, e, true, self.last_content.mode) { self.pty_tx.notify(bytes); } } else if e.button == MouseButton::Left { - self.left_click(e, origin) - } - } - - pub fn left_click(&mut self, e: &DownRegionEvent, origin: Vector2F) { - let position = e.position.sub(origin); - if !self.mouse_mode(e.shift) { - //Hyperlinks - { - let mouse_cell_index = content_index_for_mouse(position, &self.last_content); - if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() { - open_uri(link.uri()).log_err(); - } else { - self.events - .push_back(InternalEvent::FindHyperlink(position, true)); - } - } + let position = e.position.sub(origin); + let point = grid_point( + position, + self.last_content.size, + self.last_content.display_offset, + ); + let side = mouse_side(position, self.last_content.size); - // Selections - { - let point = grid_point( - position, - self.last_content.size, - self.last_content.display_offset, - ); - let side = mouse_side(position, self.last_content.size); - - let selection_type = match e.click_count { - 0 => return, //This is a release - 1 => Some(SelectionType::Simple), - 2 => Some(SelectionType::Semantic), - 3 => Some(SelectionType::Lines), - _ => None, - }; + let selection_type = match e.click_count { + 0 => return, //This is a release + 1 => Some(SelectionType::Simple), + 2 => Some(SelectionType::Semantic), + 3 => Some(SelectionType::Lines), + _ => None, + }; - let selection = selection_type - .map(|selection_type| Selection::new(selection_type, point, side)); + let selection = + selection_type.map(|selection_type| Selection::new(selection_type, point, side)); - if let Some(sel) = selection { - self.events - .push_back(InternalEvent::SetSelection(Some((sel, point)))); - } + if let Some(sel) = selection { + self.events + .push_back(InternalEvent::SetSelection(Some((sel, point)))); } } } @@ -1094,8 +1073,21 @@ impl Terminal { if let Some(bytes) = mouse_button_report(point, e, false, self.last_content.mode) { self.pty_tx.notify(bytes); } - } else if e.button == MouseButton::Left && copy_on_select { - self.copy(); + } else { + if e.button == MouseButton::Left && copy_on_select { + self.copy(); + } + + //Hyperlinks + if self.selection_phase == SelectionPhase::Ended { + let mouse_cell_index = content_index_for_mouse(position, &self.last_content); + if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() { + open_uri(link.uri()).log_err(); + } else { + self.events + .push_back(InternalEvent::FindHyperlink(position, true)); + } + } } self.selection_phase = SelectionPhase::Ended; From 50ae3e03f75b25df64879634fe392f7165cc086b Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 17 Oct 2022 12:28:44 -0400 Subject: [PATCH 11/18] More concrete usage of display map to handle diff hunk gutter layout --- crates/editor/src/element.rs | 70 +++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e4b8a762de77f743e1d8681bea0a4f210eba02b1..f7d01bdb58731f61a4abc021e5026e13732e9131 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1012,42 +1012,48 @@ impl EditorElement { rows: Range, snapshot: &EditorSnapshot, ) -> Vec { - let start_row = DisplayPoint::new(rows.start, 0).to_point(snapshot).row; - let end_row = DisplayPoint::new(rows.end, 0).to_point(snapshot).row; + let buffer_snapshot = &snapshot.buffer_snapshot; + let visual_start = DisplayPoint::new(rows.start, 0).to_point(snapshot).row; + let visual_end = DisplayPoint::new(rows.end, 0).to_point(snapshot).row; + let hunks = buffer_snapshot.git_diff_hunks_in_range(visual_start..visual_end); let mut layouts = Vec::new(); - for hunk in snapshot - .buffer_snapshot - .git_diff_hunks_in_range(start_row..end_row) - { - let start = Point::new(hunk.buffer_range.start, 0); - let hunk_content_end_row = hunk - .buffer_range - .end - .saturating_sub(1) - .max(hunk.buffer_range.start); - let hunk_content_end = Point::new( - hunk_content_end_row, - snapshot.buffer_snapshot.line_len(hunk_content_end_row), - ); - let end = Point::new(hunk.buffer_range.end, 0); - - let is_folded = snapshot - .folds_in_range(start..end) - .any(|fold_range| { - let fold_point_range = fold_range.to_point(&snapshot.buffer_snapshot); - dbg!(&fold_point_range); - fold_point_range.contains(dbg!(&start)) - && fold_point_range.contains(dbg!(&hunk_content_end)) - || fold_point_range.end == hunk_content_end - }); - layouts.push(dbg!(DiffHunkLayout { - visual_range: start.to_display_point(snapshot).row() - ..end.to_display_point(snapshot).row(), + for hunk in hunks { + let hunk_start_point = Point::new(hunk.buffer_range.start, 0); + let hunk_end_point = Point::new(hunk.buffer_range.end, 0); + let hunk_moved_start_point = Point::new(hunk.buffer_range.start.saturating_sub(1), 0); + + let is_removal = hunk.status() == DiffHunkStatus::Removed; + + let folds_start = Point::new(hunk.buffer_range.start.saturating_sub(1), 0); + let folds_end = Point::new(hunk.buffer_range.end + 1, 0); + let folds_range = folds_start..folds_end; + + let containing_fold = snapshot.folds_in_range(folds_range).find(|fold_range| { + let fold_point_range = fold_range.to_point(buffer_snapshot); + + let folded_start = fold_point_range.contains(&hunk_start_point); + let folded_end = fold_point_range.contains(&hunk_end_point); + let folded_moved_start = fold_point_range.contains(&hunk_moved_start_point); + + (folded_start && folded_end) || (is_removal && folded_moved_start) + }); + + let visual_range = if let Some(fold) = containing_fold { + let row = fold.start.to_display_point(snapshot).row(); + row..row + } else { + let start = hunk_start_point.to_display_point(snapshot).row(); + let end = hunk_end_point.to_display_point(snapshot).row(); + start..end + }; + + layouts.push(DiffHunkLayout { + visual_range, status: hunk.status(), - is_folded, - })); + is_folded: containing_fold.is_some(), + }); } layouts From be34c50c72d0da2bc67f041c84a49e80b38077bb Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 17 Oct 2022 12:41:20 -0400 Subject: [PATCH 12/18] Deduplicate identical hunk layouts --- crates/editor/src/element.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index f7d01bdb58731f61a4abc021e5026e13732e9131..e5a9f8f756e1cc6897a5f04c72e4ef671ffc0d1c 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1017,7 +1017,7 @@ impl EditorElement { let visual_end = DisplayPoint::new(rows.end, 0).to_point(snapshot).row; let hunks = buffer_snapshot.git_diff_hunks_in_range(visual_start..visual_end); - let mut layouts = Vec::new(); + let mut layouts = Vec::::new(); for hunk in hunks { let hunk_start_point = Point::new(hunk.buffer_range.start, 0); @@ -1049,11 +1049,18 @@ impl EditorElement { start..end }; - layouts.push(DiffHunkLayout { - visual_range, - status: hunk.status(), - is_folded: containing_fold.is_some(), - }); + let has_existing_layout = match layouts.last() { + Some(e) => visual_range == e.visual_range && e.status == hunk.status(), + None => false, + }; + + if !has_existing_layout { + layouts.push(DiffHunkLayout { + visual_range, + status: hunk.status(), + is_folded: containing_fold.is_some(), + }); + } } layouts From 2a5d7ea2dea1eeb7ddfbe343c25d0784678ba6e7 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 17 Oct 2022 13:11:11 -0400 Subject: [PATCH 13/18] Inclusively check for hunk in fold range --- crates/editor/src/element.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e5a9f8f756e1cc6897a5f04c72e4ef671ffc0d1c..3da475351095469a749973bc8856c1438dda1e0f 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1022,7 +1022,14 @@ impl EditorElement { for hunk in hunks { let hunk_start_point = Point::new(hunk.buffer_range.start, 0); let hunk_end_point = Point::new(hunk.buffer_range.end, 0); - let hunk_moved_start_point = Point::new(hunk.buffer_range.start.saturating_sub(1), 0); + let hunk_start_point_sub = Point::new(hunk.buffer_range.start.saturating_sub(1), 0); + let hunk_end_point_sub = Point::new( + hunk.buffer_range + .end + .saturating_sub(1) + .max(hunk.buffer_range.start), + 0, + ); let is_removal = hunk.status() == DiffHunkStatus::Removed; @@ -1032,12 +1039,13 @@ impl EditorElement { let containing_fold = snapshot.folds_in_range(folds_range).find(|fold_range| { let fold_point_range = fold_range.to_point(buffer_snapshot); + let fold_point_range = fold_point_range.start..=fold_point_range.end; let folded_start = fold_point_range.contains(&hunk_start_point); - let folded_end = fold_point_range.contains(&hunk_end_point); - let folded_moved_start = fold_point_range.contains(&hunk_moved_start_point); + let folded_end = fold_point_range.contains(&hunk_end_point_sub); + let folded_start_sub = fold_point_range.contains(&hunk_start_point_sub); - (folded_start && folded_end) || (is_removal && folded_moved_start) + (folded_start && folded_end) || (is_removal && folded_start_sub) }); let visual_range = if let Some(fold) = containing_fold { From 1716aff9697133b9b3a72ab27e71895791a3aa03 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 17 Oct 2022 14:41:16 -0400 Subject: [PATCH 14/18] Cleanup --- crates/editor/src/element.rs | 176 ++++++++++++++--------------------- 1 file changed, 72 insertions(+), 104 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 3da475351095469a749973bc8856c1438dda1e0f..3a686fd5bf9cc13c67078c597db0587e7dd04440 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -12,11 +12,11 @@ use crate::{ CmdShiftChanged, GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink, }, mouse_context_menu::DeployMouseContextMenu, - AnchorRangeExt, EditorStyle, ToOffset, + AnchorRangeExt, EditorStyle, }; use clock::ReplicaId; use collections::{BTreeMap, HashMap}; -use git::diff::{DiffHunk, DiffHunkStatus}; +use git::diff::DiffHunkStatus; use gpui::{ color::Color, elements::*, @@ -46,7 +46,6 @@ use std::{ ops::Range, sync::Arc, }; -use theme::DiffStyle; #[derive(Debug)] struct DiffHunkLayout { @@ -533,18 +532,52 @@ impl EditorElement { layout: &mut LayoutState, cx: &mut PaintContext, ) { - struct GutterLayout { - line_height: f32, - // scroll_position: Vector2F, - scroll_top: f32, - bounds: RectF, + let line_height = layout.position_map.line_height; + + let scroll_position = layout.position_map.snapshot.scroll_position(); + let scroll_top = scroll_position.y() * line_height; + + let show_gutter = matches!( + &cx.global::() + .git_overrides + .git_gutter + .unwrap_or_default(), + GitGutter::TrackedFiles + ); + + if show_gutter { + Self::paint_diff_hunks(bounds, layout, cx); + } + + for (ix, line) in layout.line_number_layouts.iter().enumerate() { + if let Some(line) = line { + let line_origin = bounds.origin() + + vec2f( + bounds.width() - line.width() - layout.gutter_padding, + ix as f32 * line_height - (scroll_top % line_height), + ); + + line.paint(line_origin, visible_bounds, line_height, cx); + } } - fn diff_quad( - hunk: &DiffHunkLayout, - gutter_layout: &GutterLayout, - diff_style: &DiffStyle, - ) -> Quad { + if let Some((row, indicator)) = layout.code_actions_indicator.as_mut() { + let mut x = bounds.width() - layout.gutter_padding; + let mut y = *row as f32 * line_height - scroll_top; + x += ((layout.gutter_padding + layout.gutter_margin) - indicator.size().x()) / 2.; + y += (line_height - indicator.size().y()) / 2.; + indicator.paint(bounds.origin() + vec2f(x, y), visible_bounds, cx); + } + } + + fn paint_diff_hunks(bounds: RectF, layout: &mut LayoutState, cx: &mut PaintContext) { + let diff_style = &cx.global::().theme.editor.diff.clone(); + let line_height = layout.position_map.line_height; + + let scroll_position = layout.position_map.snapshot.scroll_position(); + let scroll_top = scroll_position.y() * line_height; + + for hunk in &layout.hunk_layouts { let color = match (hunk.status, hunk.is_folded) { (DiffHunkStatus::Added, false) => diff_style.inserted, (DiffHunkStatus::Modified, false) => diff_style.modified, @@ -553,107 +586,63 @@ impl EditorElement { (DiffHunkStatus::Removed, false) => { let row = hunk.visual_range.start; - let offset = gutter_layout.line_height / 2.; - let start_y = - row as f32 * gutter_layout.line_height - offset - gutter_layout.scroll_top; - let end_y = start_y + gutter_layout.line_height; + let offset = line_height / 2.; + let start_y = row as f32 * line_height - offset - scroll_top; + let end_y = start_y + line_height; - let width = diff_style.removed_width_em * gutter_layout.line_height; - let highlight_origin = gutter_layout.bounds.origin() + vec2f(-width, start_y); + let width = diff_style.removed_width_em * line_height; + let highlight_origin = bounds.origin() + vec2f(-width, start_y); let highlight_size = vec2f(width * 2., end_y - start_y); let highlight_bounds = RectF::new(highlight_origin, highlight_size); - return Quad { + cx.scene.push_quad(Quad { bounds: highlight_bounds, background: Some(diff_style.deleted), border: Border::new(0., Color::transparent_black()), - corner_radius: 1. * gutter_layout.line_height, - }; + corner_radius: 1. * line_height, + }); + + continue; } (_, true) => { let row = hunk.visual_range.start; - let start_y = row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; - let end_y = start_y + gutter_layout.line_height; + let start_y = row as f32 * line_height - scroll_top; + let end_y = start_y + line_height; - let width = diff_style.removed_width_em * gutter_layout.line_height; - let highlight_origin = gutter_layout.bounds.origin() + vec2f(-width, start_y); + let width = diff_style.removed_width_em * line_height; + let highlight_origin = bounds.origin() + vec2f(-width, start_y); let highlight_size = vec2f(width * 2., end_y - start_y); let highlight_bounds = RectF::new(highlight_origin, highlight_size); - return Quad { + cx.scene.push_quad(Quad { bounds: highlight_bounds, background: Some(diff_style.modified), border: Border::new(0., Color::transparent_black()), - corner_radius: 1. * gutter_layout.line_height, - }; + corner_radius: 1. * line_height, + }); + + continue; } }; let start_row = hunk.visual_range.start; let end_row = hunk.visual_range.end; - let start_y = start_row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; - let end_y = end_row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; + let start_y = start_row as f32 * line_height - scroll_top; + let end_y = end_row as f32 * line_height - scroll_top; - let width = diff_style.width_em * gutter_layout.line_height; - let highlight_origin = gutter_layout.bounds.origin() + vec2f(-width, start_y); + let width = diff_style.width_em * line_height; + let highlight_origin = bounds.origin() + vec2f(-width, start_y); let highlight_size = vec2f(width * 2., end_y - start_y); let highlight_bounds = RectF::new(highlight_origin, highlight_size); - Quad { + cx.scene.push_quad(Quad { bounds: highlight_bounds, background: Some(color), border: Border::new(0., Color::transparent_black()), - corner_radius: diff_style.corner_radius * gutter_layout.line_height, - } - } - - let scroll_position = layout.position_map.snapshot.scroll_position(); - let gutter_layout = { - let line_height = layout.position_map.line_height; - GutterLayout { - scroll_top: scroll_position.y() * line_height, - line_height, - bounds, - } - }; - - let diff_style = &cx.global::().theme.editor.diff.clone(); - let show_gutter = matches!( - &cx.global::() - .git_overrides - .git_gutter - .unwrap_or_default(), - GitGutter::TrackedFiles - ); - - if show_gutter { - for hunk in &layout.hunk_layouts { - let quad = diff_quad(hunk, &gutter_layout, diff_style); - cx.scene.push_quad(quad); - } - } - - for (ix, line) in layout.line_number_layouts.iter().enumerate() { - if let Some(line) = line { - let line_origin = bounds.origin() - + vec2f( - bounds.width() - line.width() - layout.gutter_padding, - ix as f32 * gutter_layout.line_height - - (gutter_layout.scroll_top % gutter_layout.line_height), - ); - - line.paint(line_origin, visible_bounds, gutter_layout.line_height, cx); - } - } - - if let Some((row, indicator)) = layout.code_actions_indicator.as_mut() { - let mut x = bounds.width() - layout.gutter_padding; - let mut y = *row as f32 * gutter_layout.line_height - gutter_layout.scroll_top; - x += ((layout.gutter_padding + layout.gutter_margin) - indicator.size().x()) / 2.; - y += (gutter_layout.line_height - indicator.size().y()) / 2.; - indicator.paint(bounds.origin() + vec2f(x, y), visible_bounds, cx); + corner_radius: diff_style.corner_radius * line_height, + }); } } @@ -1426,27 +1415,6 @@ impl EditorElement { } } -/// Get the hunk that contains buffer_line, starting from start_idx -/// Returns none if there is none found, and -fn get_hunk(hunks: &[DiffHunk], buffer_line: u32) -> Option<&DiffHunk> { - for i in 0..hunks.len() { - // Safety: Index out of bounds is handled by the check above - let hunk = hunks.get(i).unwrap(); - if hunk.buffer_range.contains(&(buffer_line as u32)) { - return Some(hunk); - } else if hunk.status() == DiffHunkStatus::Removed && buffer_line == hunk.buffer_range.start - { - return Some(hunk); - } else if hunk.buffer_range.start > buffer_line as u32 { - // If we've passed the buffer_line, just stop - return None; - } - } - - // We reached the end of the array without finding a hunk, just return none. - return None; -} - impl Element for EditorElement { type LayoutState = LayoutState; type PaintState = (); From 40c3e925ad5bc8b23a3c320cdc8312f5e2b989d1 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Sat, 15 Oct 2022 15:08:21 -0700 Subject: [PATCH 15/18] Add cursor blink setting and replicate cursor shape to remote collaborators --- Cargo.lock | 1 + assets/settings/default.json | 2 + crates/editor/src/editor.rs | 24 +++++++--- crates/editor/src/element.rs | 60 ++++++++++--------------- crates/editor/src/items.rs | 1 + crates/editor/src/multi_buffer.rs | 10 +++-- crates/language/src/buffer.rs | 21 ++++++++- crates/language/src/buffer_tests.rs | 4 +- crates/language/src/proto.rs | 27 ++++++++++- crates/rpc/proto/zed.proto | 9 ++++ crates/settings/src/settings.rs | 7 +++ crates/terminal/Cargo.toml | 13 +++--- crates/terminal/src/terminal_element.rs | 3 +- crates/vim/src/state.rs | 2 +- crates/vim/src/vim.rs | 3 +- 15 files changed, 126 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a399ad4ad62342071c598126fc3ec9e01d94dff..188113a66d4772eb94afb9ad040c5b99334a0cb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5828,6 +5828,7 @@ dependencies = [ "futures 0.3.24", "gpui", "itertools", + "language", "lazy_static", "libc", "mio-extras", diff --git a/assets/settings/default.json b/assets/settings/default.json index 2ccd2c5f973b4578d62b1639c643c75d020f5a60..57f76f5f21904af012cbfcaa73cb0b4d78fb5db5 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -69,6 +69,8 @@ // The column at which to soft-wrap lines, for buffers where soft-wrap // is enabled. "preferred_line_length": 80, + // Whether the cursor blinks in the editor. + "cursor_blink": true, // Whether to indent lines using tab characters, as opposed to multiple // spaces. "hard_tabs": false, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 070fc69f7ebcfe1d974b2db2bccf5d45c19af200..901547db2e4e31dc3d95992a1c9171a8d85dc30f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -42,9 +42,9 @@ use hover_popover::{hide_hover, HoverState}; pub use items::MAX_TAB_TITLE_LEN; pub use language::{char_kind, CharKind}; use language::{ - AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, Diagnostic, - DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Point, - Selection, SelectionGoal, TransactionId, + AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, CursorShape, + Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, + Point, Selection, SelectionGoal, TransactionId, }; use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState}; pub use multi_buffer::{ @@ -1478,6 +1478,7 @@ impl Editor { buffer.set_active_selections( &self.selections.disjoint_anchors(), self.selections.line_mode, + self.cursor_shape, cx, ) }); @@ -6145,7 +6146,17 @@ impl Editor { fn blink_cursors(&mut self, epoch: usize, cx: &mut ViewContext) { if epoch == self.blink_epoch && self.focused && !self.blinking_paused { - self.show_local_cursors = !self.show_local_cursors; + let newest_head = self.selections.newest::(cx).head(); + let language_name = self + .buffer + .read(cx) + .language_at(newest_head, cx) + .map(|l| l.name()); + + self.show_local_cursors = !self.show_local_cursors + || !cx + .global::() + .cursor_blink(language_name.as_deref()); cx.notify(); let epoch = self.next_blink_epoch(); @@ -6466,9 +6477,7 @@ impl View for Editor { } Stack::new() - .with_child( - EditorElement::new(self.handle.clone(), style.clone(), self.cursor_shape).boxed(), - ) + .with_child(EditorElement::new(self.handle.clone(), style.clone()).boxed()) .with_child(ChildView::new(&self.mouse_context_menu, cx).boxed()) .boxed() } @@ -6491,6 +6500,7 @@ impl View for Editor { buffer.set_active_selections( &self.selections.disjoint_anchors(), self.selections.line_mode, + self.cursor_shape, cx, ); } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 3e68c6766f92d57c33eac323f84ae32c182dfb34..d2090741d803ed316e5325987828df0a4b291ca4 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -35,7 +35,7 @@ use gpui::{ WeakViewHandle, }; use json::json; -use language::{Bias, DiagnosticSeverity, OffsetUtf16, Point, Selection}; +use language::{Bias, CursorShape, DiagnosticSeverity, OffsetUtf16, Point, Selection}; use project::ProjectPath; use settings::{GitGutter, Settings}; use smallvec::SmallVec; @@ -56,6 +56,7 @@ struct DiffHunkLayout { struct SelectionLayout { head: DisplayPoint, + cursor_shape: CursorShape, range: Range, } @@ -63,6 +64,7 @@ impl SelectionLayout { fn new( selection: Selection, line_mode: bool, + cursor_shape: CursorShape, map: &DisplaySnapshot, ) -> Self { if line_mode { @@ -70,6 +72,7 @@ impl SelectionLayout { let point_range = map.expand_to_line(selection.range()); Self { head: selection.head().to_display_point(map), + cursor_shape, range: point_range.start.to_display_point(map) ..point_range.end.to_display_point(map), } @@ -77,6 +80,7 @@ impl SelectionLayout { let selection = selection.map(|p| p.to_display_point(map)); Self { head: selection.head(), + cursor_shape, range: selection.range(), } } @@ -87,19 +91,13 @@ impl SelectionLayout { pub struct EditorElement { view: WeakViewHandle, style: Arc, - cursor_shape: CursorShape, } impl EditorElement { - pub fn new( - view: WeakViewHandle, - style: EditorStyle, - cursor_shape: CursorShape, - ) -> Self { + pub fn new(view: WeakViewHandle, style: EditorStyle) -> Self { Self { view, style: Arc::new(style), - cursor_shape, } } @@ -723,7 +721,7 @@ impl EditorElement { if block_width == 0.0 { block_width = layout.position_map.em_width; } - let block_text = if let CursorShape::Block = self.cursor_shape { + let block_text = if let CursorShape::Block = selection.cursor_shape { layout .position_map .snapshot @@ -759,7 +757,7 @@ impl EditorElement { block_width, origin: vec2f(x, y), line_height: layout.position_map.line_height, - shape: self.cursor_shape, + shape: selection.cursor_shape, block_text, }); } @@ -1648,7 +1646,7 @@ impl Element for EditorElement { ); let mut remote_selections = HashMap::default(); - for (replica_id, line_mode, selection) in display_map + for (replica_id, line_mode, cursor_shape, selection) in display_map .buffer_snapshot .remote_selections_in_range(&(start_anchor.clone()..end_anchor.clone())) { @@ -1659,7 +1657,12 @@ impl Element for EditorElement { remote_selections .entry(replica_id) .or_insert(Vec::new()) - .push(SelectionLayout::new(selection, line_mode, &display_map)); + .push(SelectionLayout::new( + selection, + line_mode, + cursor_shape, + &display_map, + )); } selections.extend(remote_selections); @@ -1691,7 +1694,12 @@ impl Element for EditorElement { local_selections .into_iter() .map(|selection| { - SelectionLayout::new(selection, view.selections.line_mode, &display_map) + SelectionLayout::new( + selection, + view.selections.line_mode, + view.cursor_shape, + &display_map, + ) }) .collect(), )); @@ -2094,20 +2102,6 @@ fn layout_line( ) } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum CursorShape { - Bar, - Block, - Underscore, - Hollow, -} - -impl Default for CursorShape { - fn default() -> Self { - CursorShape::Bar - } -} - #[derive(Debug)] pub struct Cursor { origin: Vector2F, @@ -2348,11 +2342,7 @@ mod tests { let (window_id, editor) = cx.add_window(Default::default(), |cx| { Editor::new(EditorMode::Full, buffer, None, None, cx) }); - let element = EditorElement::new( - editor.downgrade(), - editor.read(cx).style(cx), - CursorShape::Bar, - ); + let element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx)); let layouts = editor.update(cx, |editor, cx| { let snapshot = editor.snapshot(cx); @@ -2388,11 +2378,7 @@ mod tests { cx.blur(); }); - let mut element = EditorElement::new( - editor.downgrade(), - editor.read(cx).style(cx), - CursorShape::Bar, - ); + let mut element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx)); let mut scene = Scene::new(1.0); let mut presenter = cx.build_presenter(window_id, 30., Default::default()); diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index e6a4eebffb0cb3587761855028411182fe7aac25..cf69d2a9228637296d536b3e3e76c87187c9fbdf 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -120,6 +120,7 @@ impl FollowableItem for Editor { buffer.set_active_selections( &self.selections.disjoint_anchors(), self.selections.line_mode, + self.cursor_shape, cx, ); } diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 448564ed9808e40fcf9e2fa515a881308ce4937f..1cff0038686f88c27816124d850eece8427ae864 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -8,7 +8,7 @@ use git::diff::DiffHunk; use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task}; pub use language::Completion; use language::{ - char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, + char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, CursorShape, DiagnosticEntry, Event, File, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point, PointUtf16, Selection, TextDimension, ToOffset as _, ToOffsetUtf16 as _, ToPoint as _, ToPointUtf16 as _, TransactionId, @@ -604,6 +604,7 @@ impl MultiBuffer { &mut self, selections: &[Selection], line_mode: bool, + cursor_shape: CursorShape, cx: &mut ModelContext, ) { let mut selections_by_buffer: HashMap>> = @@ -668,7 +669,7 @@ impl MultiBuffer { } Some(selection) })); - buffer.set_active_selections(merged_selections, line_mode, cx); + buffer.set_active_selections(merged_selections, line_mode, cursor_shape, cx); }); } } @@ -2698,7 +2699,7 @@ impl MultiBufferSnapshot { pub fn remote_selections_in_range<'a>( &'a self, range: &'a Range, - ) -> impl 'a + Iterator)> { + ) -> impl 'a + Iterator)> { let mut cursor = self.excerpts.cursor::>(); cursor.seek(&Some(&range.start.excerpt_id), Bias::Left, &()); cursor @@ -2715,7 +2716,7 @@ impl MultiBufferSnapshot { excerpt .buffer .remote_selections_in_range(query_range) - .flat_map(move |(replica_id, line_mode, selections)| { + .flat_map(move |(replica_id, line_mode, cursor_shape, selections)| { selections.map(move |selection| { let mut start = Anchor { buffer_id: Some(excerpt.buffer_id), @@ -2737,6 +2738,7 @@ impl MultiBufferSnapshot { ( replica_id, line_mode, + cursor_shape, Selection { id: selection.id, start, diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 274777b81cbf5531288f81e03523f515b53a0eda..da7bd5332487f8fc07c68bdf42e9b6ba547ec7a4 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -111,9 +111,19 @@ pub enum IndentKind { Tab, } +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] +pub enum CursorShape { + #[default] + Bar, + Block, + Underscore, + Hollow, +} + #[derive(Clone, Debug)] struct SelectionSet { line_mode: bool, + cursor_shape: CursorShape, selections: Arc<[Selection]>, lamport_timestamp: clock::Lamport, } @@ -161,6 +171,7 @@ pub enum Operation { selections: Arc<[Selection]>, lamport_timestamp: clock::Lamport, line_mode: bool, + cursor_shape: CursorShape, }, UpdateCompletionTriggers { triggers: Vec, @@ -395,6 +406,7 @@ impl Buffer { selections: set.selections.clone(), lamport_timestamp: set.lamport_timestamp, line_mode: set.line_mode, + cursor_shape: set.cursor_shape, }) })); operations.push(proto::serialize_operation(&Operation::UpdateDiagnostics { @@ -1227,6 +1239,7 @@ impl Buffer { &mut self, selections: Arc<[Selection]>, line_mode: bool, + cursor_shape: CursorShape, cx: &mut ModelContext, ) { let lamport_timestamp = self.text.lamport_clock.tick(); @@ -1236,6 +1249,7 @@ impl Buffer { selections: selections.clone(), lamport_timestamp, line_mode, + cursor_shape, }, ); self.send_operation( @@ -1243,13 +1257,14 @@ impl Buffer { selections, line_mode, lamport_timestamp, + cursor_shape, }, cx, ); } pub fn remove_active_selections(&mut self, cx: &mut ModelContext) { - self.set_active_selections(Arc::from([]), false, cx); + self.set_active_selections(Arc::from([]), false, Default::default(), cx); } pub fn set_text(&mut self, text: T, cx: &mut ModelContext) -> Option @@ -1474,6 +1489,7 @@ impl Buffer { selections, lamport_timestamp, line_mode, + cursor_shape, } => { if let Some(set) = self.remote_selections.get(&lamport_timestamp.replica_id) { if set.lamport_timestamp > lamport_timestamp { @@ -1487,6 +1503,7 @@ impl Buffer { selections, lamport_timestamp, line_mode, + cursor_shape, }, ); self.text.lamport_clock.observe(lamport_timestamp); @@ -2236,6 +2253,7 @@ impl BufferSnapshot { Item = ( ReplicaId, bool, + CursorShape, impl Iterator> + '_, ), > + '_ { @@ -2259,6 +2277,7 @@ impl BufferSnapshot { ( *replica_id, set.line_mode, + set.cursor_shape, set.selections[start_ix..end_ix].iter(), ) }) diff --git a/crates/language/src/buffer_tests.rs b/crates/language/src/buffer_tests.rs index 0f3ab50f4adf2daae6828479cf4cd5879615fddb..f1b51f7e021368d93a99f9addd9d223a7e3934ab 100644 --- a/crates/language/src/buffer_tests.rs +++ b/crates/language/src/buffer_tests.rs @@ -1283,7 +1283,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) { selections ); active_selections.insert(replica_id, selections.clone()); - buffer.set_active_selections(selections, false, cx); + buffer.set_active_selections(selections, false, Default::default(), cx); }); mutation_count -= 1; } @@ -1448,7 +1448,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) { let buffer = buffer.read(cx).snapshot(); let actual_remote_selections = buffer .remote_selections_in_range(Anchor::MIN..Anchor::MAX) - .map(|(replica_id, _, selections)| (replica_id, selections.collect::>())) + .map(|(replica_id, _, _, selections)| (replica_id, selections.collect::>())) .collect::>(); let expected_remote_selections = active_selections .iter() diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rs index 9e3ee7d46b17790cb0af121dade9edea27eb301f..f93d99f76b02a86a0267d2355a7c85cccda60b70 100644 --- a/crates/language/src/proto.rs +++ b/crates/language/src/proto.rs @@ -1,5 +1,6 @@ use crate::{ - diagnostic_set::DiagnosticEntry, CodeAction, CodeLabel, Completion, Diagnostic, Language, + diagnostic_set::DiagnosticEntry, CodeAction, CodeLabel, Completion, CursorShape, Diagnostic, + Language, }; use anyhow::{anyhow, Result}; use clock::ReplicaId; @@ -52,11 +53,13 @@ pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation { selections, line_mode, lamport_timestamp, + cursor_shape, } => proto::operation::Variant::UpdateSelections(proto::operation::UpdateSelections { replica_id: lamport_timestamp.replica_id as u32, lamport_timestamp: lamport_timestamp.value, selections: serialize_selections(selections), line_mode: *line_mode, + cursor_shape: serialize_cursor_shape(cursor_shape) as i32, }), crate::Operation::UpdateDiagnostics { diagnostics, @@ -125,6 +128,24 @@ pub fn serialize_selection(selection: &Selection) -> proto::Selection { } } +pub fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape { + match cursor_shape { + CursorShape::Bar => proto::CursorShape::CursorBar, + CursorShape::Block => proto::CursorShape::CursorBlock, + CursorShape::Underscore => proto::CursorShape::CursorUnderscore, + CursorShape::Hollow => proto::CursorShape::CursorHollow, + } +} + +pub fn deserialize_cursor_shape(cursor_shape: proto::CursorShape) -> CursorShape { + match cursor_shape { + proto::CursorShape::CursorBar => CursorShape::Bar, + proto::CursorShape::CursorBlock => CursorShape::Block, + proto::CursorShape::CursorUnderscore => CursorShape::Underscore, + proto::CursorShape::CursorHollow => CursorShape::Hollow, + } +} + pub fn serialize_diagnostics<'a>( diagnostics: impl IntoIterator>, ) -> Vec { @@ -223,6 +244,10 @@ pub fn deserialize_operation(message: proto::Operation) -> Result { diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index 1248bb05519788a2d4ac1f198161afae3733a6ab..380b83ae8d3c8a09db3296b086a81e5a5b48c7e5 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -908,6 +908,7 @@ message SelectionSet { repeated Selection selections = 2; uint32 lamport_timestamp = 3; bool line_mode = 4; + CursorShape cursor_shape = 5; } message Selection { @@ -917,6 +918,13 @@ message Selection { bool reversed = 4; } +enum CursorShape { + CursorBar = 0; + CursorBlock = 1; + CursorUnderscore = 2; + CursorHollow = 3; +} + message Anchor { uint32 replica_id = 1; uint32 local_timestamp = 2; @@ -982,6 +990,7 @@ message Operation { uint32 lamport_timestamp = 2; repeated Selection selections = 3; bool line_mode = 4; + CursorShape cursor_shape = 5; } message UpdateCompletionTriggers { diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 63bc5962fa0bba24e6cc0875793f96643f17cfe4..f079ae86707fc17fca4e54d7503d5bb0cc2681d5 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -79,6 +79,7 @@ pub struct GitGutterConfig {} pub struct EditorSettings { pub tab_size: Option, pub hard_tabs: Option, + pub cursor_blink: Option, pub soft_wrap: Option, pub preferred_line_length: Option, pub format_on_save: Option, @@ -301,6 +302,7 @@ impl Settings { editor_defaults: EditorSettings { tab_size: required(defaults.editor.tab_size), hard_tabs: required(defaults.editor.hard_tabs), + cursor_blink: required(defaults.editor.cursor_blink), soft_wrap: required(defaults.editor.soft_wrap), preferred_line_length: required(defaults.editor.preferred_line_length), format_on_save: required(defaults.editor.format_on_save), @@ -390,6 +392,10 @@ impl Settings { self.language_setting(language, |settings| settings.hard_tabs) } + pub fn cursor_blink(&self, language: Option<&str>) -> bool { + self.language_setting(language, |settings| settings.cursor_blink) + } + pub fn soft_wrap(&self, language: Option<&str>) -> SoftWrap { self.language_setting(language, |settings| settings.soft_wrap) } @@ -444,6 +450,7 @@ impl Settings { editor_defaults: EditorSettings { tab_size: Some(4.try_into().unwrap()), hard_tabs: Some(false), + cursor_blink: Some(true), soft_wrap: Some(SoftWrap::None), preferred_line_length: Some(80), format_on_save: Some(FormatOnSave::On), diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index a0b5231501228d699631e4146b2acb3051656903..efd6a739679178fd54d55f6e840df53d8f5a3165 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -8,16 +8,17 @@ path = "src/terminal.rs" doctest = false [dependencies] -alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" } -procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false } +context_menu = { path = "../context_menu" } editor = { path = "../editor" } -util = { path = "../util" } +language = { path = "../language" } gpui = { path = "../gpui" } -theme = { path = "../theme" } +project = { path = "../project" } settings = { path = "../settings" } +theme = { path = "../theme" } +util = { path = "../util" } workspace = { path = "../workspace" } -project = { path = "../project" } -context_menu = { path = "../context_menu" } +alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" } +procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false } smallvec = { version = "1.6", features = ["union"] } smol = "1.2.5" mio-extras = "2.0.6" diff --git a/crates/terminal/src/terminal_element.rs b/crates/terminal/src/terminal_element.rs index df745dae464459f0d53439b264e91036353a7f44..823d99c801b7e6ed1d4f0808d11655fd8714a125 100644 --- a/crates/terminal/src/terminal_element.rs +++ b/crates/terminal/src/terminal_element.rs @@ -4,7 +4,7 @@ use alacritty_terminal::{ index::Point, term::{cell::Flags, TermMode}, }; -use editor::{Cursor, CursorShape, HighlightedRange, HighlightedRangeLine}; +use editor::{Cursor, HighlightedRange, HighlightedRangeLine}; use gpui::{ color::Color, elements::{Empty, Overlay}, @@ -20,6 +20,7 @@ use gpui::{ WeakViewHandle, }; use itertools::Itertools; +use language::CursorShape; use ordered_float::OrderedFloat; use settings::Settings; use theme::TerminalStyle; diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index fef0da209996289ac1ac11171951918fe03ae9ee..b5acb50e7c04e945660187438096aa84be6405dc 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -1,5 +1,5 @@ -use editor::CursorShape; use gpui::keymap::Context; +use language::CursorShape; use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 81bafcf3e27f7f850aa89863c1c8f404a3e9b3f8..ce3a7e2366ae8279e877d94bf8e48bdcca6394b2 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -12,8 +12,9 @@ mod visual; use collections::HashMap; use command_palette::CommandPaletteFilter; -use editor::{Bias, Cancel, CursorShape, Editor}; +use editor::{Bias, Cancel, Editor}; use gpui::{impl_actions, MutableAppContext, Subscription, ViewContext, WeakViewHandle}; +use language::CursorShape; use serde::Deserialize; use settings::Settings; From 09a0b3eb55521403c9f4428a77577cbfcab78884 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Sat, 15 Oct 2022 15:10:43 -0700 Subject: [PATCH 16/18] increment protocol version --- crates/rpc/src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc/src/rpc.rs b/crates/rpc/src/rpc.rs index 5fb9ca79a2c51e7930eb88bdb96d2c949eb3a5f0..89963eb0627f27b39030fc24d7692a97d873209a 100644 --- a/crates/rpc/src/rpc.rs +++ b/crates/rpc/src/rpc.rs @@ -6,4 +6,4 @@ pub use conn::Connection; pub use peer::*; mod macros; -pub const PROTOCOL_VERSION: u32 = 35; +pub const PROTOCOL_VERSION: u32 = 36; From 54cf6fa838b74c94fb9e547b6c3aab2e02448580 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Mon, 17 Oct 2022 16:19:03 -0700 Subject: [PATCH 17/18] Pull blink functionality out of editor and into blink manager. Make blink manager subscribe to settings changes in order to start blinking properly when it is re-enabled. Co-Authored-By: Mikayla Maki --- assets/settings/default.json | 4 +- crates/editor/src/blink_manager.rs | 110 +++++++++++++++++++++++++++++ crates/editor/src/editor.rs | 84 ++++------------------ crates/editor/src/element.rs | 2 +- crates/settings/src/settings.rs | 13 ++-- 5 files changed, 131 insertions(+), 82 deletions(-) create mode 100644 crates/editor/src/blink_manager.rs diff --git a/assets/settings/default.json b/assets/settings/default.json index 57f76f5f21904af012cbfcaa73cb0b4d78fb5db5..51aa108cd98a7bd5d16af5882b4293cca112239c 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -10,6 +10,8 @@ // Whether to show the informational hover box when moving the mouse // over symbols in the editor. "hover_popover_enabled": true, + // Whether the cursor blinks in the editor. + "cursor_blink": true, // Whether to pop the completions menu while typing in an editor without // explicitly requesting it. "show_completions_on_input": true, @@ -69,8 +71,6 @@ // The column at which to soft-wrap lines, for buffers where soft-wrap // is enabled. "preferred_line_length": 80, - // Whether the cursor blinks in the editor. - "cursor_blink": true, // Whether to indent lines using tab characters, as opposed to multiple // spaces. "hard_tabs": false, diff --git a/crates/editor/src/blink_manager.rs b/crates/editor/src/blink_manager.rs new file mode 100644 index 0000000000000000000000000000000000000000..77d10534d29a05d3a68b3f872eccc1184d01899b --- /dev/null +++ b/crates/editor/src/blink_manager.rs @@ -0,0 +1,110 @@ +use std::time::Duration; + +use gpui::{Entity, ModelContext}; +use settings::Settings; +use smol::Timer; + +pub struct BlinkManager { + blink_interval: Duration, + + blink_epoch: usize, + blinking_paused: bool, + visible: bool, + enabled: bool, +} + +impl BlinkManager { + pub fn new(blink_interval: Duration, cx: &mut ModelContext) -> Self { + let weak_handle = cx.weak_handle(); + cx.observe_global::(move |_, cx| { + if let Some(this) = weak_handle.upgrade(cx) { + // Make sure we blink the cursors if the setting is re-enabled + this.update(cx, |this, cx| this.blink_cursors(this.blink_epoch, cx)); + } + }) + .detach(); + + Self { + blink_interval, + + blink_epoch: 0, + blinking_paused: false, + visible: true, + enabled: true, + } + } + + fn next_blink_epoch(&mut self) -> usize { + self.blink_epoch += 1; + self.blink_epoch + } + + pub fn pause_blinking(&mut self, cx: &mut ModelContext) { + if !self.visible { + self.visible = true; + cx.notify(); + } + + let epoch = self.next_blink_epoch(); + let interval = self.blink_interval; + cx.spawn(|this, mut cx| { + let this = this.downgrade(); + async move { + Timer::after(interval).await; + if let Some(this) = this.upgrade(&cx) { + this.update(&mut cx, |this, cx| this.resume_cursor_blinking(epoch, cx)) + } + } + }) + .detach(); + } + + fn resume_cursor_blinking(&mut self, epoch: usize, cx: &mut ModelContext) { + if epoch == self.blink_epoch { + self.blinking_paused = false; + self.blink_cursors(epoch, cx); + } + } + + fn blink_cursors(&mut self, epoch: usize, cx: &mut ModelContext) { + if cx.global::().cursor_blink { + if epoch == self.blink_epoch && self.enabled && !self.blinking_paused { + self.visible = !self.visible; + cx.notify(); + + let epoch = self.next_blink_epoch(); + let interval = self.blink_interval; + cx.spawn(|this, mut cx| { + let this = this.downgrade(); + async move { + Timer::after(interval).await; + if let Some(this) = this.upgrade(&cx) { + this.update(&mut cx, |this, cx| this.blink_cursors(epoch, cx)); + } + } + }) + .detach(); + } + } else if !self.visible { + self.visible = true; + cx.notify(); + } + } + + pub fn enable(&mut self, cx: &mut ModelContext) { + self.enabled = true; + self.blink_cursors(self.blink_epoch, cx); + } + + pub fn disable(&mut self, _: &mut ModelContext) { + self.enabled = true; + } + + pub fn visible(&self) -> bool { + self.visible + } +} + +impl Entity for BlinkManager { + type Event = (); +} diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 901547db2e4e31dc3d95992a1c9171a8d85dc30f..f3edee1a9e2651030145566233d253c2215d32a6 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1,3 +1,4 @@ +mod blink_manager; pub mod display_map; mod element; mod highlight_matching_bracket; @@ -16,6 +17,7 @@ pub mod test; use aho_corasick::AhoCorasick; use anyhow::Result; +use blink_manager::BlinkManager; use clock::ReplicaId; use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque}; pub use display_map::DisplayPoint; @@ -447,12 +449,10 @@ pub struct Editor { override_text_style: Option>, project: Option>, focused: bool, - show_local_cursors: bool, + blink_manager: ModelHandle, show_local_selections: bool, show_scrollbars: bool, hide_scrollbar_task: Option>, - blink_epoch: usize, - blinking_paused: bool, mode: EditorMode, vertical_scroll_margin: f32, placeholder_text: Option>, @@ -1076,6 +1076,8 @@ impl Editor { let selections = SelectionsCollection::new(display_map.clone(), buffer.clone()); + let blink_manager = cx.add_model(|cx| BlinkManager::new(CURSOR_BLINK_INTERVAL, cx)); + let mut this = Self { handle: cx.weak_handle(), buffer: buffer.clone(), @@ -1097,12 +1099,10 @@ impl Editor { scroll_top_anchor: Anchor::min(), autoscroll_request: None, focused: false, - show_local_cursors: false, + blink_manager: blink_manager.clone(), show_local_selections: true, show_scrollbars: true, hide_scrollbar_task: None, - blink_epoch: 0, - blinking_paused: false, mode, vertical_scroll_margin: 3.0, placeholder_text: None, @@ -1130,6 +1130,7 @@ impl Editor { cx.observe(&buffer, Self::on_buffer_changed), cx.subscribe(&buffer, Self::on_buffer_event), cx.observe(&display_map, Self::on_display_map_changed), + cx.observe(&blink_manager, |_, _, cx| cx.notify()), ], }; this.end_selection(cx); @@ -1542,7 +1543,7 @@ impl Editor { refresh_matching_bracket_highlights(self, cx); } - self.pause_cursor_blinking(cx); + self.blink_manager.update(cx, BlinkManager::pause_blinking); cx.emit(Event::SelectionsChanged { local }); cx.notify(); } @@ -6111,70 +6112,8 @@ impl Editor { highlights } - fn next_blink_epoch(&mut self) -> usize { - self.blink_epoch += 1; - self.blink_epoch - } - - fn pause_cursor_blinking(&mut self, cx: &mut ViewContext) { - if !self.focused { - return; - } - - self.show_local_cursors = true; - cx.notify(); - - let epoch = self.next_blink_epoch(); - cx.spawn(|this, mut cx| { - let this = this.downgrade(); - async move { - Timer::after(CURSOR_BLINK_INTERVAL).await; - if let Some(this) = this.upgrade(&cx) { - this.update(&mut cx, |this, cx| this.resume_cursor_blinking(epoch, cx)) - } - } - }) - .detach(); - } - - fn resume_cursor_blinking(&mut self, epoch: usize, cx: &mut ViewContext) { - if epoch == self.blink_epoch { - self.blinking_paused = false; - self.blink_cursors(epoch, cx); - } - } - - fn blink_cursors(&mut self, epoch: usize, cx: &mut ViewContext) { - if epoch == self.blink_epoch && self.focused && !self.blinking_paused { - let newest_head = self.selections.newest::(cx).head(); - let language_name = self - .buffer - .read(cx) - .language_at(newest_head, cx) - .map(|l| l.name()); - - self.show_local_cursors = !self.show_local_cursors - || !cx - .global::() - .cursor_blink(language_name.as_deref()); - cx.notify(); - - let epoch = self.next_blink_epoch(); - cx.spawn(|this, mut cx| { - let this = this.downgrade(); - async move { - Timer::after(CURSOR_BLINK_INTERVAL).await; - if let Some(this) = this.upgrade(&cx) { - this.update(&mut cx, |this, cx| this.blink_cursors(epoch, cx)); - } - } - }) - .detach(); - } - } - - pub fn show_local_cursors(&self) -> bool { - self.show_local_cursors && self.focused + pub fn show_local_cursors(&self, cx: &AppContext) -> bool { + self.blink_manager.read(cx).visible() && self.focused } pub fn show_scrollbars(&self) -> bool { @@ -6493,7 +6432,7 @@ impl View for Editor { cx.focus(&rename.editor); } else { self.focused = true; - self.blink_cursors(self.blink_epoch, cx); + self.blink_manager.update(cx, BlinkManager::enable); self.buffer.update(cx, |buffer, cx| { buffer.finalize_last_transaction(cx); if self.leader_replica_id.is_none() { @@ -6512,6 +6451,7 @@ impl View for Editor { let blurred_event = EditorBlurred(cx.handle()); cx.emit_global(blurred_event); self.focused = false; + self.blink_manager.update(cx, BlinkManager::disable); self.buffer .update(cx, |buffer, cx| buffer.remove_active_selections(cx)); self.hide_context_menu(cx); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index d2090741d803ed316e5325987828df0a4b291ca4..57eee994057c67c5ca47bd56b4b3ee000021cd39 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -705,7 +705,7 @@ impl EditorElement { cx, ); - if view.show_local_cursors() || *replica_id != local_replica_id { + if view.show_local_cursors(cx) || *replica_id != local_replica_id { let cursor_position = selection.head; if layout .visible_display_row_range diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index f079ae86707fc17fca4e54d7503d5bb0cc2681d5..ee389c7a0efc3d3f6dc36ef526225dec0e4ec448 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -28,6 +28,7 @@ pub struct Settings { pub buffer_font_family: FamilyId, pub default_buffer_font_size: f32, pub buffer_font_size: f32, + pub cursor_blink: bool, pub hover_popover_enabled: bool, pub show_completions_on_input: bool, pub vim_mode: bool, @@ -79,7 +80,6 @@ pub struct GitGutterConfig {} pub struct EditorSettings { pub tab_size: Option, pub hard_tabs: Option, - pub cursor_blink: Option, pub soft_wrap: Option, pub preferred_line_length: Option, pub format_on_save: Option, @@ -235,6 +235,8 @@ pub struct SettingsFileContent { #[serde(default)] pub buffer_font_size: Option, #[serde(default)] + pub cursor_blink: Option, + #[serde(default)] pub hover_popover_enabled: Option, #[serde(default)] pub show_completions_on_input: Option, @@ -293,6 +295,7 @@ impl Settings { .unwrap(), buffer_font_size: defaults.buffer_font_size.unwrap(), default_buffer_font_size: defaults.buffer_font_size.unwrap(), + cursor_blink: defaults.cursor_blink.unwrap(), hover_popover_enabled: defaults.hover_popover_enabled.unwrap(), show_completions_on_input: defaults.show_completions_on_input.unwrap(), projects_online_by_default: defaults.projects_online_by_default.unwrap(), @@ -302,7 +305,6 @@ impl Settings { editor_defaults: EditorSettings { tab_size: required(defaults.editor.tab_size), hard_tabs: required(defaults.editor.hard_tabs), - cursor_blink: required(defaults.editor.cursor_blink), soft_wrap: required(defaults.editor.soft_wrap), preferred_line_length: required(defaults.editor.preferred_line_length), format_on_save: required(defaults.editor.format_on_save), @@ -348,6 +350,7 @@ impl Settings { ); merge(&mut self.buffer_font_size, data.buffer_font_size); merge(&mut self.default_buffer_font_size, data.buffer_font_size); + merge(&mut self.cursor_blink, data.cursor_blink); merge(&mut self.hover_popover_enabled, data.hover_popover_enabled); merge( &mut self.show_completions_on_input, @@ -392,10 +395,6 @@ impl Settings { self.language_setting(language, |settings| settings.hard_tabs) } - pub fn cursor_blink(&self, language: Option<&str>) -> bool { - self.language_setting(language, |settings| settings.cursor_blink) - } - pub fn soft_wrap(&self, language: Option<&str>) -> SoftWrap { self.language_setting(language, |settings| settings.soft_wrap) } @@ -442,6 +441,7 @@ impl Settings { buffer_font_family: cx.font_cache().load_family(&["Monaco"]).unwrap(), buffer_font_size: 14., default_buffer_font_size: 14., + cursor_blink: true, hover_popover_enabled: true, show_completions_on_input: true, vim_mode: false, @@ -450,7 +450,6 @@ impl Settings { editor_defaults: EditorSettings { tab_size: Some(4.try_into().unwrap()), hard_tabs: Some(false), - cursor_blink: Some(true), soft_wrap: Some(SoftWrap::None), preferred_line_length: Some(80), format_on_save: Some(FormatOnSave::On), From 54428ca6f6d5c63e82de6a360cb49d199f4b0d1d Mon Sep 17 00:00:00 2001 From: K Simmons Date: Mon, 17 Oct 2022 16:49:34 -0700 Subject: [PATCH 18/18] swap to using vercel to run the local zed.dev server --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index a64b411ef3224a8b6bbf4596bff109b125462bf4..e1b87dd48b6eea968a4dfa24f468f5c5acb7f3c0 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -web: cd ../zed.dev && PORT=3000 npx next dev +web: cd ../zed.dev && PORT=3000 npx vercel dev collab: cd crates/collab && cargo run