Skip to content

Commit

Permalink
feat(highlightlistener): Avoid get selection race (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Aug 28, 2020
1 parent a5fcff9 commit 4f3a718
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/highlight/HighlightListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ export default class HighlightListener {
return;
}

this.isMouseSelecting = false;

this.selectionChangeTimer = window.setTimeout(this.setSelection, this.selectionChangeDelay);
this.selectionChangeTimer = window.setTimeout(() => {
this.setSelection();
this.isMouseSelecting = false;
}, this.selectionChangeDelay);
};

handleSelectionChange = (): void => {
Expand Down
5 changes: 3 additions & 2 deletions src/highlight/__tests__/HighlightListener-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('HighlightListener', () => {
});
});

describe('handleMouseDown', () => {
describe('handleMouseDown()', () => {
test('should clear timeout and selection', () => {
highlightListener.selectionChangeTimer = 1;

Expand All @@ -130,11 +130,12 @@ describe('HighlightListener', () => {

highlightListener.handleMouseUp();

expect(highlightListener.isMouseSelecting).toBe(false);
expect(highlightListener.isMouseSelecting).toBe(true);

jest.runAllTimers();

expect(highlightListener.setSelection).toHaveBeenCalled();
expect(highlightListener.isMouseSelecting).toBe(false);
});

test('should do nothing if select not using mouse', () => {
Expand Down

0 comments on commit 4f3a718

Please sign in to comment.