本文整理匯總了TypeScript中wed/caret-manager.CaretManager.getNormalizedCaret方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CaretManager.getNormalizedCaret方法的具體用法?TypeScript CaretManager.getNormalizedCaret怎麽用?TypeScript CaretManager.getNormalizedCaret使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wed/caret-manager.CaretManager
的用法示例。
在下文中一共展示了CaretManager.getNormalizedCaret方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("unwraps elements", () => {
const initial = editor.dataRoot.getElementsByTagName("title")[0];
// Make sure we are looking at the right thing.
assert.equal(initial.childNodes.length, 1);
assert.equal(initial.firstChild!.textContent, "abcd");
caretManager.setCaret(initial, 0);
let caret = caretManager.getNormalizedCaret()!;
assert.equal(caret.node.childNodes[caret.offset].nodeValue, "abcd");
let trs = editor.modeTree.getMode(initial)
.getContextualActions(["wrap"], "hi", initial, 0);
caretManager.setCaret(initial.firstChild, 1);
caret = caretManager.getNormalizedCaret()!;
caretManager.setRange(caret, caret.makeWithOffset(caret.offset + 2));
trs[0].execute({ node: undefined, name: "hi" });
const node = initial.getElementsByTagName("hi")[0];
trs = editor.modeTree.getMode(node).getContextualActions(["unwrap"], "hi",
node, 0);
trs[0].execute({ node, element_name: "hi" });
assert.equal(initial.childNodes.length, 1, "length after unwrap");
assert.equal(initial.firstChild!.textContent, "abcd");
});
示例2: it
it("when there is no caret", async () => {
const initial = guiRoot.getElementsByClassName("title")[0].childNodes[1];
assert.isUndefined(caretManager.getNormalizedCaret());
activateContextMenu(editor, initial.parentNode as Element);
await delay(1);
// tslint:disable-next-line:no-any
assert.isDefined((menuManager as any).currentDropdown,
"dropdown defined");
assert.isDefined(caretManager.getNormalizedCaret(), "caret defined");
});
示例3: async
"outside wed", async () => {
caretManager.clearSelection(); // Also clears the caret.
assert.isUndefined(caretManager.getNormalizedCaret());
activateContextMenu(editor,
guiRoot.getElementsByClassName("title")[0]);
await delay(1);
// tslint:disable-next-line:no-any
assert.isDefined((menuManager as any).currentDropdown);
});
示例4: it
it("element becoming empty acquires a placeholder", () => {
// Text node inside title.
const initial = editor.dataRoot.getElementsByTagName("title")[0];
// Make sure we are looking at the right thing.
assert.equal(initial.childNodes.length, 1);
assert.equal(initial.firstChild!.textContent, "abcd");
caretManager.setCaret(initial, 0);
const caret = caretManager.getNormalizedCaret()!;
assert.equal(caret.node.childNodes[caret.offset].nodeValue, "abcd");
// Delete all contents.
editor.dataUpdater.removeNode(initial.firstChild);
// We should have a placeholder now, between the two labels.
assert.equal(caret.node.childNodes.length, 3);
assert.isTrue((caret.node.childNodes[1] as Element).classList.contains(
"_placeholder"));
});
示例5: it
it("clicking a phantom element after typing text works", (done) => {
// We create a special phantom element because the generic mode does not
// create any.
const title = editor.guiRoot.getElementsByClassName("title")[0];
const phantom = title.ownerDocument.createElement("span");
phantom.className = "_phantom";
phantom.textContent = "phantom";
title.insertBefore(phantom, null);
// Text node inside paragraph.
const initial = editor.dataRoot.querySelector("body>p")!;
caretManager.setCaret(initial.firstChild, 1);
editor.type(" ");
assert.equal(initial.firstChild!.nodeValue, "B lah blah ");
const caret = caretManager.getNormalizedCaret()!;
// We're simulating how Chrome would handle it. When a mousedown event
// occurs, Chrome moves the caret *after* the mousedown event is processed.
const event = new $.Event("mousedown");
event.target = phantom;
caretManager.setCaret(caret);
// This simulates the movement of the caret after the mousedown event is
// processed. This will be processed after the mousedown handler but before
// _seekCaret is run.
window.setTimeout(() => {
caretManager.setCaret(phantom, 0);
}, 0);
// We trigger the event here so that the order specified above is respected.
$(phantom).trigger(event);
window.setTimeout(() => {
const clickEvent = new $.Event("click");
clickEvent.target = phantom;
$(phantom).trigger(clickEvent);
done();
}, 1);
});
示例6: it
it("works even if there is no caret defined", () => {
editor.caretManager.onBlur();
assert.equal(caretManager.getNormalizedCaret(), undefined, "no caret");
caretManager.move("right");
assert.equal(caretManager.getNormalizedCaret(), undefined, "no caret");
});