Improve docs and compare with alternatives
This commit is contained in:
parent
5962feb90a
commit
3d382ad741
14 changed files with 106 additions and 69 deletions
|
|
@ -15,8 +15,7 @@ pub enum History {
|
|||
RemovedFromRight = "RemovedFromRight",
|
||||
}
|
||||
|
||||
/// Simple enum for describing the result of `reconcile` in a flat list.
|
||||
/// When compiled to WASM, the enum values are the same as their names.
|
||||
/// Provenance label for each span returned by `apply_with_history`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ impl TryFrom<JsValue> for NumberOrText {
|
|||
}
|
||||
|
||||
if let Some(num) = value.clone().as_f64() {
|
||||
if num.is_nan() {
|
||||
return Err(DeserialisationError::new("NaN is not a valid number"));
|
||||
}
|
||||
|
||||
if num.abs() > INTEGRAL_LIMIT {
|
||||
return Err(DeserialisationError::new(
|
||||
"Floating-point number exceeds safe integer limit, use BigInt instead",
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ use wasm_bindgen::prelude::*;
|
|||
|
||||
use crate::types::history::History;
|
||||
|
||||
/// Wrapper type for `(String, History)` where History describes the origin of
|
||||
/// `text`.
|
||||
/// A text span annotated with its origin in a merge result.
|
||||
#[allow(clippy::unsafe_derive_deserialize)]
|
||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@ pub struct TextWithCursors {
|
|||
|
||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||
impl TextWithCursors {
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if any cursor's `char_index` exceeds the text's character length.
|
||||
#[cfg_attr(feature = "wasm", wasm_bindgen(constructor))]
|
||||
#[must_use]
|
||||
pub fn new(text: String, cursors: Vec<CursorPosition>) -> Self {
|
||||
let length = text.chars().count();
|
||||
for cursor in &cursors {
|
||||
debug_assert!(
|
||||
assert!(
|
||||
cursor.char_index <= length,
|
||||
// cursor.char_index == length means that the cursor is at the end
|
||||
"Cursor positions ({}) must be contained within the text (of length {length}) or \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue