Skip to content

Commit 95665ee

Browse files
authored
fix(QEditor): get selection on selectionchange #13326 (#13330)
- fixes selection on mobile - fixes selection when mouseup is outside editor
1 parent 060ed54 commit 95665ee

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

ui/src/components/editor/QEditor.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, ref, computed, watch, onMounted, nextTick, getCurrentInstance } from 'vue'
1+
import { h, ref, computed, watch, onMounted, onBeforeUnmount, nextTick, getCurrentInstance } from 'vue'
22

33
import Caret from './editor-caret.js'
44
import { getToolbar, getFonts, getLinkEditor } from './editor-utils.js'
@@ -400,27 +400,12 @@ export default createComponent({
400400
}
401401
}
402402

403-
function onMousedown () {
403+
function onPointerStart () {
404404
offsetBottom = void 0
405405
}
406406

407-
function onMouseup (e) {
407+
function onSelectionchange (e) {
408408
eVm.caret.save()
409-
emit('mouseup', e)
410-
}
411-
412-
function onTouchstartPassive () {
413-
offsetBottom = void 0
414-
}
415-
416-
function onKeyup (e) {
417-
eVm.caret.save()
418-
emit('keyup', e)
419-
}
420-
421-
function onTouchend (e) {
422-
eVm.caret.save()
423-
emit('touchend', e)
424409
}
425410

426411
function setContent (v, restorePosition) {
@@ -477,6 +462,12 @@ export default createComponent({
477462
eVm.caret = proxy.caret = new Caret(contentRef.value, eVm)
478463
setContent(props.modelValue)
479464
refreshToolbar()
465+
466+
document.addEventListener('selectionchange', onSelectionchange)
467+
})
468+
469+
onBeforeUnmount(() => {
470+
document.removeEventListener('selectionchange', onSelectionchange)
480471
})
481472

482473
return () => {
@@ -532,13 +523,8 @@ export default createComponent({
532523
onFocus,
533524

534525
// clean saved scroll position
535-
onMousedown,
536-
onTouchstartPassive,
537-
538-
// save caret
539-
onMouseup,
540-
onKeyup,
541-
onTouchend
526+
onMousedown: onPointerStart,
527+
onTouchstartPassive: onPointerStart
542528
})
543529
])
544530
}

0 commit comments

Comments
 (0)