Conform more of the codebase to strictNullChecks (#10573)

* Conform more of the codebase to `strictNullChecks`

* Iterate
This commit is contained in:
Michael Telatynski 2023-04-13 08:52:57 +01:00 committed by GitHub
parent b4d7f6b592
commit 605ef084ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 119 additions and 104 deletions

View file

@ -231,6 +231,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
}
private updateEditorState = (selection: Caret, inputType?: string, diff?: IDiff): void => {
if (!this.editorRef.current) return;
renderModel(this.editorRef.current, this.props.model);
if (selection) {
// set the caret/selection
@ -358,6 +359,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
private onPaste = (event: ClipboardEvent<HTMLDivElement>): boolean | undefined => {
event.preventDefault(); // we always handle the paste ourselves
if (!this.editorRef.current) return;
if (this.props.onPaste?.(event, this.props.model)) {
// to prevent double handling, allow props.onPaste to skip internal onPaste
return true;
@ -377,7 +379,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
}
this.modifiedFlag = true;
const range = getRangeForSelection(this.editorRef.current, model, document.getSelection());
const range = getRangeForSelection(this.editorRef.current, model, document.getSelection()!);
// If the user is pasting a link, and has a range selected which is not a link, wrap the range with the link
if (plainText && range.length > 0 && linkify.test(plainText) && !linkify.test(range.text)) {
@ -388,18 +390,20 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
};
private onInput = (event: Partial<InputEvent>): void => {
if (!this.editorRef.current) return;
// ignore any input while doing IME compositions
if (this.isIMEComposing) {
return;
}
this.modifiedFlag = true;
const sel = document.getSelection();
const sel = document.getSelection()!;
const { caret, text } = getCaretOffsetAndText(this.editorRef.current, sel);
this.props.model.update(text, event.inputType, caret);
};
private insertText(textToInsert: string, inputType = "insertText"): void {
const sel = document.getSelection();
if (!this.editorRef.current) return;
const sel = document.getSelection()!;
const { caret, text } = getCaretOffsetAndText(this.editorRef.current, sel);
const newText = text.slice(0, caret.offset) + textToInsert + text.slice(caret.offset);
caret.offset += textToInsert.length;
@ -468,6 +472,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
};
private onSelectionChange = (): void => {
if (!this.editorRef.current) return;
const { isEmpty } = this.props.model;
this.refreshLastCaretIfNeeded();
@ -486,6 +491,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
};
private onKeyDown = (event: React.KeyboardEvent): void => {
if (!this.editorRef.current) return;
const model = this.props.model;
let handled = false;
@ -497,7 +503,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
const selectionRange = getRangeForSelection(
this.editorRef.current,
this.props.model,
document.getSelection(),
document.getSelection()!,
);
// trim the range as we want it to exclude leading/trailing spaces
selectionRange.trim();
@ -745,11 +751,11 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
}
public onFormatAction = (action: Formatting): void => {
if (!this.state.useMarkdown) {
if (!this.state.useMarkdown || !this.editorRef.current) {
return;
}
const range: Range = getRangeForSelection(this.editorRef.current, this.props.model, document.getSelection());
const range: Range = getRangeForSelection(this.editorRef.current, this.props.model, document.getSelection()!);
this.historyManager.ensureLastChangesPushed(this.props.model);
this.modifiedFlag = true;