|
2 | 2 | * Copyright (c) 2021 - present core.ai |
3 | 3 | * SPDX-License-Identifier: LicenseRef-Proprietary |
4 | 4 | */ |
5 | | -/*global GLOBALS, LivePreviewView, dismissUIAndCleanupState, customReturns, proConstants, strings, icons*/ |
| 5 | +/*global GLOBALS, LivePreviewView, dismissUIAndCleanupState, customReturns, proConstants, strings, icons, SHARED_STATE*/ |
6 | 6 |
|
7 | 7 | // we store references to interaction blocker event handlers so we can remove them when switching modes |
8 | 8 | let _interactionBlockerHandlers = null; |
@@ -97,6 +97,14 @@ function registerInteractionBlocker() { |
97 | 97 | return; |
98 | 98 | } |
99 | 99 |
|
| 100 | + // allow clicks within the element that user is currently editing |
| 101 | + // this is done to prevent the interaction blocker from interfering with text editing |
| 102 | + if (SHARED_STATE._currentlyEditingElement && |
| 103 | + (SHARED_STATE._currentlyEditingElement === element || |
| 104 | + SHARED_STATE._currentlyEditingElement.contains(element))) { |
| 105 | + return; |
| 106 | + } |
| 107 | + |
100 | 108 | // BLOCK: Kill all user page interactions in edit mode |
101 | 109 | event.preventDefault(); |
102 | 110 | event.stopImmediatePropagation(); |
@@ -232,8 +240,9 @@ function startEditing(element) { |
232 | 240 | return; |
233 | 241 | } |
234 | 242 |
|
235 | | - // Make the element editable |
| 243 | + SHARED_STATE._currentlyEditingElement = element; |
236 | 244 | element.setAttribute("contenteditable", "true"); |
| 245 | + element.setAttribute("draggable", "false"); |
237 | 246 | element.focus(); |
238 | 247 | // to compare with the new text content, if same we don't make any changes in the editor area |
239 | 248 | const oldContent = element.textContent; |
@@ -321,8 +330,9 @@ function finishEditingCleanup(element) { |
321 | 330 | return; |
322 | 331 | } |
323 | 332 |
|
324 | | - // Remove contenteditable attribute |
| 333 | + SHARED_STATE._currentlyEditingElement = null; |
325 | 334 | element.removeAttribute("contenteditable"); |
| 335 | + element.removeAttribute("draggable"); |
326 | 336 | dismissUIAndCleanupState(); |
327 | 337 |
|
328 | 338 | // Remove event listeners |
|
0 commit comments