Files
wordcraft/docs
MichaelandClaude Sonnet 5.5 c8f103c148 MCP: type_text with paragraphs is one command (#3973)
It was a text.newParagraph and a text.insert per line. Each Session::run
that edits snapshots the whole document for Undo and for rollback, so a
command costs about the document's size: 10,000 lines took 2.8 s through
MCP (release build; doubling the lines cost 2.4-3.2x), and left an Undo
step per line. text.insert already takes a carriage return as a paragraph
break, so the lines go in as one command: ~10 ms for 10,000 (linear), one
Undo step.

Measured per call on a 10,000-paragraph document (release, microseconds):
text.newParagraph 188 in run (61 + 66 for the two snapshots, 53 in the
handler), text.insert of one character 85 (47 snapshot, 31 handler), and
caret.docEnd 261, all in its handler (it finds the last paragraph by
listing them all). The snapshots are the bulk, which is why a command per
line cannot be linear; this does not change them.

Behaviour: a CRLF is one break, not two (the per-line way inserted the
carriage return as a break and then added its own). The breaks no longer
run Enter's AutoCorrect: the per-line way capitalised every line but the
last (no Enter followed it) and fixed typos there, so what came out
depended on the line's place; the text now goes in as written, as the
tool's raw insert already did within each line.

Test: the paragraphs made equal those of the per-line way (in a list and
not, blank lines, leading and trailing breaks, indents, tabs) for text
AutoCorrect has nothing to change; lowercase lines and a typo stay as
written; CRLF; one Undo removes every line. Fails on the old code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 18:14:33 +08:00
..