Skip to content

Commit

Permalink
js: fix: comment doesn't presists newlines
Browse files Browse the repository at this point in the history
- happens on firefox when you make the comment autosave and then finally
save the comment

Signed-off-by: Rashesh <[email protected]>
Change-Id: Ida59e546577a2c55197568225a1277340ef94367
  • Loading branch information
Rash419 committed Jan 11, 2025
1 parent 47e45cd commit a94f2a8
Showing 1 changed file with 0 additions and 12 deletions.
12 changes: 0 additions & 12 deletions browser/src/canvas/sections/CommentSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ export class Comment extends CanvasSectionObject {
this.sectionProperties.data.reply = this.sectionProperties.data.text;
this.sectionProperties.commentListSection.saveReply(this);
} else {
this.removeBRTag(this.sectionProperties.nodeReplyText);
this.sectionProperties.data.reply = this.sectionProperties.nodeReplyText.innerText;
this.sectionProperties.data.html = this.sectionProperties.nodeReplyText.innerHTML;
// Assigning an empty string to .innerHTML property in some browsers will convert it to 'null'
Expand Down Expand Up @@ -1065,7 +1064,6 @@ export class Comment extends CanvasSectionObject {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public onSaveComment (e: any): void {
L.DomEvent.stopPropagation(e);
this.removeBRTag(this.sectionProperties.nodeModifyText);
this.sectionProperties.data.text = this.sectionProperties.nodeModifyText.innerText;
this.sectionProperties.data.html = this.sectionProperties.nodeModifyText.innerHTML;
this.updateContent();
Expand All @@ -1074,23 +1072,13 @@ export class Comment extends CanvasSectionObject {
this.sectionProperties.commentListSection.save(this);
}

// for some reason firefox adds <br> at of the end of text in contenteditable div
// there have been similar reports: https://bugzilla.mozilla.org/show_bug.cgi?id=1615852
private removeBRTag(element: HTMLElement) {
if (!L.Browser.gecko)
return;
const brElements = element.querySelectorAll('br');
brElements.forEach(br => br.remove());
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public onLostFocus (e: any): void {
if (this.sectionProperties.docLayer._docType === 'text' && this.map.mention?.isTypingMention()) {
return;
}
if (!this.sectionProperties.isRemoved) {
$(this.sectionProperties.container).removeClass('annotation-active reply-annotation-container modify-annotation-container');
this.removeBRTag(this.sectionProperties.nodeModifyText);
if (this.sectionProperties.contentText.origText !== this.sectionProperties.nodeModifyText.innerText ||
this.sectionProperties.contentText.origHTML !== this.sectionProperties.nodeModifyText.innerHTML) {
if (!this.sectionProperties.contentText.uneditedHTML)
Expand Down

0 comments on commit a94f2a8

Please sign in to comment.