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 bcce6ea6ed..147d6bf31e 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 @@ -14,13 +14,16 @@ import { } from '@codemirror/state' import { isSplitTestEnabled } from '@/utils/splitTestUtils' import { v4 as uuid } from 'uuid' -import { textSelected, textSelectedEffect } from './text-selected' import { isCursorNearViewportTop } from '../utils/is-cursor-near-edge' export const addNewCommentRangeEffect = StateEffect.define>() export const removeNewCommentRangeEffect = StateEffect.define() +export const textSelectedEffect = StateEffect.define() + +export const removeReviewPanelTooltipEffect = StateEffect.define() + export const buildAddNewCommentRangeEffect = (range: SelectionRange) => { return addNewCommentRangeEffect.of( Decoration.mark({ @@ -37,7 +40,34 @@ export const reviewTooltip = (): Extension => { return [] } - return [reviewTooltipTheme, reviewTooltipStateField, textSelected] + return [ + reviewTooltipTheme, + reviewTooltipStateField, + 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), + }) + }, + }), + ] } export const reviewTooltipStateField = StateField.define<{ @@ -54,6 +84,10 @@ export const reviewTooltipStateField = StateField.define<{ addCommentRanges = addCommentRanges.map(tr.changes) for (const effect of tr.effects) { + if (effect.is(removeReviewPanelTooltipEffect)) { + return { tooltip: null, addCommentRanges } + } + if (effect.is(removeNewCommentRangeEffect)) { const rangeToRemove = effect.value addCommentRanges = addCommentRanges.update({ diff --git a/services/web/frontend/js/features/source-editor/extensions/text-selected.ts b/services/web/frontend/js/features/source-editor/extensions/text-selected.ts deleted file mode 100644 index 71456bac97..0000000000 --- a/services/web/frontend/js/features/source-editor/extensions/text-selected.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { StateEffect } from '@codemirror/state' -import { EditorView, ViewPlugin } from '@codemirror/view' - -export const textSelectedEffect = StateEffect.define() - -export const textSelected = ViewPlugin.define(view => { - function mouseUpListener() { - if (!view.state.selection.main.empty) { - view.dispatch({ - effects: textSelectedEffect.of(view), - }) - } - } - function keyUpListener(event: KeyboardEvent) { - if ( - (event.shiftKey || event.key === 'Meta') && - !view.state.selection.main.empty - ) { - view.dispatch({ - effects: textSelectedEffect.of(view), - }) - } - } - - view.dom.addEventListener('mouseup', mouseUpListener) - view.dom.addEventListener('keyup', keyUpListener) - - return { - destroy() { - view.dom.removeEventListener('mouseup', mouseUpListener) - view.dom.removeEventListener('keyup', keyUpListener) - }, - } -})