diff --git a/lib/scripts/toolbar.js b/lib/scripts/toolbar.js index 3ad370ff5e9bae2354e91c094d43a62e2ee2f1fb..4f7aca12e7d2b1c5dcd03878e5ef1520c790c7a5 100644 --- a/lib/scripts/toolbar.js +++ b/lib/scripts/toolbar.js @@ -96,16 +96,26 @@ function tb_formatln(btn, props, edid) { } sample = fixtxt(sample); - var selection = getSelection($(edid)); - if(selection.getLength()) sample = selection.getText(); - props['open'] = fixtxt(props['open']); props['close'] = fixtxt(props['close']); + // is something selected? + var opts; + var selection = getSelection($(edid)); + if(selection.getLength()){ + sample = selection.getText(); + opts = {nosel: true}; + }else{ + opts = { + startofs: props['open'].length, + endofs: props['close'].length + }; + } + sample = sample.split("\n").join(props['close']+"\n"+props['open']); sample = props['open']+sample+props['close']; - pasteText(selection,sample,{nosel: true}); + pasteText(selection,sample,opts); pickerClose(); return false;