Remove markdown on toolbar click

pull/7748/head
Diego Sampaio 8 years ago
parent 22d38ed268
commit e0631f74d1
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 31
      packages/rocketchat-ui-message/client/messageBox.js

@ -35,6 +35,37 @@ function applyMd(e, t) {
}, 100);
}
box.focus();
// removes markdown if selected text in inside the same clicked markdown
if (selectionStart !== selectionEnd) {
const startPattern = this.pattern.substr(0, this.pattern.indexOf('{{text}}'));
const startPatternFound = [...startPattern].reverse().every((char, index) => {
return box.value.substr(selectionStart - index - 1, 1) === char;
});
if (startPatternFound) {
const endPattern = this.pattern.substr(this.pattern.indexOf('{{text}}') + '{{text}}'.length);
const endPatternFound = [...endPattern].every((char, index) => {
return box.value.substr(selectionEnd + index, 1) === char;
});
if (endPatternFound) {
box.selectionStart = selectionStart - startPattern.length;
box.selectionEnd = selectionEnd + endPattern.length;
if (document.execCommand) {
document.execCommand('insertText', false, selectedText);
} else {
box.value = initText.substr(0, initText.length - startPattern.length) + selectedText + finalText.substr(endPattern.length);
}
box.selectionStart = selectionStart - startPattern.length;
box.selectionEnd = box.selectionStart + selectedText.length;
$(box).change();
return;
}
}
}
/*
get text
apply pattern

Loading…
Cancel
Save