Support highlighting in blocks
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
0f1eb3dd2e
commit
0a6293bcda
10 changed files with 105 additions and 87 deletions
|
@ -4,6 +4,7 @@ use language::{rope, Chunk};
|
|||
use parking_lot::Mutex;
|
||||
use std::{cmp, mem, ops::Range};
|
||||
use sum_tree::Bias;
|
||||
use theme::SyntaxTheme;
|
||||
|
||||
pub struct TabMap(Mutex<Snapshot>);
|
||||
|
||||
|
@ -33,7 +34,7 @@ impl TabMap {
|
|||
let mut delta = 0;
|
||||
for chunk in old_snapshot
|
||||
.fold_snapshot
|
||||
.chunks(fold_edit.old_bytes.end..max_offset, false)
|
||||
.chunks(fold_edit.old_bytes.end..max_offset, None)
|
||||
{
|
||||
let patterns: &[_] = &['\t', '\n'];
|
||||
if let Some(ix) = chunk.text.find(patterns) {
|
||||
|
@ -116,7 +117,7 @@ impl Snapshot {
|
|||
self.max_point()
|
||||
};
|
||||
for c in self
|
||||
.chunks(range.start..line_end, false)
|
||||
.chunks(range.start..line_end, None)
|
||||
.flat_map(|chunk| chunk.text.chars())
|
||||
{
|
||||
if c == '\n' {
|
||||
|
@ -130,7 +131,7 @@ impl Snapshot {
|
|||
last_line_chars = first_line_chars;
|
||||
} else {
|
||||
for _ in self
|
||||
.chunks(TabPoint::new(range.end.row(), 0)..range.end, false)
|
||||
.chunks(TabPoint::new(range.end.row(), 0)..range.end, None)
|
||||
.flat_map(|chunk| chunk.text.chars())
|
||||
{
|
||||
last_line_chars += 1;
|
||||
|
@ -150,7 +151,11 @@ impl Snapshot {
|
|||
self.fold_snapshot.version
|
||||
}
|
||||
|
||||
pub fn chunks(&self, range: Range<TabPoint>, highlights: bool) -> Chunks {
|
||||
pub fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<TabPoint>,
|
||||
theme: Option<&'a SyntaxTheme>,
|
||||
) -> Chunks<'a> {
|
||||
let (input_start, expanded_char_column, to_next_stop) =
|
||||
self.to_fold_point(range.start, Bias::Left);
|
||||
let input_start = input_start.to_offset(&self.fold_snapshot);
|
||||
|
@ -165,9 +170,7 @@ impl Snapshot {
|
|||
};
|
||||
|
||||
Chunks {
|
||||
fold_chunks: self
|
||||
.fold_snapshot
|
||||
.chunks(input_start..input_end, highlights),
|
||||
fold_chunks: self.fold_snapshot.chunks(input_start..input_end, theme),
|
||||
column: expanded_char_column,
|
||||
output_position: range.start.0,
|
||||
max_output_position: range.end.0,
|
||||
|
@ -186,7 +189,7 @@ impl Snapshot {
|
|||
|
||||
#[cfg(test)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(TabPoint::zero()..self.max_point(), false)
|
||||
self.chunks(TabPoint::zero()..self.max_point(), None)
|
||||
.map(|chunk| chunk.text)
|
||||
.collect()
|
||||
}
|
||||
|
@ -502,7 +505,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
expected_text,
|
||||
tabs_snapshot
|
||||
.chunks(start..end, false)
|
||||
.chunks(start..end, None)
|
||||
.map(|c| c.text)
|
||||
.collect::<String>()
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue