fix: Fix undefined showing up in markdown (#970)

This commit is contained in:
SleeplessOne1917 2023-03-26 22:10:08 -04:00 committed by GitHub
parent 47daa9d143
commit 1ad36d2c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -416,18 +416,18 @@ export class MarkdownTextArea extends Component<
handleInsertLink(i: MarkdownTextArea, event: any) { handleInsertLink(i: MarkdownTextArea, event: any) {
event.preventDefault(); event.preventDefault();
let textarea: any = document.getElementById(i.id); const textarea: any = document.getElementById(i.id);
let start: number = textarea.selectionStart; const start: number = textarea.selectionStart;
let end: number = textarea.selectionEnd; const end: number = textarea.selectionEnd;
let content = i.state.content; const content = i.state.content ?? "";
if (!i.state.content) { if (!i.state.content) {
i.setState({ content: "" }); i.setState({ content: "" });
} }
if (start !== end) { if (start !== end) {
let selectedText = content?.substring(start, end); const selectedText = content?.substring(start, end);
i.setState({ i.setState({
content: `${content?.substring( content: `${content?.substring(
0, 0,
@ -457,16 +457,16 @@ export class MarkdownTextArea extends Component<
afterChars: string, afterChars: string,
emptyChars = "___" emptyChars = "___"
) { ) {
let content = this.state.content; const content = this.state.content ?? "";
if (!this.state.content) { if (!this.state.content) {
this.setState({ content: "" }); this.setState({ content: "" });
} }
let textarea: any = document.getElementById(this.id); const textarea: any = document.getElementById(this.id);
let start: number = textarea.selectionStart; const start: number = textarea.selectionStart;
let end: number = textarea.selectionEnd; const end: number = textarea.selectionEnd;
if (start !== end) { if (start !== end) {
let selectedText = content?.substring(start, end); const selectedText = content?.substring(start, end);
this.setState({ this.setState({
content: `${content?.substring( content: `${content?.substring(
0, 0,