mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Slice the before_window at char boundaries (#4028)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
b302ecc1e8
commit
329b0f9b8d
@ -1053,7 +1053,7 @@ impl<'a> CompletionContext<'a> {
|
|||||||
|
|
||||||
/// A small window of context before the cursor.
|
/// A small window of context before the cursor.
|
||||||
fn before_window(&self, size: usize) -> &str {
|
fn before_window(&self, size: usize) -> &str {
|
||||||
&self.before[self.cursor.saturating_sub(size)..]
|
Scanner::new(self.before).from(self.cursor.saturating_sub(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a prefix and suffix to all applications.
|
/// Add a prefix and suffix to all applications.
|
||||||
@ -1433,4 +1433,12 @@ mod tests {
|
|||||||
test("#i", 2, &["int", "if conditional"], &["foo"]);
|
test("#i", 2, &["int", "if conditional"], &["foo"]);
|
||||||
test("#().", 4, &["insert", "remove", "len", "all"], &["foo"]);
|
test("#().", 4, &["insert", "remove", "len", "all"], &["foo"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_before_window_char_boundary() {
|
||||||
|
// Check that the `before_window` doesn't slice into invalid byte
|
||||||
|
// boundaries.
|
||||||
|
let s = "😀😀 #text(font: \"\")";
|
||||||
|
test(s, s.len() - 2, &[], &[]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user