Skip to content

Commit

Permalink
annotation: refocus comments on tab getting focus
Browse files Browse the repository at this point in the history
problem:
if user was editing comment and switched tab/window,
on returning to tab document will gain focus instead of comment
and user accidentally type in doc instead of comment

Signed-off-by: Pranam Lashkari <[email protected]>
Change-Id: I356f311461010fc191620ac489f6b3bc65434e2b
  • Loading branch information
lpranam committed Jan 10, 2025
1 parent c6160f0 commit d22db81
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions browser/src/canvas/sections/CommentListSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {

map: any;
static autoSavedComment: cool.Comment;
static needFocus: cool.Comment;
static commentWasAutoAdded: boolean = false;
static pendingImport: boolean = false;
static importingComments: boolean = false; // active during comments insertion, disable scroll
Expand Down Expand Up @@ -1517,6 +1518,9 @@ export class CommentSection extends app.definitions.canvasSectionObject {
if (autoSavedComment) {
var isOurComment = annotation.isAutoSaved();
if (isOurComment) {
if (app.definitions.CommentSection.needFocus) {
app.definitions.CommentSection.needFocus = annotation;
}
annotation.sectionProperties.container.style.visibility = 'visible';
annotation.sectionProperties.autoSave.innerText = _('Autosaved');
if (this.sectionProperties.docLayer._docType === 'spreadsheet')
Expand Down
8 changes: 6 additions & 2 deletions browser/src/canvas/sections/CommentSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,8 @@ export class Comment extends CanvasSectionObject {
this.removeBRTag(this.sectionProperties.nodeModifyText);
if (this.sectionProperties.contentText.origText !== this.sectionProperties.nodeModifyText.textContent ||
this.sectionProperties.contentText.origHTML !== this.sectionProperties.nodeModifyText.innerHTML) {
if(!document.hasFocus())
app.definitions.CommentSection.needFocus = this;
if (!this.sectionProperties.contentText.uneditedHTML)
this.sectionProperties.contentText.uneditedHTML = this.sectionProperties.contentText.origHTML;
if (!this.sectionProperties.contentText.uneditedText)
Expand All @@ -1117,6 +1119,8 @@ export class Comment extends CanvasSectionObject {
return;
}
if (this.sectionProperties.nodeReplyText.textContent !== '') {
if(!document.hasFocus())
app.definitions.CommentSection.needFocus = this;
if (!this.sectionProperties.contentText.uneditedHTML)
this.sectionProperties.contentText.uneditedHTML = this.sectionProperties.contentText.origHTML;
if (!this.sectionProperties.contentText.uneditedText)
Expand All @@ -1131,8 +1135,8 @@ export class Comment extends CanvasSectionObject {

public focus (): void {
this.sectionProperties.container.classList.add('annotation-active');
this.sectionProperties.nodeModifyText.focus();
this.sectionProperties.nodeReplyText.focus();
this.sectionProperties.nodeModifyText.focus({ focusVisible: true });
this.sectionProperties.nodeReplyText.focus({ focusVisible: true });

// set cursor at the last position on refocus after autosave
if (this.isModifying() && this.sectionProperties.nodeModifyText.childNodes.length > 0) {
Expand Down
7 changes: 7 additions & 0 deletions browser/src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,13 @@ L.Map = L.Evented.extend({
}

app.idleHandler._activate();

if (app.definitions.CommentSection.needFocus)
{
app.definitions.CommentSection.needFocus.focus();
app.sectionContainer.getSectionWithName(L.CSections.CommentList.name).select(app.needFocus)
app.definitions.CommentSection.needFocus = null;
}
},

// Event to change the focus to dialog or editor.
Expand Down

0 comments on commit d22db81

Please sign in to comment.