Skip to content

Commit

Permalink
fix(annotations): Fix AnnotationControlsFSM reset when fullscreen ent…
Browse files Browse the repository at this point in the history
…er (#1287)

* fix(annotations): Fix AnnotationControlsFSM reset when fullscreen enter

* fix(annotations): Address comments
  • Loading branch information
Mingze authored Nov 6, 2020
1 parent ede8e42 commit 65763fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ class BaseViewer extends EventEmitter {

if (this.annotator && this.areNewAnnotationsEnabled()) {
this.annotator.emit(ANNOTATOR_EVENT.setVisibility, false);
this.annotator.toggleAnnotationMode(AnnotationMode.NONE);
this.disableAnnotationControls();
}
}
Expand Down Expand Up @@ -919,9 +918,9 @@ class BaseViewer extends EventEmitter {
disableAnnotationControls() {
if (this.annotator && this.annotationControls && this.areNewAnnotationsEnabled()) {
this.annotator.toggleAnnotationMode(AnnotationMode.NONE);
this.annotationControls.resetControls();
this.annotationControls.toggle(false);
}
this.processAnnotationModeChange(this.annotationControlsFSM.transition(AnnotationInput.RESET));
}

enableAnnotationControls() {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ describe('lib/viewers/BaseViewer', () => {
test('should hide annotations and toggle annotations mode', () => {
jest.spyOn(base, 'areNewAnnotationsEnabled').mockReturnValue(true);
jest.spyOn(base, 'disableAnnotationControls');
jest.spyOn(base, 'processAnnotationModeChange');

base.annotator = {
emit: jest.fn(),
Expand All @@ -535,6 +536,7 @@ describe('lib/viewers/BaseViewer', () => {
base.annotationControls = {
destroy: jest.fn(),
resetControls: jest.fn(),
setMode: jest.fn(),
toggle: jest.fn(),
};

Expand All @@ -543,6 +545,7 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.annotator.emit).toBeCalledWith(ANNOTATOR_EVENT.setVisibility, false);
expect(base.annotator.toggleAnnotationMode).toBeCalledWith(AnnotationMode.NONE);
expect(base.disableAnnotationControls).toBeCalled();
expect(base.processAnnotationModeChange).toBeCalledWith(AnnotationMode.NONE);
});
});

Expand Down Expand Up @@ -1042,20 +1045,22 @@ describe('lib/viewers/BaseViewer', () => {
describe('disableAnnotationControls()', () => {
test('should hide annotations and toggle annotations mode', () => {
jest.spyOn(base, 'areNewAnnotationsEnabled').mockReturnValue(true);
jest.spyOn(base, 'processAnnotationModeChange');

base.annotator = {
toggleAnnotationMode: jest.fn(),
};
base.annotationControls = {
destroy: jest.fn(),
resetControls: jest.fn(),
setMode: jest.fn(),
toggle: jest.fn(),
};

base.disableAnnotationControls();

expect(base.annotationControls.resetControls).toBeCalled();
expect(base.annotationControls.toggle).toBeCalledWith(false);
expect(base.processAnnotationModeChange).toBeCalledWith(AnnotationMode.NONE);
});
});

Expand Down
1 change: 0 additions & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,6 @@ class DocBaseViewer extends BaseViewer {

if (this.annotator && this.areNewAnnotationsEnabled() && this.options.enableAnnotationsDiscoverability) {
this.annotator.toggleAnnotationMode(AnnotationMode.REGION);
this.processAnnotationModeChange(this.annotationControlsFSM.transition(AnnotationInput.RESET));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

expect(docBase.annotator.emit).toBeCalledWith(ANNOTATOR_EVENT.setVisibility, true);
expect(docBase.annotator.toggleAnnotationMode).toBeCalledWith(AnnotationMode.REGION);
expect(docBase.processAnnotationModeChange).toBeCalledWith(AnnotationMode.NONE);
expect(docBase.enableAnnotationControls).toBeCalled();
});
});
Expand Down

0 comments on commit 65763fe

Please sign in to comment.