Skip to content

Commit

Permalink
Graphics.wrapString fix issue with missing final char if immediately …
Browse files Browse the repository at this point in the history
…after a '.' or other char we can split after (fix #2572)

# Conflicts:
#	ChangeLog
  • Loading branch information
gfwilliams committed Dec 6, 2024
1 parent d6d1d73 commit a5f01e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
Fix parsing of semicolons in DO with a statement: `do print(a);while(a--);`
In SAVE_ON_FLASH builds (Microbit 1) remove getSerial, Math.LN*/LOG*SQRT* constants, passwords, Serial/I2C/SPI.find, Date.toUTCString
ESP32: add setIP and setAPIP
Graphics.wrapString fix issue with missing final char if immediately after a '.' or other char we can split after (#2572)

2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'
Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off)
Expand Down
5 changes: 4 additions & 1 deletion libs/graphics/jswrap_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,10 @@ JsVar *jswrap_graphics_wrapString(JsVar *parent, JsVar *str, int maxWidth) {
wasNewLine = ch=='\n';
canSplitAfter = ch==0; // can split after if there is an image next
if (endOfText) break;
if (ch!=0) continue; // allow us to handle images next
if (ch!=0) {
if (!jsvStringIteratorHasChar(&it)) endOfText=true; // handle sometimes missed final char: #2572
continue; // allow us to handle images next
}
}
canSplitAfter = false;
#ifndef SAVE_ON_FLASH
Expand Down
5 changes: 5 additions & 0 deletions tests/test_graphics_wrapString.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ g.clear().setFont("4x6:2");
lines = g.wrapString("Hello there lots of text here", 64);
SHOULD_BE(lines, ["Hello","there","lots of","text","here"]);

// char at end missing: https://github.com/espruino/Espruino/issues/2572
g.clear().setFont("4x6");
lines = g.wrapString('test.a', 100);
SHOULD_BE(lines, ["test.a"]);

// wrap string correctly when an image is inline
var g = Graphics.createArrayBuffer(32,16,8);
g.clear().setFont("4x6");
Expand Down

0 comments on commit a5f01e3

Please sign in to comment.