mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Fix crash with "wrap-lines" text editor operation if prefix or suffix is missing
Fixes #6376
This commit is contained in:
parent
4e01fc1838
commit
88812092fd
@ -13,15 +13,17 @@ Text editor operation to wrap the selected lines with a prefix and suffix
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports["wrap-lines"] = function(event,operation) {
|
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
|
// Cut just past the preceding line break, or the start of the text
|
||||||
operation.cutStart = $tw.utils.findPrecedingLineBreak(operation.text,operation.selStart);
|
operation.cutStart = $tw.utils.findPrecedingLineBreak(operation.text,operation.selStart);
|
||||||
// Cut to just past the following line break, or to the end of the text
|
// Cut to just past the following line break, or to the end of the text
|
||||||
operation.cutEnd = $tw.utils.findFollowingLineBreak(operation.text,operation.selEnd);
|
operation.cutEnd = $tw.utils.findFollowingLineBreak(operation.text,operation.selEnd);
|
||||||
// Add the prefix and suffix
|
// Add the prefix and suffix
|
||||||
operation.replacement = event.paramObject.prefix + "\n" +
|
operation.replacement = prefix + "\n" +
|
||||||
operation.text.substring(operation.cutStart,operation.cutEnd) + "\n" +
|
operation.text.substring(operation.cutStart,operation.cutEnd) + "\n" +
|
||||||
event.paramObject.suffix + "\n";
|
suffix + "\n";
|
||||||
operation.newSelStart = operation.cutStart + event.paramObject.prefix.length + 1;
|
operation.newSelStart = operation.cutStart + prefix.length + 1;
|
||||||
operation.newSelEnd = operation.newSelStart + (operation.cutEnd - operation.cutStart);
|
operation.newSelEnd = operation.newSelStart + (operation.cutEnd - operation.cutStart);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user