Merge pull request #1271 from zed-industries/matching-bracket-highlights

Highlight matching bracket when newest selection head is on a bracket
This commit is contained in:
Keith Simmons 2022-07-05 16:51:46 -07:00 committed by GitHub
commit 58e57d0150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 241 additions and 27 deletions

View file

@ -1,5 +1,6 @@
pub mod display_map;
mod element;
mod highlight_matching_bracket;
mod hover_popover;
pub mod items;
mod link_go_to_definition;
@ -32,6 +33,7 @@ use gpui::{
ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext,
ViewHandle, WeakViewHandle,
};
use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState};
pub use language::{char_kind, CharKind};
use language::{
@ -1430,6 +1432,7 @@ impl Editor {
}
self.refresh_code_actions(cx);
self.refresh_document_highlights(cx);
refresh_matching_bracket_highlights(self, cx);
}
self.pause_cursor_blinking(cx);
@ -5425,7 +5428,7 @@ impl Editor {
.map(|h| &h.1);
let write_highlights = self
.background_highlights
.get(&TypeId::of::<DocumentHighlightRead>())
.get(&TypeId::of::<DocumentHighlightWrite>())
.map(|h| &h.1);
let left_position = position.bias_left(buffer);
let right_position = position.bias_right(buffer);
@ -10553,3 +10556,13 @@ impl<T: Ord + Clone> RangeExt<T> for Range<T> {
self.start.clone()..=self.end.clone()
}
}
trait RangeToAnchorExt {
fn to_anchors(self, snapshot: &MultiBufferSnapshot) -> Range<Anchor>;
}
impl<T: ToOffset> RangeToAnchorExt for Range<T> {
fn to_anchors(self, snapshot: &MultiBufferSnapshot) -> Range<Anchor> {
snapshot.anchor_after(self.start)..snapshot.anchor_before(self.end)
}
}