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 items::BufferItemHandle;
|
||||||
use language::{
|
use language::{
|
||||||
multi_buffer::{
|
multi_buffer::{
|
||||||
Anchor, AnchorRangeExt, AnchorRangeSet, MultiBuffer, MultiBufferSnapshot, SelectionSet,
|
Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, SelectionSet, ToOffset, ToPoint,
|
||||||
ToOffset, ToPoint,
|
|
||||||
},
|
},
|
||||||
BracketPair, Buffer, Diagnostic, DiagnosticSeverity, Language, Point, Selection, SelectionGoal,
|
BracketPair, Buffer, Diagnostic, DiagnosticSeverity, Language, Point, Selection, SelectionGoal,
|
||||||
SelectionSetId,
|
SelectionSetId,
|
||||||
|
@ -1292,19 +1291,19 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn autoclose_pairs(&mut self, cx: &mut ViewContext<Self>) {
|
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 new_autoclose_pair = self.buffer.update(cx, |buffer, cx| {
|
||||||
let autoclose_pair = buffer.language().and_then(|language| {
|
let autoclose_pair = buffer.language().and_then(|language| {
|
||||||
let first_selection_start = selections.first().unwrap().start;
|
let first_selection_start = selections.first().unwrap().start;
|
||||||
let pair = language.brackets().iter().find(|pair| {
|
let pair = language.brackets().iter().find(|pair| {
|
||||||
buffer_snapshot.contains_str_at(
|
buffer.contains_str_at(
|
||||||
first_selection_start.saturating_sub(pair.start.len()),
|
first_selection_start.saturating_sub(pair.start.len()),
|
||||||
&pair.start,
|
&pair.start,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
pair.and_then(|pair| {
|
pair.and_then(|pair| {
|
||||||
let should_autoclose = selections[1..].iter().all(|selection| {
|
let should_autoclose = selections[1..].iter().all(|selection| {
|
||||||
buffer_snapshot.contains_str_at(
|
buffer.contains_str_at(
|
||||||
selection.start.saturating_sub(pair.start.len()),
|
selection.start.saturating_sub(pair.start.len()),
|
||||||
&pair.start,
|
&pair.start,
|
||||||
)
|
)
|
||||||
|
@ -1322,7 +1321,7 @@ impl Editor {
|
||||||
let selection_ranges = selections
|
let selection_ranges = selections
|
||||||
.iter()
|
.iter()
|
||||||
.map(|selection| {
|
.map(|selection| {
|
||||||
let start = selection.start.to_offset(&buffer_snapshot);
|
let start = selection.start.to_offset(buffer);
|
||||||
start..start
|
start..start
|
||||||
})
|
})
|
||||||
.collect::<SmallVec<[_; 32]>>();
|
.collect::<SmallVec<[_; 32]>>();
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod selection;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
buffer::{self, Buffer, Chunk, ToOffset as _, ToPoint as _},
|
buffer::{self, Buffer, Chunk, ToOffset as _, ToPoint as _},
|
||||||
BufferSnapshot, Diagnostic, File, Language,
|
BufferSnapshot, Diagnostic, DiagnosticEntry, File, Language,
|
||||||
};
|
};
|
||||||
pub use anchor::{Anchor, AnchorRangeExt};
|
pub use anchor::{Anchor, AnchorRangeExt};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -383,6 +383,13 @@ impl MultiBuffer {
|
||||||
[].into_iter()
|
[].into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn contains_str_at<T>(&self, _: T, _: &str) -> bool
|
||||||
|
where
|
||||||
|
T: ToOffset,
|
||||||
|
{
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn max_point(&self) -> Point {
|
pub fn max_point(&self) -> Point {
|
||||||
self.snapshot.lock().max_point()
|
self.snapshot.lock().max_point()
|
||||||
}
|
}
|
||||||
|
@ -438,7 +445,7 @@ impl MultiBuffer {
|
||||||
pub fn diagnostics_in_range<'a, T, O>(
|
pub fn diagnostics_in_range<'a, T, O>(
|
||||||
&'a self,
|
&'a self,
|
||||||
search_range: Range<T>,
|
search_range: Range<T>,
|
||||||
) -> impl Iterator<Item = (Range<O>, &Diagnostic)> + 'a
|
) -> impl Iterator<Item = DiagnosticEntry<O>> + 'a
|
||||||
where
|
where
|
||||||
T: 'a + ToOffset,
|
T: 'a + ToOffset,
|
||||||
O: 'a,
|
O: 'a,
|
||||||
|
|
Loading…
Reference in a new issue