mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
Desktop: Fixes #4201: Fixed context menu when the UI is zoomed in or out
This commit is contained in:
parent
17edebb6b1
commit
a9af58146b
@ -718,6 +718,9 @@ packages/app-desktop/gui/style/StyledTextInput.js.map
|
||||
packages/app-desktop/gui/utils/NoteListUtils.d.ts
|
||||
packages/app-desktop/gui/utils/NoteListUtils.js
|
||||
packages/app-desktop/gui/utils/NoteListUtils.js.map
|
||||
packages/app-desktop/gui/utils/convertToScreenCoordinates.d.ts
|
||||
packages/app-desktop/gui/utils/convertToScreenCoordinates.js
|
||||
packages/app-desktop/gui/utils/convertToScreenCoordinates.js.map
|
||||
packages/app-desktop/plugins/GotoAnything.d.ts
|
||||
packages/app-desktop/plugins/GotoAnything.js
|
||||
packages/app-desktop/plugins/GotoAnything.js.map
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -707,6 +707,9 @@ packages/app-desktop/gui/style/StyledTextInput.js.map
|
||||
packages/app-desktop/gui/utils/NoteListUtils.d.ts
|
||||
packages/app-desktop/gui/utils/NoteListUtils.js
|
||||
packages/app-desktop/gui/utils/NoteListUtils.js.map
|
||||
packages/app-desktop/gui/utils/convertToScreenCoordinates.d.ts
|
||||
packages/app-desktop/gui/utils/convertToScreenCoordinates.js
|
||||
packages/app-desktop/gui/utils/convertToScreenCoordinates.js.map
|
||||
packages/app-desktop/plugins/GotoAnything.d.ts
|
||||
packages/app-desktop/plugins/GotoAnything.js
|
||||
packages/app-desktop/plugins/GotoAnything.js.map
|
||||
|
@ -24,6 +24,7 @@ import { themeStyle } from '@joplin/lib/theme';
|
||||
import { ThemeAppearance } from '@joplin/lib/themes/type';
|
||||
import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService';
|
||||
import dialogs from '../../../dialogs';
|
||||
import convertToScreenCoordinates from '../../../utils/convertToScreenCoordinates';
|
||||
|
||||
const Note = require('@joplin/lib/models/Note.js');
|
||||
const { clipboard } = require('electron');
|
||||
@ -613,7 +614,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 = elements[0].getBoundingClientRect();
|
||||
const rect = convertToScreenCoordinates(elements[0].getBoundingClientRect());
|
||||
return rect.x < x && rect.y < y && rect.right > x && rect.bottom > y;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import bridge from '../../../../../services/bridge';
|
||||
import { menuItems, ContextMenuOptions, ContextMenuItemType } from '../../../utils/contextMenu';
|
||||
import MenuUtils from '@joplin/lib/services/commands/MenuUtils';
|
||||
import CommandService from '@joplin/lib/services/CommandService';
|
||||
import convertToScreenCoordinates from '../../../../utils/convertToScreenCoordinates';
|
||||
|
||||
const Resource = require('@joplin/lib/models/Resource');
|
||||
|
||||
@ -20,7 +21,7 @@ function contextMenuElement(editor: any, x: number, y: number) {
|
||||
const iframes = document.getElementsByClassName('tox-edit-area__iframe');
|
||||
if (!iframes.length) return null;
|
||||
|
||||
const iframeRect = iframes[0].getBoundingClientRect();
|
||||
const iframeRect = convertToScreenCoordinates(iframes[0].getBoundingClientRect());
|
||||
|
||||
if (iframeRect.x < x && iframeRect.y < y && iframeRect.right > x && iframeRect.bottom > y) {
|
||||
const relativeX = x - iframeRect.x;
|
||||
|
18
packages/app-desktop/gui/utils/convertToScreenCoordinates.ts
Normal file
18
packages/app-desktop/gui/utils/convertToScreenCoordinates.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// Converts world coordinate to screen coordinates by applying the current
|
||||
// zoom.
|
||||
export default function convertToScreenCoordinates(o: any): any {
|
||||
const pixelRatio = window.devicePixelRatio;
|
||||
|
||||
if (typeof o === 'number') return o * pixelRatio;
|
||||
|
||||
if (typeof o === 'object' && o !== null) {
|
||||
o = JSON.parse(JSON.stringify(o));
|
||||
console.info('K', Object.keys(o));
|
||||
for (const k of Object.keys(o)) {
|
||||
o[k] = convertToScreenCoordinates(o[k]);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
throw new Error(`Cannot convert to screen coordinates: ${typeof o}`);
|
||||
}
|
Loading…
Reference in New Issue
Block a user