Books containing the formatting character '§' make the client mismatch the actual character length/text position when clicking the text or moving the cursor using the arrow keys.
Use the following command and right click the placed sign to get a book and reproduce the issue:
/setblock ~ ~1 ~ minecraft:oak_sign{front_text:{messages:['{"text":"Click me","clickEvent":{"action":"run_command","value":"/give @s minecraft:writable_book[minecraft:writable_book_content={pages:[\\"\\u00a7nVery cool text\\n\\u00a7r \\u00a7\\u00a7\\u00a7\\u00a7 hi\\n\\u00a75more\\n\\u00a7etext\\"]}]"}}', '""', '""', '""']}}
In older versions, the command would be:
/setblock ~ ~ ~ oak_sign{Text1:"{\"text\":\"Click me\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/give @p writable_book{pages:[\\\"\\u00a7nVery cool text\\n\\u00a7r \\u00a7\\u00a7\\u00a7\\u00a7 hi\\n\\u00a75more\\n\\u00a7etext\\\"]}\"}}"}(This can also be reproduced without extra commands by having a book with the formatting character in a 1.13 world by copy-pasting text into it, and upgrading/opening that world with a 1.14+ client.)
See attached screenshot: clicking text after a formatting symbol misplaces the cursor a few characters before the click position. Moving the cursor with the arrow keys requires multiple presses to go past the formatting character (see also MC-181673).
Linked issues
relates to 3
Attachments
Comments 7
Created a separate issue for the character removal MC-181673
This command doesn't work anymore as of 24w36a so I cannot reproduce this.
Could you provide updated reproduction steps?
Code analysis (26.3): MultilineTextField#seekCursorToPoint gets the character index corresponding to the x-position by calling Font#plainSubstrByWidth, which eventually lands in StringSplitter#plainIndexAtWidth. plainIndexAtWidth uses StringDecomposer#iterate to iterate through all the characters in the string without considering formatting codes, even though MultilineTextField accounts for formatting codes when wrapping and MultilineEditBox does so when rendering the text. This could be solved by calling StringDecomposer#iterateFormatted instead.
also a problem in bedrock