MarkdownDocument: a Markdown file in one CodeEditor, shown visual, source, split or preview
CI / site (push) Successful in 34s
CI / platforms (windows-latest) (push) Successful in 5m7s
CI / crate (push) Failing after 26m45s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

Visual draws the top-level blocks in a gpui list; a pressed block opens as
its source and its typing is the text at once, written back as one undo
step. CodeEditor takes the owner's line colors, resets with a fresh
history and keeps at most 64 MiB of undo text. MarkdownMode gains Preview.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-12 00:44:17 -04:00
1 parent 9036c92442
commit 2b6f5513aa
19 files changed
+1267 -86

No files matched your search

+25
View File
@@ -143,12 +143,37 @@ impl<S> History<S> {
self.typing_since = None;
Some(next)
}
/// Drops oldest undo steps past `budget`; returns how many.
pub fn trim(&mut self, budget: usize, size: impl Fn(&S) -> usize) -> usize {
let mut held: usize = self.undo.iter().chain(&self.redo).map(&size).sum();
let mut dropped = 0;
while held > budget && dropped < self.undo.len() {
held -= size(&self.undo[dropped]);
dropped += 1;
}
self.undo.drain(..dropped);
dropped
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn trimming_drops_the_oldest_steps_past_the_budget() {
let mut history = History::default();
for step in ["aaaa", "bbbb", "cccc"] {
history.record(step.to_string(), false);
}
assert_eq!(history.trim(9, String::len), 1, "12 bytes over 9");
assert_eq!(history.undo("now".into()), Some("cccc".to_string()));
assert_eq!(history.undo("cccc".into()), Some("bbbb".to_string()));
assert_eq!(history.undo("bbbb".into()), None, "the oldest went");
assert_eq!(history.trim(100, String::len), 0);
}
#[test]
fn graphemes_keep_clusters_whole() {
let text = "ae\u{301}🇯🇵z";