From 7a8c69a6f9722c32e624d64a3cb8f78e9b0203b2 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 23 Nov 2022 22:47:20 +0100 Subject: [PATCH] fix jumping cursor position after closing a dialog, fixes #3325 --- src/public/app/services/utils.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js index 8cab5ec5b..21f79ceb7 100644 --- a/src/public/app/services/utils.js +++ b/src/public/app/services/utils.js @@ -230,7 +230,19 @@ function focusSavedElement() { return; } - $lastFocusedElement.focus(); + if ($lastFocusedElement.hasClass("ck")) { + // must handle CKEditor separately because of this bug: https://github.com/ckeditor/ckeditor5/issues/607 + // the bug manifests itself in resetting the cursor position to the first character - jumping above + + const editor = $lastFocusedElement + .closest('.ck-editor__editable') + .prop('ckeditorInstance'); + + editor.editing.view.focus(); + } else { + $lastFocusedElement.focus(); + } + $lastFocusedElement = null; } @@ -241,7 +253,7 @@ async function openDialog($dialog, closeActDialog = true) { } saveFocusedElement(); -- + $dialog.modal(); $dialog.on('hidden.bs.modal', () => {