本文整理匯總了TypeScript中wed/caret-manager.CaretManager.setCaret方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CaretManager.setCaret方法的具體用法?TypeScript CaretManager.setCaret怎麽用?TypeScript CaretManager.setCaret使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wed/caret-manager.CaretManager
的用法示例。
在下文中一共展示了CaretManager.setCaret方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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("moving the caret scrolls the pane", (done) => {
const initial = editor.dataRoot;
caretManager.setCaret(initial.firstChild, 0);
// tslint:disable-next-line:no-any
const scroller = (editor as any).scroller;
const initialScroll = scroller.scrollTop;
scroller.events.pipe(first()).subscribe(() => {
// We need to wait until the scroller has fired the scroll event.
assert.isTrue(initialScroll < scroller.scrollTop);
const caretRect = editor.caretManager.mark.getBoundingClientRect();
const scrollerRect = scroller.getBoundingClientRect();
assert.equal(distFromRect(caretRect.left, caretRect.top,
scrollerRect.left, scrollerRect.top,
scrollerRect.right,
scrollerRect.bottom),
0, "caret should be in visible space");
done();
});
caretManager.setCaret(initial.firstChild,
initial.firstChild!.childNodes.length);
});
示例3: it
it("prevents pasting in readonly elements and attributes", () => {
const initial = editor.dataRoot.querySelector("bar")!;
const initialGUI =
caretManager.fromDataLocation(initial, 0)!.node as Element;
assert.isTrue(initialGUI.classList.contains("_readonly"));
caretManager.setCaret(initial, 0);
const initialValue = initial.textContent;
// Synthetic event
let event = makeFakePasteEvent({
types: ["text/plain"],
getData: () => "a",
});
editor.$guiRoot.trigger(event);
assert.equal(initial.textContent, initialValue);
dataCaretCheck(editor, initial, 0, "final position");
// Check that removing _readonly would make the paste work. This proves that
// the only thing that was preventing pasting was _readonly.
initialGUI.classList.remove("_readonly");
caretManager.setCaret(initial, 0);
// We have to create a new event.
event = makeFakePasteEvent({
types: ["text/plain"],
getData: () => "a",
});
editor.$guiRoot.trigger(event);
assert.equal(initial.textContent, `a${initialValue}`);
dataCaretCheck(editor, initial.firstChild!, 1, "final position");
});
示例4: it
it("typing multiple spaces in an attribute normalizes the space", () => {
// Text node inside title.
let initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
caretManager.setCaret(initial, 0);
assert.equal(initial.data, "rend_value");
editor.type(" ");
// We have to refetch because the decorations have been redone.
initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
assert.equal(initial.data, " rend_value");
caretCheck(editor, initial, 1, "caret after text insertion");
// Check that the data is also modified
const dataNode = editor.toDataNode(initial) as Attr;
assert.equal(dataNode.value, " rend_value");
editor.type(" ");
// We have to refetch because the decorations have been redone.
initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
assert.equal(initial.data, " rend_value");
caretCheck(editor, initial, 1, "caret after text insertion");
// Check that the data is also modified
assert.equal(dataNode.value, " rend_value");
caretManager.setCaret(initial, 11);
editor.type(" ");
// We have to refetch because the decorations have been redone.
initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
assert.equal(initial.data, " rend_value ");
caretCheck(editor, initial, 12, "caret after text insertion");
// Check that the data is also modified
assert.equal(dataNode.value, " rend_value ");
editor.type(" ");
// We have to refetch because the decorations have been redone.
initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
assert.equal(initial.data, " rend_value ");
caretCheck(editor, initial, 12, "caret after text insertion");
// Check that the data is also modified
assert.equal(dataNode.value, " rend_value ");
});
示例5: it
it("for which the mode provides completion", () => {
const p = ps[13];
const attrVals = getAttributeValuesFor(p);
caretManager.setCaret(attrVals[0].firstChild, 0);
// This is an arbitrary menu item we check for.
contextMenuHasOption(editor, /^completion1$/);
});
示例6: beforeEach
beforeEach(() => {
dataRoot = editor.dataRoot;
caretManager = editor.caretManager;
ps = Array.from(dataRoot.querySelectorAll("body p"));
firstBodyP = ps[0];
firstBodyPLocation = caretManager.mustFromDataLocation(
DLoc.mustMakeDLoc(dataRoot, firstBodyP, 0));
caretManager.setCaret(firstBodyPLocation);
// First 3 text characters in the 5th paragraph (at index 4).
const pFiveStart = DLoc.mustMakeDLoc(dataRoot, ps[4].firstChild, 0);
pFiveFirstThree = new DLocRange(
caretManager.mustFromDataLocation(pFiveStart),
caretManager.mustFromDataLocation(pFiveStart.makeWithOffset(3)));
expect(pFiveFirstThree.mustMakeDOMRange().toString()).to.equal("abc");
pFiveFirstFour = new DLocRange(
caretManager.mustFromDataLocation(pFiveStart),
caretManager.mustFromDataLocation(pFiveStart.makeWithOffset(4)));
expect(pFiveFirstFour.mustMakeDOMRange().toString()).to.equal("abcd");
const pSevenStart = DLoc.mustMakeDLoc(dataRoot, ps[6].firstChild, 0);
pSevenFirstThree = new DLocRange(
caretManager.mustFromDataLocation(pSevenStart),
caretManager.mustFromDataLocation(pSevenStart.makeWithOffset(3)));
expect(pSevenFirstThree.mustMakeDOMRange().toString()).to.equal("abc");
// This is the first "abc" found when doing a TEXT search.
firstABCText = new DLocRange(
caretManager.mustFromDataLocation(ps[3].firstChild!.firstChild!, 0),
caretManager.mustFromDataLocation(ps[3].lastChild!, 1));
});
示例7: it
it("undoing an attribute value change undoes the value change", () => {
let initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
caretManager.setCaret(initial, 4);
assert.equal(initial.data, "rend_value", "initial value");
editor.type("blah");
// We have to refetch because the decorations have been redone.
initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
assert.equal(initial.data, "rendblah_value");
caretCheck(editor, initial, 8, "caret after text insertion");
// Check that the data is also modified
const dataNode = editor.toDataNode(initial) as Attr;
assert.equal(dataNode.value, "rendblah_value");
editor.undo();
// We have to refetch because the decorations have been redone.
initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
assert.equal(initial.data, "rend_value");
caretCheck(editor, initial, 4, "caret after undo");
// Check that the data change has been undone.
assert.equal(dataNode.value, "rend_value", "value undone");
});
示例8: it
it("pasting structured text: invalid, decline pasting as text", (done) => {
const p = editor.dataRoot.querySelector("body>p")!;
const initial = p.firstChild!;
caretManager.setCaret(initial, 0);
const initialValue = p.innerHTML;
// Synthetic event
const event = makeFakePasteEvent({
types: ["text/html", "text/plain"],
getData: () => p.outerHTML,
});
const pasteModal = editor.modals.getModal("paste");
const $top = pasteModal.getTopLevel();
$top.one("shown.bs.modal", () => {
// Wait until visible to add this handler so that it is run after the
// callback that wed sets on the modal.
$top.one("hidden.bs.modal", () => {
assert.equal(p.innerHTML, initialValue);
dataCaretCheck(editor, initial, 0, "final position");
done();
});
});
editor.$guiRoot.trigger(event);
// This clicks "No".
pasteModal.getTopLevel().find(".modal-footer .btn")[1].click();
});