From a5f01e3df3f43210fdab7af2c58052b77aec1476 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 6 Dec 2024 08:51:51 +0000 Subject: [PATCH] Graphics.wrapString fix issue with missing final char if immediately after a '.' or other char we can split after (fix #2572) # Conflicts: # ChangeLog --- ChangeLog | 1 + libs/graphics/jswrap_graphics.c | 5 ++++- tests/test_graphics_wrapString.js | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3ab5432ae7..861636107f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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) diff --git a/libs/graphics/jswrap_graphics.c b/libs/graphics/jswrap_graphics.c index e230340c49..455d23d3cd 100644 --- a/libs/graphics/jswrap_graphics.c +++ b/libs/graphics/jswrap_graphics.c @@ -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 diff --git a/tests/test_graphics_wrapString.js b/tests/test_graphics_wrapString.js index b742e44ebe..7e6765f756 100644 --- a/tests/test_graphics_wrapString.js +++ b/tests/test_graphics_wrapString.js @@ -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");