1
0
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:
Laurent Cozic 2020-12-23 23:17:12 +00:00
parent 17edebb6b1
commit a9af58146b
5 changed files with 28 additions and 2 deletions

View File

@ -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.d.ts
packages/app-desktop/gui/utils/NoteListUtils.js packages/app-desktop/gui/utils/NoteListUtils.js
packages/app-desktop/gui/utils/NoteListUtils.js.map 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.d.ts
packages/app-desktop/plugins/GotoAnything.js packages/app-desktop/plugins/GotoAnything.js
packages/app-desktop/plugins/GotoAnything.js.map packages/app-desktop/plugins/GotoAnything.js.map

3
.gitignore vendored
View File

@ -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.d.ts
packages/app-desktop/gui/utils/NoteListUtils.js packages/app-desktop/gui/utils/NoteListUtils.js
packages/app-desktop/gui/utils/NoteListUtils.js.map 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.d.ts
packages/app-desktop/plugins/GotoAnything.js packages/app-desktop/plugins/GotoAnything.js
packages/app-desktop/plugins/GotoAnything.js.map packages/app-desktop/plugins/GotoAnything.js.map

View File

@ -24,6 +24,7 @@ import { themeStyle } from '@joplin/lib/theme';
import { ThemeAppearance } from '@joplin/lib/themes/type'; import { ThemeAppearance } from '@joplin/lib/themes/type';
import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService'; import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService';
import dialogs from '../../../dialogs'; import dialogs from '../../../dialogs';
import convertToScreenCoordinates from '../../../utils/convertToScreenCoordinates';
const Note = require('@joplin/lib/models/Note.js'); const Note = require('@joplin/lib/models/Note.js');
const { clipboard } = require('electron'); const { clipboard } = require('electron');
@ -613,7 +614,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
function pointerInsideEditor(x: number, y: number) { function pointerInsideEditor(x: number, y: number) {
const elements = document.getElementsByClassName('codeMirrorEditor'); const elements = document.getElementsByClassName('codeMirrorEditor');
if (!elements.length) return null; 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; return rect.x < x && rect.y < y && rect.right > x && rect.bottom > y;
} }

View File

@ -6,6 +6,7 @@ import bridge from '../../../../../services/bridge';
import { menuItems, ContextMenuOptions, ContextMenuItemType } from '../../../utils/contextMenu'; import { menuItems, ContextMenuOptions, ContextMenuItemType } from '../../../utils/contextMenu';
import MenuUtils from '@joplin/lib/services/commands/MenuUtils'; import MenuUtils from '@joplin/lib/services/commands/MenuUtils';
import CommandService from '@joplin/lib/services/CommandService'; import CommandService from '@joplin/lib/services/CommandService';
import convertToScreenCoordinates from '../../../../utils/convertToScreenCoordinates';
const Resource = require('@joplin/lib/models/Resource'); 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'); const iframes = document.getElementsByClassName('tox-edit-area__iframe');
if (!iframes.length) return null; 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) { if (iframeRect.x < x && iframeRect.y < y && iframeRect.right > x && iframeRect.bottom > y) {
const relativeX = x - iframeRect.x; const relativeX = x - iframeRect.x;

View 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}`);
}