diff --git a/extensions/lab/text.js b/extensions/lab/text.js index 53f911cd82..8fc31edeb2 100644 --- a/extensions/lab/text.js +++ b/extensions/lab/text.js @@ -876,7 +876,25 @@ opcode: "getLines", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate("# of lines"), + hideFromPalette: true, + disableMonitor: true, + extensions: ["colours_looks"], + }, + { + opcode: "getLinesV2", + blockType: Scratch.BlockType.REPORTER, + text: Scratch.translate({ + default: "# of lines [WITH_WORD_WRAP]", + description: + "[WITH_WORD_WRAP] is a menu with choices 'with word wrap' and 'without word wrap'", + }), hideFromPalette: compatibilityMode, + arguments: { + WITH_WORD_WRAP: { + type: Scratch.ArgumentType.STRING, + menu: "twWordWrap", + }, + }, disableMonitor: true, extensions: ["colours_looks"], }, @@ -1179,6 +1197,19 @@ acceptReporters: true, items: "getFonts", }, + twWordWrap: { + acceptReporters: true, + items: [ + { + text: Scratch.translate("with word wrap"), + value: "with word wrap", + }, + { + text: Scratch.translate("without word wrap"), + value: "without word wrap", + }, + ], + }, }, }; } @@ -1382,6 +1413,18 @@ return text.split("\n").length; } + getLinesV2(args, util) { + const drawableID = util.target.drawableID; + const skin = renderer._allDrawables[drawableID].skin; + if (!(skin instanceof TextCostumeSkin)) return 0; + + const state = this._getState(util.target); + if (Scratch.Cast.toString(args.WITH_WORD_WRAP) === "with word wrap") { + return state.skin.lines.length; + } + return state.skin.text.split("\n").length; + } + setAlignment(args, util) { // see setWidth const state = this._getState(util.target);