remove redundant ending new line when copying code block in read mode

This commit is contained in:
Le Tan 2019-06-15 10:13:58 +08:00
parent ada7400306
commit 3b1d9e9cbf

View File

@ -278,8 +278,19 @@ window.onwheel = function(e) {
var skipScrollCheckRange = null;
var VClipboardDataTextAttr = 'source-text';
window.addEventListener('load', function() {
new ClipboardJS('.vnote-copy-clipboard-btn');
new ClipboardJS('.vnote-copy-clipboard-btn', {
text: function(trigger) {
var t = trigger.getAttribute(VClipboardDataTextAttr);
if (t[t.length - 1] == '\n') {
return t.substring(0, t.length - 1);
} else {
return t;
}
}
});
});
window.onscroll = function() {
@ -1290,7 +1301,7 @@ var addCopyButtonToCodeBlock = function() {
btn.classList.add('vnote-btn');
btn.classList.add('vnote-copy-clipboard-btn');
btn.setAttribute('type', 'button');
btn.setAttribute('data-clipboard-text', code.textContent);
btn.setAttribute(VClipboardDataTextAttr, code.textContent);
code.insertAdjacentElement('beforebegin', btn);
}
};