本文整理匯總了TypeScript中quill/core.getSelection函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getSelection函數的具體用法?TypeScript getSelection怎麽用?TypeScript getSelection使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getSelection函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: new
export function disableAllBlotsInRange<T extends Blot>(
quill: Quill,
blotConstructor:
| {
new (): T;
}
| typeof Blot,
range: RangeStatic | null = null,
) {
if (range === null) {
range = quill.getSelection()!;
}
const currentBlots = quill.scroll.descendants(blotConstructor as any, range.index, range.length) as Blot[];
const firstBlot = currentBlots[0];
const lastBlot = currentBlots[currentBlots.length - 1];
const startRange = firstBlot && {
index: firstBlot.offset(quill.scroll),
length: firstBlot.length(),
};
const endRange = lastBlot && {
index: lastBlot.offset(quill.scroll),
length: lastBlot.length(),
};
const finalRange = expandRange(range, startRange, endRange);
if (finalRange) {
quill.formatText(finalRange.index, finalRange.length, "link", false, Emitter.sources.USER);
}
}
示例2: it
it("will place focus on a FocusableEmbedBlot if it is the first element in the editor", async () => {
const embed = Parchment.create("embed-loading", stubEmbedData) as LoadingBlot;
quill.scroll.insertBefore(embed, quill.scroll.children.tail!);
const test = quill.insertText(quill.scroll.length(), "test");
embedFocusModule.focusFirstLine();
expect(embed.domNode.contains(document.activeElement) || document.activeElement === embed.domNode).eq(true);
expect(quill.getSelection().index, "The quill selection was incorrect").eq(0);
});
示例3: rangeContainsBlot
export function rangeContainsBlot(quill: Quill, blotConstructor: any, range: RangeStatic | null = null): boolean {
if (range === null) {
range = quill.getSelection();
}
if (!range) {
return false;
}
if (range.length > 0) {
const blots = quill.scroll.descendants(blotConstructor, range.index, range.length);
return blots.length > 0;
} else {
const blot = quill.scroll.descendant(blotConstructor, range.index)[0];
return !!blot;
}
}
示例4: setupTestQuill
const resetQuill = () => {
quill = setupTestQuill();
const buttonCont = document.createElement("div");
buttonCont.innerHTML = `
<div>
<button id="indent">Indent</button>
<button id="outdent">Outdent</button>
</div>`;
document.body.appendChild(buttonCont);
const indent = document.getElementById("indent")!;
const outdent = document.getElementById("outdent")!;
const formatter = new Formatter(quill, quill.getSelection());
indent.addEventListener("click", e => {
e.preventDefault();
formatter.indentList();
});
outdent.addEventListener("click", e => {
e.preventDefault();
formatter.outdentList();
});
quillNode = quill.scroll.domNode as HTMLDivElement;
};