The bug
When writing in a book & quill and a word jumps to the next line on the last letter, it will jump back when the space bar is struck. However, in the signed book, that word will be on the next line and if the text on the page is over 13 lines long, a line of text will be lost. I have illustrated this in the screenshots below.
P.S.: Yes, I know this has been reported before but that report was written off as a duplicate to another issue that was not related. MC-78858 was not a duplicate of MC-31113.
Code analysis
Based on 1.11 decompiled using MCP 9.35 rc1
Automatic linebreak for valid text lengths while editing
The last word appears in the new line because the method net.minecraft.client.gui.GuiScreenBook.drawScreen(int, int, float)
just appends the cursor (flashing _
) to the text which increases the length. One possible approach to fix this might be to use the method net.minecraft.client.gui.GuiUtilRenderComponents.splitText(ITextComponent, int, FontRenderer, boolean, boolean)
and then test if the cursor character can be appended to the last ITextComponent
item and if not a new ITextComponentItem
has to be added (this would probably solve the second bug as well).
Automatic linebreak while editing differs from signed version
The reason here is similar to the one for MC-83469 and is caused by the two different rendering methods.net.minecraft.client.gui.GuiUtilRenderComponents.splitText(ITextComponent, int, FontRenderer, boolean, boolean)
splits a string before the character which causes the string to exceed a given rendering width, whereas net.minecraft.client.gui.FontRenderer.drawSplitString(String, int, int, int, int)
splits it after the character which exceeded the given width. (Please correct me here if I am wrong).
Related issues
Attachments
Comments


An obvious work around is to create a page break when a word jumps to the next line on the last letter then jumps back when the space bar is struck. That way, the text in the GUI will match what the signed book will display and you won't suffer the frustration of having to re-write an entire book because you lost text on the first page. Again, I would like to describe this bug and the work around in the MineCraft wiki page for Book and Quill if it is not going to be fixed.

I don't know enough about the code to know if one glitch could cause both problems but the 2 cases report different results. MC-83469 states that formatting doesn't stay when the book is signed if it has carried down from a previous line. MC-99863 reports a difference in where the line breaks fall after signing the book. At the very least if MC-83469 gets resolved, MC-99863 should be re-tested, not discarded because of a similarity that may not be relevant.

Is this still an issue in the latest snapshot 16w44a? If so please update the affected versions.
This is an automated comment on any open or reopened issue with out-of-date affected versions.

I just tested this in 1.13.1 and it appears to be resolved. I used the same process to test as I did to confirm the bug and the text behaved as before with a word that brought the line to 20 characters going to the next line, then jumping back when a space was added after it. This duplicated pictures glitch1 and glitch2 shown above. HOWEVER, the text stayed the same when the book was signed and there was no text lost. Thank you for fixing this!

I was still able to reproduce.