Skip to content

Commit 56ec56c

Browse files
committed
annotation: refocus comments on tab getting focus
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
1 parent c3e323a commit 56ec56c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

browser/src/canvas/sections/CommentListSection.ts

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
8787

8888
map: any;
8989
static autoSavedComment: cool.Comment;
90+
static needFocus: cool.Comment;
9091
static commentWasAutoAdded: boolean = false;
9192
static pendingImport: boolean = false;
9293
static importingComments: boolean = false; // active during comments insertion, disable scroll
@@ -1525,6 +1526,9 @@ export class CommentSection extends app.definitions.canvasSectionObject {
15251526
if (autoSavedComment) {
15261527
var isOurComment = annotation.isAutoSaved();
15271528
if (isOurComment) {
1529+
if (app.definitions.CommentSection.needFocus) {
1530+
app.definitions.CommentSection.needFocus = annotation;
1531+
}
15281532
annotation.sectionProperties.container.style.visibility = 'visible';
15291533
annotation.sectionProperties.autoSave.innerText = _('Autosaved');
15301534
if (this.sectionProperties.docLayer._docType === 'spreadsheet')

browser/src/canvas/sections/CommentSection.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,8 @@ export class Comment extends CanvasSectionObject {
11171117
this.removeLastBRTag(this.sectionProperties.nodeModifyText);
11181118
if (this.sectionProperties.contentText.origText !== this.sectionProperties.nodeModifyText.innerText ||
11191119
this.sectionProperties.contentText.origHTML !== this.sectionProperties.nodeModifyText.innerHTML) {
1120+
if(!document.hasFocus())
1121+
app.definitions.CommentSection.needFocus = this;
11201122
if (!this.sectionProperties.contentText.uneditedHTML)
11211123
this.sectionProperties.contentText.uneditedHTML = this.sectionProperties.contentText.origHTML;
11221124
if (!this.sectionProperties.contentText.uneditedText)
@@ -1141,6 +1143,8 @@ export class Comment extends CanvasSectionObject {
11411143
return;
11421144
}
11431145
if (this.sectionProperties.nodeReplyText.innerText !== '') {
1146+
if(!document.hasFocus())
1147+
app.definitions.CommentSection.needFocus = this;
11441148
if (!this.sectionProperties.contentText.uneditedHTML)
11451149
this.sectionProperties.contentText.uneditedHTML = this.sectionProperties.contentText.origHTML;
11461150
if (!this.sectionProperties.contentText.uneditedText)
@@ -1157,8 +1161,8 @@ export class Comment extends CanvasSectionObject {
11571161

11581162
public focus (): void {
11591163
this.sectionProperties.container.classList.add('annotation-active');
1160-
this.sectionProperties.nodeModifyText.focus();
1161-
this.sectionProperties.nodeReplyText.focus();
1164+
this.sectionProperties.nodeModifyText.focus({ focusVisible: true });
1165+
this.sectionProperties.nodeReplyText.focus({ focusVisible: true });
11621166

11631167
// set cursor at the last position on refocus after autosave
11641168
if (this.isModifying() && this.sectionProperties.nodeModifyText.childNodes.length > 0) {

browser/src/map/Map.js

+7
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,13 @@ L.Map = L.Evented.extend({
14421442
}
14431443

14441444
app.idleHandler._activate();
1445+
1446+
if (app.definitions.CommentSection.needFocus)
1447+
{
1448+
app.definitions.CommentSection.needFocus.focus();
1449+
app.sectionContainer.getSectionWithName(L.CSections.CommentList.name).select(app.needFocus)
1450+
app.definitions.CommentSection.needFocus = null;
1451+
}
14451452
},
14461453

14471454
// Event to change the focus to dialog or editor.

0 commit comments

Comments
 (0)