|
2 | 2 | <div ref="editorContainer" class="position-relative" v-bind="$attrs">
|
3 | 3 | <div
|
4 | 4 | v-if="editor && (showToolbar || markdownMode)"
|
| 5 | + ref="toolbarContainer" |
5 | 6 | class="btn-toolbar mb-2 border rounded p-2 shadow-sm bg-white sticky-top overflow-auto flex-wrap"
|
6 | 7 | style="z-index: 10; gap: 0.5rem"
|
7 | 8 | >
|
|
31 | 32 | type="checkbox"
|
32 | 33 | class="custom-control-input"
|
33 | 34 | @change="toggleMarkdownView"
|
| 35 | + @mousedown.prevent.stop |
34 | 36 | />
|
35 | 37 | <label class="custom-control-label" for="markdownToggleSwitch">
|
36 | 38 | {{ markdownMode ? "Markdown" : "Preview" }}
|
@@ -642,30 +644,8 @@ export default {
|
642 | 644 |
|
643 | 645 | this.editor.on("update", () => this.$emit("update:modelValue", this.editor.getHTML()));
|
644 | 646 | this.editor.on("focus", () => {
|
645 |
| - if (!this.markdownMode) { |
646 |
| - this.showToolbar = true; |
647 |
| - } |
648 |
| - }); |
649 |
| -
|
650 |
| - this.editor.on("blur", () => { |
651 |
| - if (!this.markdownMode) { |
652 |
| - setTimeout(() => { |
653 |
| - const suggestionEl = document.querySelector(".tiptap-suggestions"); |
654 |
| - const editorHasFocus = this.$refs.editorContainer?.contains(document.activeElement); |
655 |
| - const hasSelection = this.editor && !this.editor.state.selection.empty; |
656 |
| -
|
657 |
| - if ( |
658 |
| - !editorHasFocus && |
659 |
| - !hasSelection && |
660 |
| - (!suggestionEl || !suggestionEl.contains(document.activeElement)) |
661 |
| - ) { |
662 |
| - this.showToolbar = false; |
663 |
| - this.showColorPicker = false; |
664 |
| - } |
665 |
| - }, 50); |
666 |
| - } |
| 647 | + this.showToolbar = true; |
667 | 648 | });
|
668 |
| -
|
669 | 649 | this.editor.view.dom.addEventListener(
|
670 | 650 | "mousedown",
|
671 | 651 | (e) => {
|
@@ -705,10 +685,13 @@ export default {
|
705 | 685 | },
|
706 | 686 | handleClickOutside(event) {
|
707 | 687 | const editorElement = this.$refs.editorContainer;
|
708 |
| - if (editorElement && !editorElement.contains(event.target)) { |
709 |
| - if (this.editor && !this.editor.state.selection.empty) { |
710 |
| - return; |
711 |
| - } |
| 688 | + const toolbarElement = this.$refs.toolbarContainer; |
| 689 | + if ( |
| 690 | + editorElement && |
| 691 | + !editorElement.contains(event.target) && |
| 692 | + !(toolbarElement && toolbarElement.contains(event.target)) |
| 693 | + ) { |
| 694 | + if (this.editor && !this.editor.state.selection.empty) return; |
712 | 695 | this.showToolbar = false;
|
713 | 696 | this.showColorPicker = false;
|
714 | 697 | }
|
|
0 commit comments