From 88812092fd8fa7da18e6da77f9c410338469cc4e Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Sun, 9 Jan 2022 17:43:34 +0000 Subject: [PATCH] Fix crash with "wrap-lines" text editor operation if prefix or suffix is missing Fixes #6376 --- core/modules/editor/operations/text/wrap-lines.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/modules/editor/operations/text/wrap-lines.js b/core/modules/editor/operations/text/wrap-lines.js index 521811f50..b49de3cfb 100644 --- a/core/modules/editor/operations/text/wrap-lines.js +++ b/core/modules/editor/operations/text/wrap-lines.js @@ -13,15 +13,17 @@ Text editor operation to wrap the selected lines with a prefix and suffix "use strict"; exports["wrap-lines"] = function(event,operation) { + var prefix = operation.paramObject.prefix || "", + suffix = operation.paramObject.suffix || ""; // Cut just past the preceding line break, or the start of the text operation.cutStart = $tw.utils.findPrecedingLineBreak(operation.text,operation.selStart); // Cut to just past the following line break, or to the end of the text operation.cutEnd = $tw.utils.findFollowingLineBreak(operation.text,operation.selEnd); // Add the prefix and suffix - operation.replacement = event.paramObject.prefix + "\n" + + operation.replacement = prefix + "\n" + operation.text.substring(operation.cutStart,operation.cutEnd) + "\n" + - event.paramObject.suffix + "\n"; - operation.newSelStart = operation.cutStart + event.paramObject.prefix.length + 1; + suffix + "\n"; + operation.newSelStart = operation.cutStart + prefix.length + 1; operation.newSelEnd = operation.newSelStart + (operation.cutEnd - operation.cutStart); };