diff options
author | Pascal Kuthe | 2023-06-20 19:35:12 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-06-25 16:32:31 +0000 |
commit | d491e234f4eb4d8c3869f44ab71fedf022dc463e (patch) | |
tree | df56999f77fadfbaa18aab1a9531a2e9d566af3c /helix-view/src | |
parent | 6c6923c39eae8b176d4deb7779ab19dcebb326ea (diff) |
map positions through changes in O(N)
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 52b2dfc0..4140c105 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1121,21 +1121,28 @@ impl Document { let changes = transaction.changes(); + changes.update_positions( + self.diagnostics + .iter_mut() + .map(|diagnostic| (&mut diagnostic.range.start, Assoc::After)), + ); + changes.update_positions( + self.diagnostics + .iter_mut() + .map(|diagnostic| (&mut diagnostic.range.end, Assoc::After)), + ); // map state.diagnostics over changes::map_pos too for diagnostic in &mut self.diagnostics { - diagnostic.range.start = changes.map_pos(diagnostic.range.start, Assoc::After); - diagnostic.range.end = changes.map_pos(diagnostic.range.end, Assoc::After); diagnostic.line = self.text.char_to_line(diagnostic.range.start); } - self.diagnostics - .sort_unstable_by_key(|diagnostic| diagnostic.range); // Update the inlay hint annotations' positions, helping ensure they are displayed in the proper place let apply_inlay_hint_changes = |annotations: &mut Rc<[InlineAnnotation]>| { if let Some(data) = Rc::get_mut(annotations) { - for inline in data.iter_mut() { - inline.char_idx = changes.map_pos(inline.char_idx, Assoc::After); - } + changes.update_positions( + data.iter_mut() + .map(|diagnostic| (&mut diagnostic.char_idx, Assoc::After)), + ); } }; |