1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixed context menu not being displayed on high DPI screens

This commit is contained in:
Laurent Cozic 2021-01-07 21:44:31 +00:00
parent f43ec71d9a
commit df3e6a6219
3 changed files with 8 additions and 7 deletions

View File

@ -620,7 +620,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
function pointerInsideEditor(x: number, y: number) {
const elements = document.getElementsByClassName('codeMirrorEditor');
if (!elements.length) return null;
const rect = convertToScreenCoordinates(elements[0].getBoundingClientRect());
const rect = convertToScreenCoordinates(Setting.value('windowContentZoomFactor'), elements[0].getBoundingClientRect());
return rect.x < x && rect.y < y && rect.right > x && rect.bottom > y;
}

View File

@ -7,6 +7,7 @@ import { menuItems, ContextMenuOptions, ContextMenuItemType } from '../../../uti
import MenuUtils from '@joplin/lib/services/commands/MenuUtils';
import CommandService from '@joplin/lib/services/CommandService';
import convertToScreenCoordinates from '../../../../utils/convertToScreenCoordinates';
import Setting from '@joplin/lib/models/Setting';
const Resource = require('@joplin/lib/models/Resource');
@ -21,7 +22,7 @@ function contextMenuElement(editor: any, x: number, y: number) {
const iframes = document.getElementsByClassName('tox-edit-area__iframe');
if (!iframes.length) return null;
const iframeRect = convertToScreenCoordinates(iframes[0].getBoundingClientRect());
const iframeRect = convertToScreenCoordinates(Setting.value('windowContentZoomFactor'), iframes[0].getBoundingClientRect());
if (iframeRect.x < x && iframeRect.y < y && iframeRect.right > x && iframeRect.bottom > y) {
const relativeX = x - iframeRect.x;

View File

@ -1,14 +1,14 @@
// Converts world coordinate to screen coordinates by applying the current
// zoom.
export default function convertToScreenCoordinates(o: any): any {
const pixelRatio = window.devicePixelRatio;
// zoom. `windowContentZoomFactor` is the setting value.
export default function convertToScreenCoordinates(windowContentZoomFactor: number, o: any): any {
const percent = windowContentZoomFactor / 100;
if (typeof o === 'number') return o * pixelRatio;
if (typeof o === 'number') return o * percent;
if (typeof o === 'object' && o !== null) {
o = JSON.parse(JSON.stringify(o));
for (const k of Object.keys(o)) {
o[k] = convertToScreenCoordinates(o[k]);
o[k] = convertToScreenCoordinates(windowContentZoomFactor, o[k]);
}
return o;
}