mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
WIP
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
9c74deb9ec
commit
da09247e5e
2 changed files with 14 additions and 8 deletions
|
@ -22,8 +22,7 @@ use gpui::{
|
|||
use items::BufferItemHandle;
|
||||
use language::{
|
||||
multi_buffer::{
|
||||
Anchor, AnchorRangeExt, AnchorRangeSet, MultiBuffer, MultiBufferSnapshot, SelectionSet,
|
||||
ToOffset, ToPoint,
|
||||
Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, SelectionSet, ToOffset, ToPoint,
|
||||
},
|
||||
BracketPair, Buffer, Diagnostic, DiagnosticSeverity, Language, Point, Selection, SelectionGoal,
|
||||
SelectionSetId,
|
||||
|
@ -1292,19 +1291,19 @@ impl Editor {
|
|||
}
|
||||
|
||||
fn autoclose_pairs(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
||||
let selections = self.selections::<usize>(cx);
|
||||
let new_autoclose_pair = self.buffer.update(cx, |buffer, cx| {
|
||||
let autoclose_pair = buffer.language().and_then(|language| {
|
||||
let first_selection_start = selections.first().unwrap().start;
|
||||
let pair = language.brackets().iter().find(|pair| {
|
||||
buffer_snapshot.contains_str_at(
|
||||
buffer.contains_str_at(
|
||||
first_selection_start.saturating_sub(pair.start.len()),
|
||||
&pair.start,
|
||||
)
|
||||
});
|
||||
pair.and_then(|pair| {
|
||||
let should_autoclose = selections[1..].iter().all(|selection| {
|
||||
buffer_snapshot.contains_str_at(
|
||||
buffer.contains_str_at(
|
||||
selection.start.saturating_sub(pair.start.len()),
|
||||
&pair.start,
|
||||
)
|
||||
|
@ -1322,7 +1321,7 @@ impl Editor {
|
|||
let selection_ranges = selections
|
||||
.iter()
|
||||
.map(|selection| {
|
||||
let start = selection.start.to_offset(&buffer_snapshot);
|
||||
let start = selection.start.to_offset(buffer);
|
||||
start..start
|
||||
})
|
||||
.collect::<SmallVec<[_; 32]>>();
|
||||
|
|
|
@ -3,7 +3,7 @@ mod selection;
|
|||
|
||||
use crate::{
|
||||
buffer::{self, Buffer, Chunk, ToOffset as _, ToPoint as _},
|
||||
BufferSnapshot, Diagnostic, File, Language,
|
||||
BufferSnapshot, Diagnostic, DiagnosticEntry, File, Language,
|
||||
};
|
||||
pub use anchor::{Anchor, AnchorRangeExt};
|
||||
use anyhow::Result;
|
||||
|
@ -383,6 +383,13 @@ impl MultiBuffer {
|
|||
[].into_iter()
|
||||
}
|
||||
|
||||
pub fn contains_str_at<T>(&self, _: T, _: &str) -> bool
|
||||
where
|
||||
T: ToOffset,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn max_point(&self) -> Point {
|
||||
self.snapshot.lock().max_point()
|
||||
}
|
||||
|
@ -438,7 +445,7 @@ impl MultiBuffer {
|
|||
pub fn diagnostics_in_range<'a, T, O>(
|
||||
&'a self,
|
||||
search_range: Range<T>,
|
||||
) -> impl Iterator<Item = (Range<O>, &Diagnostic)> + 'a
|
||||
) -> impl Iterator<Item = DiagnosticEntry<O>> + 'a
|
||||
where
|
||||
T: 'a + ToOffset,
|
||||
O: 'a,
|
||||
|
|
Loading…
Reference in a new issue