Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed selection by long-press on Safari #612

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
}