Allow selecting comment text without changing scroll position (#23628)

* Allow selecting comment text without changing scroll position

* cursor:default on review content

* check text selection on mouseup

* update comment

GitOrigin-RevId: f867613f5b4d08c3b960abfa061b14b404f411a8
This commit is contained in:
Domagoj Kriskovic
2025-02-21 12:45:08 +01:00
committed by Copybot
parent db4728d292
commit f46b7d4fd1
2 changed files with 21 additions and 2 deletions

View File

@@ -51,12 +51,13 @@ export const ReviewPanelEntry: FC<{
const { setReviewPanelOpen, reviewPanelOpen } = useLayoutContext()
const highlighted = isSelectionWithinOp(op, state.selection.main)
const entryRef = useRef<HTMLDivElement>(null)
const mousePressedRef = useRef(false)
const openReviewPanel = useCallback(() => {
setReviewPanelOpen(true)
}, [setReviewPanelOpen])
const focusHandler = useCallback(
const selectEntry = useCallback(
event => {
setFocused(true)
@@ -77,11 +78,17 @@ export const ReviewPanelEntry: FC<{
(entryRef.current?.offsetHeight || 0)
if (entryBottom > OFFSET_FOR_ENTRIES_ABOVE) {
// if the entry textarea is visible, no need to select the entry
// so that it doesn't scroll out of view as user types
setTextareaFocused(true)
return
}
}
if (mousePressedRef.current) {
return
}
setSelected(true)
if (!selectLineOnFocus) {
@@ -131,8 +138,19 @@ export const ReviewPanelEntry: FC<{
return (
<div
ref={entryRef}
onFocus={focusHandler}
onMouseDown={() => {
mousePressedRef.current = true
}}
onMouseUp={event => {
mousePressedRef.current = false
const isTextSelected = Boolean(window.getSelection()?.toString())
if (!isTextSelected && !selected) {
selectEntry(event)
}
}}
onFocus={selectEntry}
onBlur={() => {
mousePressedRef.current = false
setSelected(false)
setFocused(false)
setTextareaFocused(false)

View File

@@ -383,6 +383,7 @@
.review-panel-expandable-content {
display: inline;
padding-right: var(--spacing-02);
cursor: default;
}
.review-panel-expandable-inline {