DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
MCP: document that text offsets and story lengths are UTF-8 bytes (#68)
aiongg75aa5356bac3
diff --git a/crates/mcp/src/tools.rs b/crates/mcp/src/tools.rsindex dc2604c5b..9b9869872 100644--- a/crates/mcp/src/tools.rs+++ b/crates/mcp/src/tools.rs@@ -137,16 +137,17 @@ pub fn tool_definitions() -> Vec<Value> {"inspect_document","Inspect document","Summary of the active document: settings, pages (index, name, bounds, margins, columns), spreads with items (id, kind, \- bounds, fill, stroke, story), stories (id, frames, length, overset, preview), layers, paragraph/character styles, \- swatches, selection, active tool.",+ bounds, fill, stroke, story), stories (id, frames, length in UTF-8 bytes, overset, preview), layers, \+ paragraph/character styles, swatches, selection, active tool.",empty(),true,),tool("get_story","Get story",- "Full text of a story plus its frames, paragraph count, line count and overset position. Identify it by `story` id or \- by a text `frame` id (default: the selection).",+ "Full text of a story plus its length, frames, paragraph count, line count and overset position (length and positions \+ are UTF-8 byte offsets, the unit text.select takes). Identify it by `story` id or by a text `frame` id (default: the \+ selection).",obj(json!({"story": int("Story id"), "frame": int("Text frame id")}), &[]),true,),diff --git a/docs/mcp.md b/docs/mcp.mdindex 2181fef92..29aeff5f8 100644--- a/docs/mcp.md+++ b/docs/mcp.md@@ -43,6 +43,14 @@ spread the right page starts at x = page width. `inspect_document` lists page bo`render_page` / `export_png` are 0-based. `pointer` events in connected mode may use `"space": "screen"` (egui points,see `ui_inspect` → `canvasRect`).+## Text offsets++Positions in a story's text are **UTF-8 byte offsets**, not character counts: `anchor` / `focus` of `text.select`,+`start` / `end` of `story.replaceRange` and of `find.find` matches, the `pos` that `text.placeCaret`, `text.insert`+and `text.move` return, a story's `length` in `get_story` and `inspect_document`, and its `overset` position in+`get_story`. A character outside ASCII takes 2 to 4 bytes (é 2, — and は 3), so the story `はただ商店` has length 15+and its second character starts at 3. An offset inside a character snaps back to the start of that character.+## Tools| Tool | What it does |