mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Fix suffix computation for Source::replace (#3989)
This commit is contained in:
parent
c8cc252a45
commit
9f8cb27aef
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::iter::zip;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -76,12 +77,8 @@ impl Source {
|
|||||||
pub fn replace(&mut self, new: &str) -> Range<usize> {
|
pub fn replace(&mut self, new: &str) -> Range<usize> {
|
||||||
let old = self.text();
|
let old = self.text();
|
||||||
|
|
||||||
let mut prefix = old
|
let mut prefix =
|
||||||
.as_bytes()
|
zip(old.bytes(), new.bytes()).take_while(|(x, y)| x == y).count();
|
||||||
.iter()
|
|
||||||
.zip(new.as_bytes())
|
|
||||||
.take_while(|(x, y)| x == y)
|
|
||||||
.count();
|
|
||||||
|
|
||||||
if prefix == old.len() && prefix == new.len() {
|
if prefix == old.len() && prefix == new.len() {
|
||||||
return 0..0;
|
return 0..0;
|
||||||
@ -91,11 +88,7 @@ impl Source {
|
|||||||
prefix -= 1;
|
prefix -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut suffix = old[prefix..]
|
let mut suffix = zip(old[prefix..].bytes().rev(), new[prefix..].bytes().rev())
|
||||||
.as_bytes()
|
|
||||||
.iter()
|
|
||||||
.zip(new[prefix..].as_bytes())
|
|
||||||
.rev()
|
|
||||||
.take_while(|(x, y)| x == y)
|
.take_while(|(x, y)| x == y)
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user