Skip to content

Commit 97a3356

Browse files
Remove 'blur' causing issue with toggle markdown
1 parent 8417a42 commit 97a3356

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

webapp/src/components/TiptapInline.vue

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div ref="editorContainer" class="position-relative" v-bind="$attrs">
33
<div
44
v-if="editor && (showToolbar || markdownMode)"
5+
ref="toolbarContainer"
56
class="btn-toolbar mb-2 border rounded p-2 shadow-sm bg-white sticky-top overflow-auto flex-wrap"
67
style="z-index: 10; gap: 0.5rem"
78
>
@@ -31,6 +32,7 @@
3132
type="checkbox"
3233
class="custom-control-input"
3334
@change="toggleMarkdownView"
35+
@mousedown.prevent.stop
3436
/>
3537
<label class="custom-control-label" for="markdownToggleSwitch">
3638
{{ markdownMode ? "Markdown" : "Preview" }}
@@ -642,30 +644,8 @@ export default {
642644
643645
this.editor.on("update", () => this.$emit("update:modelValue", this.editor.getHTML()));
644646
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;
667648
});
668-
669649
this.editor.view.dom.addEventListener(
670650
"mousedown",
671651
(e) => {
@@ -705,10 +685,13 @@ export default {
705685
},
706686
handleClickOutside(event) {
707687
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;
712695
this.showToolbar = false;
713696
this.showColorPicker = false;
714697
}

0 commit comments

Comments
 (0)