From edb4e3d537f3219d8134591ae35b7682555fe510 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Mon, 11 Nov 2024 17:24:20 +0100 Subject: [PATCH] Improve selection detection for "Add comment" tooltip (#21731) GitOrigin-RevId: cd13cacea0d6e45015997f3a831d0f127ddf8cd8 --- .../extensions/review-tooltip.ts | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts b/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts index 147d6bf31e..ea268a7703 100644 --- a/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts +++ b/services/web/frontend/js/features/source-editor/extensions/review-tooltip.ts @@ -43,24 +43,21 @@ export const reviewTooltip = (): Extension => { return [ reviewTooltipTheme, reviewTooltipStateField, + EditorView.updateListener.of(update => { + if (update.selectionSet && !update.state.selection.main.empty) { + update.view.dispatch({ + effects: textSelectedEffect.of(update.view), + }) + } else if ( + !update.startState.selection.main.empty && + update.state.selection.main.empty + ) { + update.view.dispatch({ + effects: removeReviewPanelTooltipEffect.of(null), + }) + } + }), EditorView.domEventHandlers({ - mouseup(event, view) { - if (!view.state.selection.main.empty) { - view.dispatch({ - effects: textSelectedEffect.of(view), - }) - } - }, - keyup(event, view) { - if ( - (event.shiftKey || event.key === 'Meta') && - !view.state.selection.main.empty - ) { - view.dispatch({ - effects: textSelectedEffect.of(view), - }) - } - }, mousedown(event, view) { view.dispatch({ effects: removeReviewPanelTooltipEffect.of(null),