Enable @typescript-eslint/explicit-function-return-type
in /src (#9788)
* Enable `@typescript-eslint/explicit-member-accessibility` on /src * Prettier * Enable `@typescript-eslint/explicit-function-return-type` in /src * Fix types * tsc strict fixes * Delint * Fix test * Fix bad merge
This commit is contained in:
parent
7a36ba0fde
commit
030b7e90bf
683 changed files with 3459 additions and 3013 deletions
|
@ -23,7 +23,7 @@ import Range from "./range";
|
|||
type Predicate = (node: Node) => boolean;
|
||||
type Callback = (node: Node) => void;
|
||||
|
||||
export function walkDOMDepthFirst(rootNode: Node, enterNodeCallback: Predicate, leaveNodeCallback: Callback) {
|
||||
export function walkDOMDepthFirst(rootNode: Node, enterNodeCallback: Predicate, leaveNodeCallback: Callback): void {
|
||||
let node = rootNode.firstChild;
|
||||
while (node && node !== rootNode) {
|
||||
const shouldDescend = enterNodeCallback(node);
|
||||
|
@ -45,12 +45,24 @@ export function walkDOMDepthFirst(rootNode: Node, enterNodeCallback: Predicate,
|
|||
}
|
||||
}
|
||||
|
||||
export function getCaretOffsetAndText(editor: HTMLDivElement, sel: Selection) {
|
||||
export function getCaretOffsetAndText(
|
||||
editor: HTMLDivElement,
|
||||
sel: Selection,
|
||||
): {
|
||||
caret: DocumentOffset;
|
||||
text: string;
|
||||
} {
|
||||
const { offset, text } = getSelectionOffsetAndText(editor, sel.focusNode, sel.focusOffset);
|
||||
return { caret: offset, text };
|
||||
}
|
||||
|
||||
function tryReduceSelectionToTextNode(selectionNode: Node, selectionOffset: number) {
|
||||
function tryReduceSelectionToTextNode(
|
||||
selectionNode: Node,
|
||||
selectionOffset: number,
|
||||
): {
|
||||
node: Node;
|
||||
characterOffset: number;
|
||||
} {
|
||||
// if selectionNode is an element, the selected location comes after the selectionOffset-th child node,
|
||||
// which can point past any childNode, in which case, the end of selectionNode is selected.
|
||||
// we try to simplify this to point at a text node with the offset being
|
||||
|
@ -87,7 +99,14 @@ function tryReduceSelectionToTextNode(selectionNode: Node, selectionOffset: numb
|
|||
};
|
||||
}
|
||||
|
||||
function getSelectionOffsetAndText(editor: HTMLDivElement, selectionNode: Node, selectionOffset: number) {
|
||||
function getSelectionOffsetAndText(
|
||||
editor: HTMLDivElement,
|
||||
selectionNode: Node,
|
||||
selectionOffset: number,
|
||||
): {
|
||||
offset: DocumentOffset;
|
||||
text: string;
|
||||
} {
|
||||
const { node, characterOffset } = tryReduceSelectionToTextNode(selectionNode, selectionOffset);
|
||||
const { text, offsetToNode } = getTextAndOffsetToNode(editor, node);
|
||||
const offset = getCaret(node, offsetToNode, characterOffset);
|
||||
|
@ -96,7 +115,7 @@ function getSelectionOffsetAndText(editor: HTMLDivElement, selectionNode: Node,
|
|||
|
||||
// gets the caret position details, ignoring and adjusting to
|
||||
// the ZWS if you're typing in a caret node
|
||||
function getCaret(node: Node, offsetToNode: number, offsetWithinNode: number) {
|
||||
function getCaret(node: Node, offsetToNode: number, offsetWithinNode: number): DocumentOffset {
|
||||
// if no node is selected, return an offset at the start
|
||||
if (!node) {
|
||||
return new DocumentOffset(0, false);
|
||||
|
@ -119,12 +138,12 @@ function getCaret(node: Node, offsetToNode: number, offsetWithinNode: number) {
|
|||
// gets the text of the editor as a string,
|
||||
// and the offset in characters where the selectionNode starts in that string
|
||||
// all ZWS from caret nodes are filtered out
|
||||
function getTextAndOffsetToNode(editor: HTMLDivElement, selectionNode: Node) {
|
||||
function getTextAndOffsetToNode(editor: HTMLDivElement, selectionNode: Node): { offsetToNode: number; text: string } {
|
||||
let offsetToNode = 0;
|
||||
let foundNode = false;
|
||||
let text = "";
|
||||
|
||||
function enterNodeCallback(node: HTMLElement) {
|
||||
function enterNodeCallback(node: HTMLElement): boolean {
|
||||
if (!foundNode) {
|
||||
if (node === selectionNode) {
|
||||
foundNode = true;
|
||||
|
@ -150,7 +169,7 @@ function getTextAndOffsetToNode(editor: HTMLDivElement, selectionNode: Node) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function leaveNodeCallback(node: HTMLElement) {
|
||||
function leaveNodeCallback(node: HTMLElement): void {
|
||||
// if this is not the last DIV (which are only used as line containers atm)
|
||||
// we don't just check if there is a nextSibling because sometimes the caret ends up
|
||||
// after the last DIV and it creates a newline if you type then,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue