From: SleeplessOne1917 Date: Mon, 27 Mar 2023 02:10:08 +0000 (-0400) Subject: fix: Fix undefined showing up in markdown (#970) X-Git-Url: http://these/git/README.es.md?a=commitdiff_plain;h=1ad36d2c1d28d9131245be20b48957fd47016a34;p=lemmy-ui.git fix: Fix undefined showing up in markdown (#970) --- diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index b2eabe2..001779e 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -416,18 +416,18 @@ export class MarkdownTextArea extends Component< handleInsertLink(i: MarkdownTextArea, event: any) { event.preventDefault(); - let textarea: any = document.getElementById(i.id); - let start: number = textarea.selectionStart; - let end: number = textarea.selectionEnd; + const textarea: any = document.getElementById(i.id); + const start: number = textarea.selectionStart; + const end: number = textarea.selectionEnd; - let content = i.state.content; + const content = i.state.content ?? ""; if (!i.state.content) { i.setState({ content: "" }); } if (start !== end) { - let selectedText = content?.substring(start, end); + const selectedText = content?.substring(start, end); i.setState({ content: `${content?.substring( 0, @@ -457,16 +457,16 @@ export class MarkdownTextArea extends Component< afterChars: string, emptyChars = "___" ) { - let content = this.state.content; + const content = this.state.content ?? ""; if (!this.state.content) { this.setState({ content: "" }); } - let textarea: any = document.getElementById(this.id); - let start: number = textarea.selectionStart; - let end: number = textarea.selectionEnd; + const textarea: any = document.getElementById(this.id); + const start: number = textarea.selectionStart; + const end: number = textarea.selectionEnd; if (start !== end) { - let selectedText = content?.substring(start, end); + const selectedText = content?.substring(start, end); this.setState({ content: `${content?.substring( 0,