From 0dfa3c60b726b7736bb759a4e8d2890230a6528e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 3 Nov 2023 10:50:30 +0100 Subject: [PATCH] Remove some todos --- crates/editor2/src/editor.rs | 29 ++++++------- .../editor2/src/highlight_matching_bracket.rs | 43 +++++++++---------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index c3aa26cb0cb53a0e08624f71e6fa757c8fde1474..4bd1a5153860a26d1bd720f1600d17ae36af95df 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -36,8 +36,9 @@ pub use element::{ use futures::FutureExt; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ - AnyElement, AppContext, BackgroundExecutor, Context, Element, EventEmitter, Hsla, Model, - Pixels, Render, Subscription, Task, TextStyle, View, ViewContext, WeakView, WindowContext, + AnyElement, AppContext, BackgroundExecutor, Context, Element, EventEmitter, FocusHandle, Hsla, + Model, Pixels, Render, Subscription, Task, TextStyle, View, ViewContext, WeakView, + WindowContext, }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; @@ -606,6 +607,7 @@ type InlayBackgroundHighlight = (fn(&ThemeColors) -> Hsla, Vec); pub struct Editor { handle: WeakView, + focus_handle: FocusHandle, buffer: Model, display_map: Model, pub selections: SelectionsCollection, @@ -1912,6 +1914,7 @@ impl Editor { let mut this = Self { handle: cx.view().downgrade(), + focus_handle: cx.focus_handle(), buffer: buffer.clone(), display_map: display_map.clone(), selections, @@ -2066,19 +2069,15 @@ impl Editor { // } pub fn snapshot(&mut self, cx: &mut WindowContext) -> EditorSnapshot { - todo!() - // EditorSnapshot { - // mode: self.mode, - // show_gutter: self.show_gutter, - // display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)), - // scroll_anchor: self.scroll_manager.anchor(), - // ongoing_scroll: self.scroll_manager.ongoing_scroll(), - // placeholder_text: self.placeholder_text.clone(), - // is_focused: self - // .handle - // .upgrade(cx) - // .map_or(false, |handle| handle.is_focused(cx)), - // } + EditorSnapshot { + mode: self.mode, + show_gutter: self.show_gutter, + display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)), + scroll_anchor: self.scroll_manager.anchor(), + ongoing_scroll: self.scroll_manager.ongoing_scroll(), + placeholder_text: self.placeholder_text.clone(), + is_focused: self.focus_handle.is_focused(cx), + } } // pub fn language_at<'a, T: ToOffset>( diff --git a/crates/editor2/src/highlight_matching_bracket.rs b/crates/editor2/src/highlight_matching_bracket.rs index 5074ee4eda495f2f71614c4e7ade328d1a0a6018..fd8fb6b097099e6a9d47cbfd81f1b2e278e7f405 100644 --- a/crates/editor2/src/highlight_matching_bracket.rs +++ b/crates/editor2/src/highlight_matching_bracket.rs @@ -5,30 +5,29 @@ use crate::{Editor, RangeToAnchorExt}; enum MatchingBracketHighlight {} pub fn refresh_matching_bracket_highlights(editor: &mut Editor, cx: &mut ViewContext) { - todo!() - // // editor.clear_background_highlights::(cx); + // editor.clear_background_highlights::(cx); - // let newest_selection = editor.selections.newest::(cx); - // // Don't highlight brackets if the selection isn't empty - // if !newest_selection.is_empty() { - // return; - // } + let newest_selection = editor.selections.newest::(cx); + // Don't highlight brackets if the selection isn't empty + if !newest_selection.is_empty() { + return; + } - // let head = newest_selection.head(); - // let snapshot = editor.snapshot(cx); - // if let Some((opening_range, closing_range)) = snapshot - // .buffer_snapshot - // .innermost_enclosing_bracket_ranges(head..head) - // { - // editor.highlight_background::( - // vec![ - // opening_range.to_anchors(&snapshot.buffer_snapshot), - // closing_range.to_anchors(&snapshot.buffer_snapshot), - // ], - // |theme| theme.editor.document_highlight_read_background, - // cx, - // ) - // } + let head = newest_selection.head(); + let snapshot = editor.snapshot(cx); + if let Some((opening_range, closing_range)) = snapshot + .buffer_snapshot + .innermost_enclosing_bracket_ranges(head..head) + { + editor.highlight_background::( + vec![ + opening_range.to_anchors(&snapshot.buffer_snapshot), + closing_range.to_anchors(&snapshot.buffer_snapshot), + ], + |theme| todo!("theme.editor.document_highlight_read_background"), + cx, + ) + } } // #[cfg(test)]