Visual Studio Code, rebuilt in Rust
Rust
fix(workbench): draw again when a value laid out in paint changes
rokartur356dac0a9c73
diff --git a/native/crates/app/src/workbench/color_picker.rs b/native/crates/app/src/workbench/color_picker.rsindex 256599f8d52..8edcf156f2c 100644--- a/native/crates/app/src/workbench/color_picker.rs+++ b/native/crates/app/src/workbench/color_picker.rs@@ -368,7 +368,14 @@ impl Workbench {let bounds = picker.bounds.clone();let measure = |index: usize| {let bounds = bounds.clone();- canvas(move |element_bounds, _, _| bounds[index].set(Some(element_bounds.map(f32::from))), |_, _, _, _| ()).absolute().inset_0()+ // The standalone header is as wide as the saturation box measured here (`saturation_width`).+ let measured = move |element_bounds: Bounds<gpui::Pixels>, window: &mut gpui::Window, cx: &mut gpui::App| {+ let element_bounds = Some(element_bounds.map(f32::from));+ if bounds[index].replace(element_bounds) != element_bounds {+ super::part_view::redraw_after_frame(window, cx);+ }+ };+ canvas(measured, |_, _, _, _| ()).absolute().inset_0()};let saturated = PickerColor::from_hsva(hue, 1., 1., 1.).fill();let saturation_box = div()diff --git a/native/crates/app/src/workbench/input_box_view.rs b/native/crates/app/src/workbench/input_box_view.rsindex 0301bf6941a..cca2136cead 100644--- a/native/crates/app/src/workbench/input_box_view.rs+++ b/native/crates/app/src/workbench/input_box_view.rs@@ -150,14 +150,23 @@ impl InputView {self.text = Rc::default();}+ /// `x_of_char` as it reads later in the frame, once the input painted.+ pub fn x_of_char_after_paint(&self) -> impl Fn(&str, usize) -> f32 + 'static {+ let text = self.text.clone();+ move |value, index| x_of_char(&text.borrow(), value, index)+ }+/// The x of the char at `index` of `value` from the input's left edge, as last painted.pub fn x_of_char(&self, value: &str, index: usize) -> f32 {- let text = self.text.borrow();- let Some((_, line, byte)) = text.line_of(index.min(value.chars().count())) else { return 0. };- f32::from(line.x_for_index(byte)) - text.scroll+ x_of_char(&self.text.borrow(), value, index)}}+fn x_of_char(text: &InputText, value: &str, index: usize) -> f32 {+ let Some((_, line, byte)) = text.line_of(index.min(value.chars().count())) else { return 0. };+ f32::from(line.x_for_index(byte)) - text.scroll+}+/// What the input element draws besides its value.pub struct InputLook {pub password: bool,diff --git a/native/crates/app/src/workbench/quick_input_view.rs b/native/crates/app/src/workbench/quick_input_view.rsindex 3c26e1f65d0..a28e1ef9779 100644--- a/native/crates/app/src/workbench/quick_input_view.rs+++ b/native/crates/app/src/workbench/quick_input_view.rs@@ -823,7 +823,8 @@ impl Workbench {.size_full();// .monaco-list: rows show through the 7px bottom padding, but listView.ts renders only the rows that start// inside `renderHeight`: when a row starts right at its end, the padding stays empty (ref-dom, Customize Layout).- let render_bottom = scroll_top_px(&self.quick_inputs.list, &heights) + height;+ let scroll_top = scroll_top_px(&self.quick_inputs.list, &heights);+ let render_bottom = scroll_top + height;let mut row_top = 0.;let mut padding_empty = true;for row_height in &heights {@@ -833,8 +834,15 @@ impl Workbench {row_top += row_height;}let cover = padding_empty.then(|| div().absolute().left_0().right_0().bottom_0().h(px(7.)).bg(self.color("quickInput.background")));+ // The list clamps a reveal past its end as it lays out, after this render read the scroll.+ let list_state = self.quick_inputs.list.clone();+ let follow_scroll = canvas(|_, _, _| (), move |_, _, window, cx| {+ if scroll_top_px(&list_state, &heights) != scroll_top {+ super::part_view::redraw_after_frame(window, cx);+ }+ });// .monaco-scrollable-element: 6px on the sides.- let rows = div().relative().h(px(height + 7.)).px(px(6.)).child(rows).children(cover).child(self.list_scroll_layer(super::list_scroll::ListId::QuickInput, cx));+ let rows = div().relative().h(px(height + 7.)).px(px(6.)).child(rows).children(cover).child(follow_scroll).child(self.list_scroll_layer(super::list_scroll::ListId::QuickInput, cx));// quickInput.css `.quick-input-list`: line-height 22px.div().line_height(px(22.)).when(input.hide_input, |list| list.mt(px(4.)).pb(px(4.))).child(rows)}diff --git a/native/crates/app/src/workbench/settings_editor_view/search_suggest.rs b/native/crates/app/src/workbench/settings_editor_view/search_suggest.rsindex 49fa784c0d3..91aeecd4bbf 100644--- a/native/crates/app/src/workbench/settings_editor_view/search_suggest.rs+++ b/native/crates/app/src/workbench/settings_editor_view/search_suggest.rs@@ -1,7 +1,7 @@//! The search box's suggest widget (suggestEnabledInput.ts with the `SettingsEditor2` provider): a typed//! `@` or `:` opens the completions of the word before the caret.-use gpui::{Context, MouseButton, ScrollWheelEvent, Window, div, prelude::*, px};+use gpui::{Context, MouseButton, ScrollWheelEvent, Window, canvas, div, prelude::*, px};use serde_json::{Value, json};use std::collections::HashMap;@@ -128,7 +128,16 @@ impl Workbench {let editor = &self.settings_editor;let suggest = editor.suggest.as_ref().filter(|_| editor.search_focus.is_focused(window))?;// suggestWidget.ts showSuggestions: the widget sits at the caret, not at the word start.- let left = text_left + editor.search_view.x_of_char(&editor.search.value, editor.search.selection.1);+ let caret_x = editor.search_view.x_of_char(&editor.search.value, editor.search.selection.1);+ let left = text_left + caret_x;+ // The input lays its text out as it paints, before this widget: a caret moved by the typed char draws again.+ let painted_x = editor.search_view.x_of_char_after_paint();+ let (value, caret) = (editor.search.value.clone(), editor.search.selection.1);+ let follow_caret = canvas(|_, _, _| (), move |_, _, window, cx| {+ if painted_x(&value, caret) != caret_x {+ super::super::part_view::redraw_after_frame(window, cx);+ }+ });let visible = suggest.items.len().min(MAX_VISIBLE);let rows = suggest.items.iter().enumerate().skip(suggest.top).take(visible).map(|(index, (label, matches))| {let selected = index == suggest.selected;@@ -179,7 +188,8 @@ impl Workbench {suggest.top = suggest.top.saturating_add_signed(rows).min(suggest.items.len().saturating_sub(MAX_VISIBLE));cx.notify();}))- .children(rows),+ .children(rows)+ .child(follow_caret),)}}diff --git a/port/notes.md b/port/notes.mdindex 0db014d0a3a..7f42155571c 100644--- a/port/notes.md+++ b/port/notes.md@@ -1127,6 +1127,9 @@ Work the port does at another time than 1.147.0, accepted with a measured same r- A false difference of the check: it ran at the start of the next `flush_effects`, after the test had changed state without a notify (`folder.reveal` in `explorer_actions` tests), which the full render showed and no mode would have drawn. It now runs as the flush that drew the frame ends, before the test runs on. 9, `retained_check.rs` `a_change_after_the_settled_frame_is_not_a_retention_difference`.- The explorer reads the disk as it draws (`explorer.rs` `entries`), and a file added or deleted on disk notified nothing, so the cached side bar kept the old rows until an unrelated workbench change; `files_changed` now notifies when a change is in a folder the tree shows, as `explorerService.ts` refreshes on `onDidChangeFiles`. Two test setups changed the disk under a shown explorer with no watcher running: `code_lens` tests shared one folder per process (now one per test thread), `local_history_actions` kept the user data, and so the history it writes, inside the workspace folder (now beside it). 6, `explorer_actions` `a_file_added_on_disk_draws_in_the_tree`.- The editor part's size, measured by a canvas (`editor_groups.rs` `editor_groups_part`) and read by the next render (the grid's layout, the watermark's shortcuts above 478 px), drew nothing when it changed, so the cached part kept the layout of the size before (a terminal or panel toggled, zen mode); it now draws again through `part_view::redraw_after_frame`. 7, the `terminal_view` tab and toolbar tests under `GPUI_RETENTION_CHECK=1`.+ - The same trap in three more places, each a value laid out in paint and read by a render that had already run: the standalone color picker's header width from the saturation box (`color_picker.rs`), the settings search suggest widget's left edge from the input's caret x (`search_suggest.rs`, through `InputView::x_of_char_after_paint`), and the quick input list's scroll top, which the list clamps to its end as it lays out after `keep_scroll_position` (`quick_input_view.rs`). Each draws again through `part_view::redraw_after_frame` when the painted value differs. 4, `standalone_color_picker`, `settings_editor_view` `typed_at_opens_the_search_suggestions_and_enter_inserts_the_selected_one`, `quick_input_view` `keep_scroll_position_keeps_the_list_where_it_is`.+ - A false difference of the check: its full render draws every view again, so `part_view` `a_cursor_blink_draws_the_editor_part_alone`, which counts the side bar's renders through a blink, returns early under `GPUI_RETENTION_CHECK=1`; the plain run keeps it. 1.+ - Head after these: `GPUI_RETENTION_CHECK=1` 3747 passed, 0 failed; plain 3747 passed, 0 failed.- The 31 Wu commits (`git log -- native/vendor/wu`, newest first). Hunks: the commit's Rust and Metal hunks under `crates/`; failed: the hunks `patch --dry-run` rejects on the gpui-fast copy, each commit tried alone (a commit that builds on an earlier one also fails where that one is missing). Merge commits carry no change of their own.| Commit | Subject | Area | In gpui-fast | gpui-fast files | Hunks, failed |