Skip to content

Commit

Permalink
fix: Fixes text selection in contenteditable
Browse files Browse the repository at this point in the history
  • Loading branch information
james-complish committed Mar 15, 2021
1 parent 955e403 commit 92caee7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export * from './types';
// Some var shorting for better compression and readability
const {abs, max, min, ceil} = Math;

// Likely want to move this to utils
// Determines if the device's primary input supports touch
// See this article: https://css-tricks.com/touch-devices-not-judged-size/
const isTouchEnabled = window.matchMedia('(hover: none), (pointer: coarse)').matches;

export default class SelectionArea extends EventTarget<SelectionEvents> {
public static version = VERSION;

Expand Down Expand Up @@ -232,7 +237,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
}

_delayedTapMove(evt: MouseEvent | TouchEvent): void {
const {startThreshold, container, document} = this._options;
const {startThreshold, container, document, allowTouch} = this._options;
const {x1, y1} = this._areaLocation; // Coordinates of first "tap"
const {x, y} = simplifyEvent(evt);

Expand Down Expand Up @@ -289,7 +294,9 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
this._onTapMove(evt);
}

evt.preventDefault(); // Prevent swipe-down refresh
if (allowTouch && isTouchEnabled) {
evt.preventDefault(); // Prevent swipe-down refresh
}
}

_prepareSelectionArea(): void {
Expand Down Expand Up @@ -341,6 +348,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
_onTapMove(evt: MouseEvent | TouchEvent): void {
const {x, y} = simplifyEvent(evt);
const {_scrollSpeed, _areaLocation, _options} = this;
const {allowTouch} = _options;
const {speedDivider} = _options.scrolling;
const scon = this._targetElement as Element;

Expand Down Expand Up @@ -399,7 +407,9 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
this._redrawSelectionArea();
}

evt.preventDefault(); // Prevent swipe-down refresh
if (allowTouch && isTouchEnabled) {
evt.preventDefault(); // Prevent swipe-down refresh
}
}

_onScroll(): void {
Expand Down

0 comments on commit 92caee7

Please sign in to comment.