mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
06e24c9081
show Add comment button on mouse up event GitOrigin-RevId: 2c87f11fab9f9fb7e11637bb9eac2ca1ab9b298b
34 lines
958 B
TypeScript
34 lines
958 B
TypeScript
import { SelectionRange, StateEffect } from '@codemirror/state'
|
|
import { ViewPlugin } from '@codemirror/view'
|
|
|
|
export const textSelectedEffect = StateEffect.define<SelectionRange>()
|
|
|
|
export const textSelected = ViewPlugin.define(view => {
|
|
function mouseUpListener() {
|
|
if (!view.state.selection.main.empty) {
|
|
view.dispatch({
|
|
effects: textSelectedEffect.of(view.state.selection.main),
|
|
})
|
|
}
|
|
}
|
|
function keyUpListener(event: KeyboardEvent) {
|
|
if (
|
|
(event.shiftKey || event.key === 'Meta') &&
|
|
!view.state.selection.main.empty
|
|
) {
|
|
view.dispatch({
|
|
effects: textSelectedEffect.of(view.state.selection.main),
|
|
})
|
|
}
|
|
}
|
|
|
|
view.dom.addEventListener('mouseup', mouseUpListener)
|
|
view.dom.addEventListener('keyup', keyUpListener)
|
|
|
|
return {
|
|
destroy() {
|
|
view.dom.removeEventListener('mouseup', mouseUpListener)
|
|
view.dom.removeEventListener('keyup', keyUpListener)
|
|
},
|
|
}
|
|
})
|