mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-24 22:33:16 +00:00
parent
0e771e2419
commit
a054d100e7
|
@ -13,12 +13,13 @@ Text editor operation to add a prefix to the selected lines
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports["prefix-lines"] = function(event,operation) {
|
exports["prefix-lines"] = function(event,operation) {
|
||||||
|
var targetCount = parseInt(event.paramObject.count + "",10);
|
||||||
// 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);
|
||||||
// Compose the required prefix
|
// Compose the required prefix
|
||||||
var prefix = $tw.utils.repeat(event.paramObject.character,event.paramObject.count);
|
var prefix = $tw.utils.repeat(event.paramObject.character,targetCount);
|
||||||
// Process each line
|
// Process each line
|
||||||
var lines = operation.text.substring(operation.cutStart,operation.cutEnd).split(/\r?\n/mg);
|
var lines = operation.text.substring(operation.cutStart,operation.cutEnd).split(/\r?\n/mg);
|
||||||
$tw.utils.each(lines,function(line,index) {
|
$tw.utils.each(lines,function(line,index) {
|
||||||
|
@ -33,7 +34,7 @@ exports["prefix-lines"] = function(event,operation) {
|
||||||
line = line.substring(1);
|
line = line.substring(1);
|
||||||
}
|
}
|
||||||
// We're done if we removed the exact required prefix, otherwise add it
|
// We're done if we removed the exact required prefix, otherwise add it
|
||||||
if(count !== event.paramObject.count) {
|
if(count !== targetCount) {
|
||||||
// Apply the prefix
|
// Apply the prefix
|
||||||
line = prefix + " " + line;
|
line = prefix + " " + line;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user