mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Scroll selection anchor into view when adding new comment (#21328)
* Scroll selection anchor into view when adding new comment * check if cursor is near viewport edge GitOrigin-RevId: 57d4195f7ce1513a56249365b45b3959b4ea813f
This commit is contained in:
committed by
Copybot
parent
4bcc7c9602
commit
db23262611
@@ -0,0 +1,23 @@
|
||||
import { EditorView } from '@codemirror/view'
|
||||
|
||||
const TOP_EDGE_THRESHOLD = 100
|
||||
const BOTTOM_EDGE_THRESHOLD = 200
|
||||
|
||||
export function isCursorNearViewportEdge(view: EditorView, pos: number) {
|
||||
const cursorCoords = view.coordsAtPos(pos)
|
||||
|
||||
if (!cursorCoords) {
|
||||
return false
|
||||
}
|
||||
|
||||
const scrollInfo = view.scrollDOM.getBoundingClientRect()
|
||||
|
||||
// check if the cursor is near the top of the viewport
|
||||
if (Math.abs(cursorCoords.bottom - scrollInfo.top) <= TOP_EDGE_THRESHOLD) {
|
||||
return true
|
||||
}
|
||||
// check if the cursor is near the bottom of the viewport
|
||||
const viewportHeight = view.scrollDOM.clientHeight
|
||||
const viewportBottom = scrollInfo.top + viewportHeight
|
||||
return Math.abs(cursorCoords.bottom - viewportBottom) <= BOTTOM_EDGE_THRESHOLD
|
||||
}
|
||||
Reference in New Issue
Block a user