mirror of
https://github.com/wassname/talk.git
synced 2026-07-09 06:24:18 +08:00
Fix append new line after node..
This commit is contained in:
@@ -286,22 +286,6 @@ export function isSelectionInside(...nodes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a newline to the node.
|
||||
*/
|
||||
export function appendNewLine(node, changeSelection) {
|
||||
const el = document.createElement('br');
|
||||
node.appendChild(el);
|
||||
|
||||
if (changeSelection) {
|
||||
const offset = indexOfChildNode(node, el);
|
||||
const range = document.createRange();
|
||||
range.setStart(node, offset);
|
||||
range.setEnd(node, offset);
|
||||
replaceSelection(range);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert new line. This is what happens
|
||||
* when adding new lines through pressing Enter.
|
||||
@@ -344,17 +328,19 @@ export function insertNewLine(changeSelection) {
|
||||
* Inserts a new line after given node.
|
||||
*/
|
||||
export function insertNewLineAfterNode(node, changeSelection) {
|
||||
if (node.parentNode.lastChild === node) {
|
||||
appendNewLine(node.parentNode, changeSelection);
|
||||
const el = document.createElement('br');
|
||||
if (node.nextSibling) {
|
||||
node.parentNode.insertBefore(el, node.nextSibling);
|
||||
} else {
|
||||
if (changeSelection) {
|
||||
const offset = indexOfChildNode(node.parentNode, node) + 1;
|
||||
const range = document.createRange();
|
||||
range.setStart(node.parentNode, offset);
|
||||
range.setEnd(node.parentNode, offset);
|
||||
replaceSelection(range);
|
||||
}
|
||||
insertNewLine();
|
||||
node.parentNode.appendChild(el);
|
||||
}
|
||||
|
||||
if (changeSelection) {
|
||||
const offset = indexOfChildNode(node.parentNode, el);
|
||||
const range = document.createRange();
|
||||
range.setStart(node.parentNode, offset);
|
||||
range.setEnd(node.parentNode, offset);
|
||||
replaceSelection(range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user