Skip to content

Commit

Permalink
Fix crash with "wrap-lines" text editor operation if prefix or suffix…
Browse files Browse the repository at this point in the history
… is missing

Fixes #6376
  • Loading branch information
Jermolene committed Jan 9, 2022
1 parent 4e01fc1 commit 8881209
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/modules/editor/operations/text/wrap-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 8881209

Please sign in to comment.