parent
09b622f84c
commit
fecebc7991
1 changed files with 22 additions and 3 deletions
|
@ -44,9 +44,18 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
gl.text.insertText = function(textArea, text, tag, blockTag, selected, wrap) {
|
gl.text.insertText = function(textArea, text, tag, blockTag, selected, wrap) {
|
||||||
var insertText, inserted, selectedSplit, startChar;
|
var insertText, inserted, selectedSplit, startChar, removedLastNewLine;
|
||||||
|
removedLastNewLine = false;
|
||||||
|
|
||||||
|
// Remove the last newline
|
||||||
|
if (textArea.selectionEnd - textArea.selectionStart > selected.replace(/\n$/, '').length) {
|
||||||
|
removedLastNewLine = true;
|
||||||
|
selected = selected.replace(/\n$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
selectedSplit = selected.split('\n');
|
selectedSplit = selected.split('\n');
|
||||||
startChar = !wrap && textArea.selectionStart > 0 ? '\n' : '';
|
startChar = !wrap && textArea.selectionStart > 0 ? '\n' : '';
|
||||||
|
|
||||||
if (selectedSplit.length > 1 && (!wrap || (blockTag != null))) {
|
if (selectedSplit.length > 1 && (!wrap || (blockTag != null))) {
|
||||||
if (blockTag != null) {
|
if (blockTag != null) {
|
||||||
insertText = this.blockTagText(text, textArea, blockTag, selected);
|
insertText = this.blockTagText(text, textArea, blockTag, selected);
|
||||||
|
@ -62,6 +71,11 @@
|
||||||
} else {
|
} else {
|
||||||
insertText = "" + startChar + tag + selected + (wrap ? tag : ' ');
|
insertText = "" + startChar + tag + selected + (wrap ? tag : ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (removedLastNewLine) {
|
||||||
|
insertText += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
if (document.queryCommandSupported('insertText')) {
|
if (document.queryCommandSupported('insertText')) {
|
||||||
inserted = document.execCommand('insertText', false, insertText);
|
inserted = document.execCommand('insertText', false, insertText);
|
||||||
}
|
}
|
||||||
|
@ -74,9 +88,9 @@
|
||||||
document.execCommand("ms-endUndoUnit");
|
document.execCommand("ms-endUndoUnit");
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
return this.moveCursor(textArea, tag, wrap);
|
return this.moveCursor(textArea, tag, wrap, removedLastNewLine);
|
||||||
};
|
};
|
||||||
gl.text.moveCursor = function(textArea, tag, wrapped) {
|
gl.text.moveCursor = function(textArea, tag, wrapped, removedLastNewLine) {
|
||||||
var pos;
|
var pos;
|
||||||
if (!textArea.setSelectionRange) {
|
if (!textArea.setSelectionRange) {
|
||||||
return;
|
return;
|
||||||
|
@ -87,6 +101,11 @@
|
||||||
} else {
|
} else {
|
||||||
pos = textArea.selectionStart;
|
pos = textArea.selectionStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (removedLastNewLine) {
|
||||||
|
pos -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
return textArea.setSelectionRange(pos, pos);
|
return textArea.setSelectionRange(pos, pos);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue