diff options
| author | Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com> | 2024-05-06 22:00:51 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-06 14:00:51 +0000 |
| commit | 329b0f9b8d9ea5cafbfd6c7a8f92a9d13738b841 (patch) | |
| tree | 6a9b148622ece38ecceb541643aae0ac64e3606c /crates | |
| parent | b302ecc1e833da62faa56cc5fed83b0b9befd76f (diff) | |
Slice the before_window at char boundaries (#4028)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst-ide/src/complete.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs index c758dd1c..279e0493 100644 --- a/crates/typst-ide/src/complete.rs +++ b/crates/typst-ide/src/complete.rs @@ -1053,7 +1053,7 @@ impl<'a> CompletionContext<'a> { /// A small window of context before the cursor. 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. @@ -1433,4 +1433,12 @@ mod tests { test("#i", 2, &["int", "if conditional"], &["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, &[], &[]); + } } |
