feat: add syntax highlighting to text buffers
This commit is contained in:
+15
-1
@@ -693,6 +693,7 @@ struct Buffer {
|
||||
id: usize,
|
||||
lines: Vec<String>,
|
||||
saved_lines: Vec<String>,
|
||||
text_revision: u64,
|
||||
targets: Vec<Target>,
|
||||
primary: usize,
|
||||
mode: Mode,
|
||||
@@ -731,6 +732,7 @@ impl Buffer {
|
||||
id,
|
||||
saved_lines: lines.clone(),
|
||||
lines,
|
||||
text_revision: 0,
|
||||
targets: vec![Target::caret(Cursor::default())],
|
||||
primary: 0,
|
||||
mode: Mode::Normal,
|
||||
@@ -938,6 +940,10 @@ impl Editor {
|
||||
pub fn lines(&self) -> &[String] {
|
||||
&self.active.lines
|
||||
}
|
||||
/// Changes only when this buffer's text changes, independent of cursor/view state.
|
||||
pub fn text_revision(&self) -> u64 {
|
||||
self.active.text_revision
|
||||
}
|
||||
pub fn cursor(&self) -> Cursor {
|
||||
self.active.targets[self.active.primary].active
|
||||
}
|
||||
@@ -2267,7 +2273,11 @@ impl Editor {
|
||||
match effect {
|
||||
Effect::Insert(text) => self.insert_text(&normalize_newlines(&text)),
|
||||
Effect::Replace(text) => {
|
||||
self.active.lines = split_lines(&text);
|
||||
let lines = split_lines(&text);
|
||||
if lines != self.active.lines {
|
||||
self.active.text_revision = self.active.text_revision.wrapping_add(1);
|
||||
}
|
||||
self.active.lines = lines;
|
||||
self.active.search_match = None;
|
||||
self.normalize_targets();
|
||||
}
|
||||
@@ -3165,6 +3175,9 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn restore(&mut self, snapshot: Snapshot) {
|
||||
if self.active.lines != snapshot.lines {
|
||||
self.active.text_revision = self.active.text_revision.wrapping_add(1);
|
||||
}
|
||||
self.active.lines = snapshot.lines;
|
||||
self.active.targets = snapshot.targets;
|
||||
self.active.primary = snapshot.primary;
|
||||
@@ -3377,6 +3390,7 @@ impl Editor {
|
||||
destinations[edit.target] = (remap(edit.start, false) + edit.caret, edit.round_up);
|
||||
}
|
||||
if text != old {
|
||||
self.active.text_revision = self.active.text_revision.wrapping_add(1);
|
||||
self.active.search_match = None;
|
||||
}
|
||||
self.active.lines = text.split('\n').map(str::to_owned).collect();
|
||||
|
||||
Reference in New Issue
Block a user