Skip to content

Commit

Permalink
Fix image uploads not working (#1005)
Browse files Browse the repository at this point in the history
Fix image uploads not working

There is a bug where the program references undefined when an 
image/video is uploaded. This is caused by the use of the `this` 
keyword in the function `replacePlaceholderString`, which is not a 
method of any class.

Let's remove the `this` keyword in `replacePlaceholderString`.
  • Loading branch information
cheehongw authored Oct 2, 2022
1 parent c54fae4 commit 298b750
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/app/shared/comment-editor/upload-text-insertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ function replacePlaceholderString(
commentField: AbstractControl,
commentTextArea: ElementRef<HTMLTextAreaElement>
) {
const cursorPosition = this.commentTextArea.nativeElement.selectionEnd;
const cursorPosition = commentTextArea.nativeElement.selectionEnd;
const insertingString = `[Uploading ${filename}...]`;
const startIndexOfString = this.commentField.value.indexOf(insertingString);
const startIndexOfString = commentField.value.indexOf(insertingString);
const endIndexOfString = startIndexOfString + insertingString.length;
const endOfInsertedString = startIndexOfString + insertedString.length;
const differenceInLength = endOfInsertedString - endIndexOfString;
Expand All @@ -78,6 +78,6 @@ function replacePlaceholderString(
? cursorPosition
: cursorPosition + differenceInLength; // after the uploading text

commentField.setValue(this.commentField.value.replace(insertingString, insertedString));
commentField.setValue(commentField.value.replace(insertingString, insertedString));
commentTextArea.nativeElement.setSelectionRange(newCursorPosition, newCursorPosition);
}

0 comments on commit 298b750

Please sign in to comment.