mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
0329a18875
* Scroll selection anchor into view when adding new comment * check if cursor is near viewport edge * Show "add comment" tooltip below cursor if near viewport top GitOrigin-RevId: 0dc2234bc03b1d88a3719ba01a4a865f218b9bfa
34 lines
908 B
TypeScript
34 lines
908 B
TypeScript
import { StateEffect } from '@codemirror/state'
|
|
import { EditorView, ViewPlugin } from '@codemirror/view'
|
|
|
|
export const textSelectedEffect = StateEffect.define<EditorView>()
|
|
|
|
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)
|
|
},
|
|
}
|
|
})
|