From cfba73e9380925703c4d73aeb9a5ef052f3b8249 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Mon, 5 Sep 2022 04:47:25 -0700 Subject: [PATCH] Android: Fixes #6802: Double/triple-tap selection doesn't show context menu (#6803) --- .../NoteEditor/CodeMirror/CodeMirror.ts | 21 +++++++++++++++++++ .../NoteEditor/CodeMirror/demo.html | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/app-mobile/components/NoteEditor/CodeMirror/CodeMirror.ts b/packages/app-mobile/components/NoteEditor/CodeMirror/CodeMirror.ts index 4b78f0ef8c..2bdbdabecc 100644 --- a/packages/app-mobile/components/NoteEditor/CodeMirror/CodeMirror.ts +++ b/packages/app-mobile/components/NoteEditor/CodeMirror/CodeMirror.ts @@ -342,6 +342,27 @@ export function initCodeMirror( parent: parentElement, }); + // HACK: 09/02/22: Work around https://github.com/laurent22/joplin/issues/6802 by creating a copy mousedown + // event to prevent the Editor's .preventDefault from making the context menu not appear. + // TODO: Track the upstream issue at https://github.com/codemirror/dev/issues/935 and remove this workaround + // when the upstream bug is fixed. + document.body.addEventListener('mousedown', (evt) => { + if (!evt.isTrusted) { + return; + } + + // Walk up the tree -- is evt.target or any of its parent nodes the editor's input region? + for (let current: Record = evt.target; current; current = current.parentElement) { + if (current === editor.contentDOM) { + evt.stopPropagation(); + + const copyEvent = new Event('mousedown', evt); + editor.contentDOM.dispatchEvent(copyEvent); + return; + } + } + }, true); + const updateSearchQuery = (newState: SearchState) => { const query = new SearchQuery({ search: newState.searchText, diff --git a/packages/app-mobile/components/NoteEditor/CodeMirror/demo.html b/packages/app-mobile/components/NoteEditor/CodeMirror/demo.html index bee0ddb9b3..8008515f86 100644 --- a/packages/app-mobile/components/NoteEditor/CodeMirror/demo.html +++ b/packages/app-mobile/components/NoteEditor/CodeMirror/demo.html @@ -42,7 +42,7 @@ }, }; - codeMirrorBundle.initCodeMirror(parent, initialText, settings); + window.cm = codeMirrorBundle.initCodeMirror(parent, initialText, settings); \ No newline at end of file