editor.focus();
const sel = window.getSelection();
sel.collapse(editor.childNodes[0], editor.textContent.length);
(function testInsertEmptyTextNodeWhenCaretIsAtEndOfComposition() {
const description = "testInsertEmptyTextNodeWhenCaretIsAtEndOfComposition: ";
synthesizeCompositionChange({
composition: {
string: "DEF",
clauses: [
{ length: 3, attr: COMPOSITION_ATTR_RAW_CLAUSE },
],
},
caret: { start: 3, length: 0 },
});
is(
editor.textContent, "ABCDEF",
`${description} Composing text "DEF" should be inserted at end of the text node`
);
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
is(
editor.childNodes[0].data, "ABCDEF",
`${
description
} First text node should have both preceding text and the composing text`
);
is(
editor.childNodes[1].data, "",
`${description} Second text node should be empty`
);
})();
(function testInsertEmptyTextNodeWhenCaretIsAtStartOfComposition() {
const description = "testInsertEmptyTextNodeWhenCaretIsAtStartOfComposition: ";
synthesizeCompositionChange({
composition: {
string: "GHI",
clauses: [
{ length: 3, attr: COMPOSITION_ATTR_CONVERTED_CLAUSE },
],
},
caret: { start: 0, length: 0 },
});
is(
editor.textContent, "ABCGHI",
`${description} Composing text should be replaced with new one`
);
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
is(
editor.childNodes[0].data, "ABC",
`${
description
} First text node should have only the preceding text of the composition`
);
is(
editor.childNodes[1].data, "",
`${description} Second text node should have be empty`
);
is(
editor.childNodes[2].data, "GHI",
`${description} Third text node should have only composing text`
);
})();
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
is(
editor.childNodes[0].data, "ABC",
`${
description
} First text node should have only the preceding text of the composition`
);
is(
editor.childNodes[1].data, "",
`${description} Second text node should have be empty`
);
is(
editor.childNodes[2].data, "JKL",
`${description} Third text node should have only composing text`
);
})();
// Normal selection is the caret, therefore, inserting empty text node
// creates the following DOM tree:
// <div contenteditable>
// |- #text ("ABCM")
// |- #text ("")
// +- #text ("NO")
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
is(
editor.childNodes[0].data, "ABCM",
`${
description
} First text node should have the preceding text and composing string before the split point`
);
is(
editor.childNodes[1].data, "",
`${description} Second text node should be empty`
);
is(
editor.childNodes[2].data, "NO",
`${
description
} Third text node should have the remaining composing string`
);
todo_is(editor.childNodes[3].nodeName, "BR", "Forth node is empty text node, but I don't where this comes from");
})();
// Then, committing composition makes the commit string into the first
// text node and makes the following text nodes empty.
// XXX I don't know whether the empty text nodes should be removed or not
// at this moment.
(function testCommitComposition() {
const description = "testCommitComposition: ";
synthesizeComposition({ type: "compositioncommitasis" });
is(
editor.textContent, "ABCMNO",
`${description} Composing text should be committed as-is`
);
is(
editor.childNodes[0].data, "ABCMNO",
`${description} First text node should have the committed string`
);
})();
(function testUndoComposition() {
const description = "testUndoComposition: ";
synthesizeKey("Z", { accelKey: true });
is(
editor.textContent, "ABC",
`${description} Text should be undone (commit string should've gone)`
);
is(
editor.childNodes[0].data, "ABC",
`${description} First text node should have all text`
);
})();
(function testUndoAgain() {
const description = "testUndoAgain: ";
synthesizeKey("Z", { accelKey: true, shiftKey: true });
is(
editor.textContent, "ABCMNO",
`${description} Text should be redone (commit string should've be back)`
);
is(
editor.childNodes[0].data, "ABCMNO",
`${description} First text node should have all text`
);
})();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.