From 2b0318f7193d872cc14bae74e6e3396b6bf2bc16 Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 9 Jun 2024 01:54:36 -0400 Subject: [PATCH] lab/text: add with/without word wrap option to # of lines block (#1497) --- extensions/lab/text.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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);