Skip to content

Commit

Permalink
Fixed selection by long-press on Safari
Browse files Browse the repository at this point in the history
Fixes #609
  • Loading branch information
timocov committed Nov 12, 2020
1 parent 8664655 commit 9bbc186
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/gui/canvas-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ export function getContext2D(canvas: HTMLCanvasElement): CanvasRenderingContext2
return ctx;
}

function createCanvas(doc: Document): HTMLCanvasElement {
const canvas = doc.createElement('canvas');
disableSelection(canvas);
return canvas;
}

export function createPreconfiguredCanvas(doc: Document, size: Size): HTMLCanvasElement {
const canvas = createCanvas(doc);
const canvas = doc.createElement('canvas');

const pixelRatio = getCanvasDevicePixelRatio(canvas);
// we should keep the layout size...
Expand All @@ -54,7 +48,7 @@ export function createPreconfiguredCanvas(doc: Document, size: Size): HTMLCanvas

export function createBoundCanvas(parentElement: HTMLElement, size: Size): CanvasCoordinateSpaceBinding {
const doc = ensureNotNull(parentElement.ownerDocument);
const canvas = createCanvas(doc);
const canvas = doc.createElement('canvas');
parentElement.appendChild(canvas);

const binding = bindToDevicePixelRatio(canvas);
Expand All @@ -65,18 +59,6 @@ export function createBoundCanvas(parentElement: HTMLElement, size: Size): Canva
return binding;
}

function disableSelection(canvas: HTMLCanvasElement): void {
canvas.style.userSelect = 'none';
// eslint-disable-next-line deprecation/deprecation
canvas.style.webkitUserSelect = 'none';
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
(canvas as any).style.msUserSelect = 'none';
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
(canvas as any).style.MozUserSelect = 'none';

canvas.style.webkitTapHighlightColor = 'transparent';
}

export function drawScaled(ctx: CanvasRenderingContext2D, ratio: number, func: () => void): void {
ctx.save();
ctx.scale(ratio, ratio);
Expand Down
13 changes: 13 additions & 0 deletions src/gui/chart-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class ChartWidget implements IDestroyable {
this._element.style.overflow = 'hidden';
this._element.style.width = '100%';
this._element.style.height = '100%';
disableSelection(this._element);

this._tableElement = document.createElement('table');
this._tableElement.setAttribute('cellspacing', '0');
Expand Down Expand Up @@ -633,3 +634,15 @@ export class ChartWidget implements IDestroyable {
return this._options.rightPriceScale.visible;
}
}

function disableSelection(element: HTMLElement): void {
element.style.userSelect = 'none';
// eslint-disable-next-line deprecation/deprecation
element.style.webkitUserSelect = 'none';
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
(element as any).style.msUserSelect = 'none';
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
(element as any).style.MozUserSelect = 'none';

element.style.webkitTapHighlightColor = 'transparent';
}

0 comments on commit 9bbc186

Please sign in to comment.