|
1 | | -import { h, ref, computed, watch, onMounted, nextTick, getCurrentInstance } from 'vue' |
| 1 | +import { h, ref, computed, watch, onMounted, onBeforeUnmount, nextTick, getCurrentInstance } from 'vue' |
2 | 2 |
|
3 | 3 | import Caret from './editor-caret.js' |
4 | 4 | import { getToolbar, getFonts, getLinkEditor } from './editor-utils.js' |
@@ -400,27 +400,12 @@ export default createComponent({ |
400 | 400 | } |
401 | 401 | } |
402 | 402 |
|
403 | | - function onMousedown () { |
| 403 | + function onPointerStart () { |
404 | 404 | offsetBottom = void 0 |
405 | 405 | } |
406 | 406 |
|
407 | | - function onMouseup (e) { |
| 407 | + function onSelectionchange (e) { |
408 | 408 | 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) |
424 | 409 | } |
425 | 410 |
|
426 | 411 | function setContent (v, restorePosition) { |
@@ -477,6 +462,12 @@ export default createComponent({ |
477 | 462 | eVm.caret = proxy.caret = new Caret(contentRef.value, eVm) |
478 | 463 | setContent(props.modelValue) |
479 | 464 | refreshToolbar() |
| 465 | + |
| 466 | + document.addEventListener('selectionchange', onSelectionchange) |
| 467 | + }) |
| 468 | + |
| 469 | + onBeforeUnmount(() => { |
| 470 | + document.removeEventListener('selectionchange', onSelectionchange) |
480 | 471 | }) |
481 | 472 |
|
482 | 473 | return () => { |
@@ -532,13 +523,8 @@ export default createComponent({ |
532 | 523 | onFocus, |
533 | 524 |
|
534 | 525 | // clean saved scroll position |
535 | | - onMousedown, |
536 | | - onTouchstartPassive, |
537 | | - |
538 | | - // save caret |
539 | | - onMouseup, |
540 | | - onKeyup, |
541 | | - onTouchend |
| 526 | + onMousedown: onPointerStart, |
| 527 | + onTouchstartPassive: onPointerStart |
542 | 528 | }) |
543 | 529 | ]) |
544 | 530 | } |
|
0 commit comments