Replace textarea.value calls
This commit is contained in:
+10
-4
@@ -49,22 +49,28 @@ window.EditorMovie = (function () {
|
||||
return out.join('\n');
|
||||
}
|
||||
|
||||
function replaceRange(ta, start, end, text) {
|
||||
ta.focus();
|
||||
ta.selectionStart = start;
|
||||
ta.selectionEnd = end;
|
||||
document.execCommand('insertText', false, text);
|
||||
}
|
||||
|
||||
function insertOrReplace(ta, markup) {
|
||||
var t = ta.value || '';
|
||||
var b = t.indexOf(BEGIN);
|
||||
var e = t.indexOf(END);
|
||||
if (b !== -1 && e !== -1 && e > b) {
|
||||
ta.value = t.slice(0, b) + markup + t.slice(e + END.length);
|
||||
replaceRange(ta, b, e + END.length, markup);
|
||||
} else {
|
||||
var h = t.match(/^#{1,6}\s+.+?\s*$/m);
|
||||
if (h) {
|
||||
var idx = t.indexOf(h[0]) + h[0].length;
|
||||
ta.value = t.slice(0, idx) + '\n\n' + markup + t.slice(idx);
|
||||
replaceRange(ta, idx, idx, '\n\n' + markup);
|
||||
} else {
|
||||
ta.value = markup + (t ? '\n\n' + t : '');
|
||||
replaceRange(ta, 0, 0, t ? markup + '\n\n' : markup);
|
||||
}
|
||||
}
|
||||
ta.dispatchEvent(new Event('input'));
|
||||
}
|
||||
|
||||
function fetchMovie(title, year) {
|
||||
|
||||
Reference in New Issue
Block a user