mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 02:06:54 -06:00
story.replaceRange: convert offsets with usize::try_from (wasm32-safe)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
251ceda1e0
commit
0d0fa585a0
@@ -125,8 +125,12 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
has_doc,
|
||||
|s, p| {
|
||||
let sid = StoryId(p.get("story").and_then(Value::as_u64).ok_or_else(|| bad("story.replaceRange", "missing story"))?);
|
||||
let a = p.get("start").and_then(Value::as_u64).unwrap_or(0) as usize;
|
||||
let b = p.get("end").and_then(Value::as_u64).map(|v| v as usize).unwrap_or(a);
|
||||
let offset = |v: u64| usize::try_from(v).map_err(|_| bad("story.replaceRange", format!("offset {v} is out of range")));
|
||||
let a = offset(p.get("start").and_then(Value::as_u64).unwrap_or(0))?;
|
||||
let b = match p.get("end").and_then(Value::as_u64) {
|
||||
Some(v) => offset(v)?,
|
||||
None => a,
|
||||
};
|
||||
let text = super::text_param(p, "text");
|
||||
s.edit(|d, sel| {
|
||||
let st = d.story_mut(sid).ok_or(designcraft_doc::DocError::NoStory(sid))?;
|
||||
|
||||
Reference in New Issue
Block a user