History

React on multibuffer scrolls again

Kirill Bulatov committed 3 years ago

Commit 2f1a2761 parent a31d3ec3 files · +59 −23Browse files

Unified · Split

3 files
  1. crates/editor/src/editor.rs +31 −1
  2. crates/editor/src/inlay_hint_cache.rs +20 −19
  3. crates/editor/src/scroll.rs +8 −3
crates/editor/src/editor.rs+31−1
@@ -1196,6 +1196,7 @@ enum GotoDefinitionKind { · 1195 unmodified lines
11961196 #[derive(Debug, Copy, Clone)]
11971197 enum InlayRefreshReason {
11981198 SettingsChange(editor_settings::InlayHints),
1199+ Scroll(ScrollAnchor),
11991200 VisibleExcerptsChange,
12001201 }
12011202
@@ -2624,6 +2625,34 @@ impl Editor { · 1422 unmodified lines
26242625 InlayRefreshReason::SettingsChange(new_settings) => self
26252626 .inlay_hint_cache
26262627 .spawn_settings_update(multi_buffer_handle, new_settings, current_inlays),
2628+ InlayRefreshReason::Scroll(scrolled_to) => {
2629+ if let Some(new_query) = self
2630+ .excerpt_visible_offsets(&multi_buffer_handle, cx)
2631+ .into_iter()
2632+ .find_map(|(buffer, _, excerpt_id)| {
2633+ let buffer_id = scrolled_to.anchor.buffer_id?;
2634+ if buffer_id == buffer.read(cx).remote_id()
2635+ && scrolled_to.anchor.excerpt_id == excerpt_id
2636+ {
2637+ Some(InlayHintQuery {
2638+ buffer_id,
2639+ buffer_version: buffer.read(cx).version(),
2640+ excerpt_id,
2641+ })
2642+ } else {
2643+ None
2644+ }
2645+ })
2646+ {
2647+ self.inlay_hint_cache.spawn_hints_update(
2648+ multi_buffer_handle,
2649+ vec![new_query],
2650+ current_inlays,
2651+ false,
2652+ cx,
2653+ )
2654+ }
2655+ }
26272656 InlayRefreshReason::VisibleExcerptsChange => {
26282657 let replacement_queries = self
26292658 .excerpt_visible_offsets(&multi_buffer_handle, cx)
@@ -2632,7 +2661,7 @@ impl Editor { · 2 unmodified lines
26322661 let buffer = buffer.read(cx);
26332662 InlayHintQuery {
26342663 buffer_id: buffer.remote_id(),
2635− buffer_version: buffer.version.clone(),
2664+ buffer_version: buffer.version(),
26362665 excerpt_id,
26372666 }
26382667 })
@@ -2641,6 +2670,7 @@ impl Editor { · 2 unmodified lines
26412670 multi_buffer_handle,
26422671 replacement_queries,
26432672 current_inlays,
2673+ true,
26442674 cx,
26452675 )
26462676 }
crates/editor/src/inlay_hint_cache.rs+20−19
@@ -102,27 +102,29 @@ impl InlayHintCache { · 101 unmodified lines
102102 multi_buffer: ModelHandle<MultiBuffer>,
103103 queries: Vec<InlayHintQuery>,
104104 current_inlays: Vec<Inlay>,
105+ conflicts_invalidate_cache: bool,
105106 cx: &mut ViewContext<Editor>,
106107 ) {
107− let conflicts_with_cache = queries.iter().any(|update_query| {
108− let Some(cached_buffer_hints) = self.hints_in_buffers.get(&update_query.buffer_id)
108+ let conflicts_with_cache = conflicts_invalidate_cache
109+ && queries.iter().any(|update_query| {
110+ let Some(cached_buffer_hints) = self.hints_in_buffers.get(&update_query.buffer_id)
109111 else { return false };
110− if cached_buffer_hints
111− .buffer_version
112− .changed_since(&update_query.buffer_version)
113− {
114− false
115− } else if update_query
116− .buffer_version
117− .changed_since(&cached_buffer_hints.buffer_version)
118− {
119− true
120− } else {
121− cached_buffer_hints
122− .hints_per_excerpt
123− .contains_key(&update_query.excerpt_id)
124− }
125− });
112+ if cached_buffer_hints
113+ .buffer_version
114+ .changed_since(&update_query.buffer_version)
115+ {
116+ false
117+ } else if update_query
118+ .buffer_version
119+ .changed_since(&cached_buffer_hints.buffer_version)
120+ {
121+ true
122+ } else {
123+ cached_buffer_hints
124+ .hints_per_excerpt
125+ .contains_key(&update_query.excerpt_id)
126+ }
127+ });
126128
127129 let queries_per_buffer = queries
128130 .into_iter()
@@ -569,7 +571,6 @@ fn allowed_hint_types( · 440 unmodified lines
569571 }
570572
571573 // TODO kb wrong, query and update the editor separately
572−// TODO kb need to react on react on scrolling too, for multibuffer excerpts
573574 fn fetch_queries(
574575 multi_buffer: ModelHandle<MultiBuffer>,
575576 queries: impl Iterator<Item = InlayHintQuery>,
crates/editor/src/scroll.rs+8−3
@@ -13,7 +13,7 @@ use gpui::{ · 12 unmodified lines
1313 };
1414 use language::{Bias, Point};
1515 use util::ResultExt;
16−use workspace::WorkspaceId;
16+use workspace::{item::Item, WorkspaceId};
1717
1818 use crate::{
1919 display_map::{DisplaySnapshot, ToDisplayPoint},
@@ -176,7 +176,7 @@ impl ScrollManager { · 156 unmodified lines
176176 autoscroll: bool,
177177 workspace_id: Option<i64>,
178178 cx: &mut ViewContext<Editor>,
179− ) {
179+ ) -> ScrollAnchor {
180180 let (new_anchor, top_row) = if scroll_position.y() <= 0. {
181181 (
182182 ScrollAnchor {
@@ -205,6 +205,7 @@ impl ScrollManager { · 22 unmodified lines
205205 };
206206
207207 self.set_anchor(new_anchor, top_row, local, autoscroll, workspace_id, cx);
208+ new_anchor
208209 }
209210
210211 fn set_anchor(
@@ -312,7 +313,7 @@ impl Editor { · 101 unmodified lines
312313
313314 hide_hover(self, cx);
314315 let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
315− self.scroll_manager.set_scroll_position(
316+ let scroll_anchor = self.scroll_manager.set_scroll_position(
316317 scroll_position,
317318 &map,
318319 local,
@@ -320,6 +321,10 @@ impl Editor { · 1 unmodified line
320321 workspace_id,
321322 cx,
322323 );
324+
325+ if !self.is_singleton(cx) {
326+ self.refresh_inlays(crate::InlayRefreshReason::Scroll(scroll_anchor), cx);
327+ }
323328 }
324329
325330 pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t