Fix for webassembly

This commit is contained in:
Andras Schmelczer 2024-12-06 20:47:06 +00:00
parent 701425ba02
commit 9b5c663740
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
3 changed files with 32 additions and 22 deletions

View file

@ -101,13 +101,14 @@ where
deleted_text,
..
} => {
if let Some(text) = deleted_text {
debug_assert_eq!(
builder.get_slice(self.range()),
*text,
"Text to delete does not match the text in the rope"
);
}
#[cfg(debug_assertions)]
debug_assert!(
deleted_text
.as_ref()
.map(|text| builder.get_slice(self.range()) == *text)
.unwrap_or(true),
"Text to delete does not match the text in the rope"
);
builder.delete(self.range());
}
@ -313,20 +314,24 @@ where
#[cfg(debug_assertions)]
deleted_text,
} => {
if cfg!(debug_assertions) && deleted_text.is_some() {
write!(
f,
"<delete '{}' from index {}>",
deleted_text.as_ref().unwrap_or(&"<unknown>".to_string()),
index
)
} else {
write!(
f,
"<delete {} characters () from index {}>",
deleted_character_count, index
)
}
#[cfg(debug_assertions)]
write!(
f,
"<delete {} from index {}>",
deleted_text
.as_ref()
.map(|text| format!("'{text}'"))
.unwrap_or(format!("{deleted_character_count} characters")),
index
)?;
#[cfg(not(debug_assertions))]
write!(
f,
"<delete {deleted_character_count} characters from index {index}>",
)?;
Ok(())
}
}
}

View file

@ -1,3 +1,9 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// A token is a string that has been normalised in some way.
/// The normalised form is used for comparison, while the original form is used for applying Operations.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct Token<T>
where

View file

@ -63,7 +63,6 @@ impl StringBuilder<'_> {
self.buffer
}
#[cfg(debug_assertions)]
pub fn get_slice(&self, range: Range<usize>) -> String {
let result = self
.buffer