Conform more of the codebase to strictNullChecks
(#10573)
* Conform more of the codebase to `strictNullChecks` * Iterate
This commit is contained in:
parent
b4d7f6b592
commit
605ef084ec
34 changed files with 119 additions and 104 deletions
|
@ -28,7 +28,7 @@ export interface ICallback {
|
|||
}
|
||||
|
||||
export type UpdateCallback = (data: ICallback) => void;
|
||||
export type GetAutocompleterComponent = () => Autocomplete;
|
||||
export type GetAutocompleterComponent = () => Autocomplete | null;
|
||||
export type UpdateQuery = (test: string) => Promise<void>;
|
||||
|
||||
export default class AutocompleteWrapperModel {
|
||||
|
@ -42,7 +42,7 @@ export default class AutocompleteWrapperModel {
|
|||
) {}
|
||||
|
||||
public onEscape(e: KeyboardEvent): void {
|
||||
this.getAutocompleterComponent().onEscape(e);
|
||||
this.getAutocompleterComponent()?.onEscape(e);
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
|
@ -50,16 +50,16 @@ export default class AutocompleteWrapperModel {
|
|||
}
|
||||
|
||||
public hasSelection(): boolean {
|
||||
return this.getAutocompleterComponent().hasSelection();
|
||||
return !!this.getAutocompleterComponent()?.hasSelection();
|
||||
}
|
||||
|
||||
public hasCompletions(): boolean {
|
||||
const ac = this.getAutocompleterComponent();
|
||||
return ac && ac.countCompletions() > 0;
|
||||
return !!ac && ac.countCompletions() > 0;
|
||||
}
|
||||
|
||||
public confirmCompletion(): void {
|
||||
this.getAutocompleterComponent().onConfirmCompletion();
|
||||
this.getAutocompleterComponent()?.onConfirmCompletion();
|
||||
this.updateCallback({ close: true });
|
||||
}
|
||||
|
||||
|
@ -68,18 +68,18 @@ export default class AutocompleteWrapperModel {
|
|||
*/
|
||||
public async startSelection(): Promise<void> {
|
||||
const acComponent = this.getAutocompleterComponent();
|
||||
if (acComponent.countCompletions() === 0) {
|
||||
if (acComponent && acComponent.countCompletions() === 0) {
|
||||
// Force completions to show for the text currently entered
|
||||
await acComponent.forceComplete();
|
||||
}
|
||||
}
|
||||
|
||||
public selectPreviousSelection(): void {
|
||||
this.getAutocompleterComponent().moveSelection(-1);
|
||||
this.getAutocompleterComponent()?.moveSelection(-1);
|
||||
}
|
||||
|
||||
public selectNextSelection(): void {
|
||||
this.getAutocompleterComponent().moveSelection(+1);
|
||||
this.getAutocompleterComponent()?.moveSelection(+1);
|
||||
}
|
||||
|
||||
public onPartUpdate(part: Part, pos: DocumentPosition): Promise<void> {
|
||||
|
|
|
@ -44,7 +44,7 @@ import { Caret } from "./caret";
|
|||
* @return the caret position
|
||||
*/
|
||||
|
||||
type TransformCallback = (caretPosition: DocumentPosition, inputType: string, diff: IDiff) => number | void;
|
||||
type TransformCallback = (caretPosition: DocumentPosition, inputType: string | undefined, diff: IDiff) => number | void;
|
||||
type UpdateCallback = (caret?: Caret, inputType?: string, diff?: IDiff) => void;
|
||||
type ManualTransformCallback = () => Caret;
|
||||
|
||||
|
@ -151,7 +151,7 @@ export default class EditorModel {
|
|||
return this._parts.map((p) => p.serialize());
|
||||
}
|
||||
|
||||
private diff(newValue: string, inputType: string, caret: DocumentOffset): IDiff {
|
||||
private diff(newValue: string, inputType: string | undefined, caret: DocumentOffset): IDiff {
|
||||
const previousValue = this.parts.reduce((text, p) => text + p.text, "");
|
||||
// can't use caret position with drag and drop
|
||||
if (inputType === "deleteByDrag") {
|
||||
|
@ -196,7 +196,7 @@ export default class EditorModel {
|
|||
return newTextLength;
|
||||
}
|
||||
|
||||
public update(newValue: string, inputType: string, caret: DocumentOffset): Promise<void> {
|
||||
public update(newValue: string, inputType: string | undefined, caret: DocumentOffset): Promise<void> {
|
||||
const diff = this.diff(newValue, inputType, caret);
|
||||
const position = this.positionForOffset(diff.at || 0, caret.atNodeEnd);
|
||||
let removedOffsetDecrease = 0;
|
||||
|
@ -220,7 +220,7 @@ export default class EditorModel {
|
|||
return acPromise;
|
||||
}
|
||||
|
||||
private getTransformAddedLen(newPosition: DocumentPosition, inputType: string, diff: IDiff): number {
|
||||
private getTransformAddedLen(newPosition: DocumentPosition, inputType: string | undefined, diff: IDiff): number {
|
||||
const result = this.transformCallback?.(newPosition, inputType, diff);
|
||||
return Number.isFinite(result) ? (result as number) : 0;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ export default class EditorModel {
|
|||
* @return {Number} how far from position (in characters) the insertion ended.
|
||||
* This can be more than the length of `str` when crossing non-editable parts, which are skipped.
|
||||
*/
|
||||
private addText(pos: IPosition, str: string, inputType: string): number {
|
||||
private addText(pos: IPosition, str: string, inputType: string | undefined): number {
|
||||
let { index } = pos;
|
||||
const { offset } = pos;
|
||||
let addLen = str.length;
|
||||
|
|
|
@ -65,8 +65,8 @@ interface IBasePart {
|
|||
serialize(): SerializedPart;
|
||||
remove(offset: number, len: number): string | undefined;
|
||||
split(offset: number): IBasePart;
|
||||
validateAndInsert(offset: number, str: string, inputType: string): boolean;
|
||||
appendUntilRejected(str: string, inputType: string): string | undefined;
|
||||
validateAndInsert(offset: number, str: string, inputType: string | undefined): boolean;
|
||||
appendUntilRejected(str: string, inputType: string | undefined): string | undefined;
|
||||
updateDOMNode(node: Node): void;
|
||||
canUpdateDOMNode(node: Node): boolean;
|
||||
toDOMNode(): Node;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue