From eed2a7a8355fac44fa7f5b47e0737e80dce13fb7 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Sat, 31 Oct 2020 12:05:37 +0800 Subject: [PATCH] fix fillText --- libs/ui.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/ui.js b/libs/ui.js index 9c548c3e..7fb66c71 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -96,12 +96,12 @@ ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) { else if (textAlign == 'right') x -= textWidth; ctx.textAlign = 'left'; text = text.replace(/\r(?!\[.*\])/g, "\r[" + currentStyle + "]"); - var colorArray = text.match(/(?<=\r\[).*(?=\])/g); - var textArray = text.split(/\r\[.*\]/); + var colorArray = text.match(/\r\[.*?\]/g); + var textArray = text.split(/\r\[.*?\]/); var width = 0; for (var i = 0; i < textArray.length; i++) { var subtext = textArray[i]; - if (colorArray[i-1]) ctx.fillStyle = colorArray[i-1]; + if (colorArray[i-1]) ctx.fillStyle = colorArray[i-1].slice(2, -1); ctx.fillText(subtext, x + width, y); width += core.calWidth(ctx, subtext, x, y); }