本文整理汇总了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;
};