Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: System libraries (Linux; Rune's Wayland and keyboard backends, and Vulkan)
if: runner.os == 'Linux'
Expand All @@ -23,6 +25,8 @@ jobs:
run: cargo build --locked
- name: Install just
uses: taiki-e/install-action@just
- name: Lint
run: just lint
- name: Install Claude Code CLI (for the mod tests)
run: npm install -g @anthropic-ai/claude-code@2.1.309
- name: Tests (app unit tests, then mod tests)
Expand Down
19 changes: 9 additions & 10 deletions src/editor/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ impl Editor {
mod tests {
use super::*;

impl Editor {
/// Lay out at the width tests set by hand.
fn relayout_with_width(&mut self) {
let lines = self.buffer.line_count();
let old = self.rows.breaks.len();
self.rows.rewrap(&self.buffer, 0, old, lines, &self.folds);
}
}

#[test]
fn a_long_line_wraps_after_the_last_space_that_fits_and_keeps_its_indent() {
assert_eq!(wrap("short", 10), (vec![], 0));
Expand Down Expand Up @@ -439,13 +448,3 @@ mod tests {
assert!(e.hidden(6) && e.hidden(7));
}
}

#[cfg(test)]
impl Editor {
/// Lay out at the width tests set by hand.
fn relayout_with_width(&mut self) {
let lines = self.buffer.line_count();
let old = self.rows.breaks.len();
self.rows.rewrap(&self.buffer, 0, old, lines, &self.folds);
}
}
2 changes: 2 additions & 0 deletions src/editor/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ fn injected(name: &str) -> Option<&'static HighlightConfiguration> {
pub fn highlight(language: &str, text: &str) -> Option<Vec<Vec<Span>>> {
let config = configs().get(language)?;
let mut highlighter = Highlighter::new();
// The closure isn't redundant: passed bare, `injected` ties its result to the highlighter's lifetime and won't compile.
#[allow(clippy::redundant_closure)]
let events = highlighter.highlight(config, text.as_bytes(), None, |name| injected(name)).ok()?;
let starts: Vec<usize> = std::iter::once(0).chain(text.match_indices('\n').map(|(i, _)| i + 1)).collect();
let mut lines: Vec<Vec<Span>> = vec![vec![]; starts.len()];
Expand Down
4 changes: 2 additions & 2 deletions src/editor/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ impl Editor {
true
}
("c", false) => {
tx.copy(&self.take_for_clipboard(false));
tx.copy(self.take_for_clipboard(false));
true
}
("x", false) => {
tx.copy(&self.take_for_clipboard(true));
tx.copy(self.take_for_clipboard(true));
true
}
("v", false) => {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Editor {
/// The closer `c` is already next to the caret: move past it instead of typing another.
fn step_over(&mut self, c: char, at: Pos) -> bool {
let line = self.buffer.line(at.line);
if line[at.col..].chars().next() != Some(c) || escaped(&line[..at.col]) {
if !line[at.col..].starts_with(c) || escaped(&line[..at.col]) {
return false;
}
let Some(&(open, close)) = PAIRS.iter().find(|(_, cl)| *cl == c) else { return false };
Expand Down
18 changes: 8 additions & 10 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ mod tests {
let total = 1;
}
").unwrap();
let hits = search(&[file.clone()], "total", 100, &|| false);
let hits = search(std::slice::from_ref(&file), "total", 100, &|| false);
assert_eq!(hits, [Hit { path: file.clone(), line: 1, text: "let total = 1;".into() }]);
let Ok(Contents::Text { text, .. }) = read(&file) else { panic!("readable") };
assert_eq!(text.lines().nth(hits[0].line).unwrap().trim(), hits[0].text, "the editor has the same line there");
Expand Down Expand Up @@ -780,15 +780,13 @@ nothing
fn tabs_after_the_indent_are_shown_too() {
let tmp = tempfile::tempdir().unwrap();
let p = tmp.path().join("a.go");
for (file, shown, why) in [
("type A struct {\n\tName\tstring\n\tId\tint\n}\n", "type A struct {\n Name string\n Id int\n}\n", "tabs that align"),
] {
fs::write(&p, file).unwrap();
let Contents::Text { text, format, stamp: s } = read(&p).unwrap() else { panic!("not text") };
assert_eq!(text, shown, "{why}");
save(&p, &text, format, Some(s)).unwrap();
assert_eq!(fs::read_to_string(&p).unwrap(), file, "{why}: saved unchanged");
}
// Tabs that align.
let file = "type A struct {\n\tName\tstring\n\tId\tint\n}\n";
fs::write(&p, file).unwrap();
let Contents::Text { text, format, stamp: s } = read(&p).unwrap() else { panic!("not text") };
assert_eq!(text, "type A struct {\n Name string\n Id int\n}\n");
save(&p, &text, format, Some(s)).unwrap();
assert_eq!(fs::read_to_string(&p).unwrap(), file, "saved unchanged");
// A line edited by hand keeps the tabs of its indent, not the ones inside it.
fs::write(&p, "type A struct {\n\tName\tstring\n}\n").unwrap();
let Contents::Text { format, stamp: s, .. } = read(&p).unwrap() else { panic!("not text") };
Expand Down
Loading