fix(editor): don't prevent typing editor focus shortcut when other instance of an editor is focused already
This commit is contained in:
parent
a453449fea
commit
2864854cd4
@ -162,6 +162,7 @@ import BaseButton from '@/components/base/BaseButton.vue'
|
|||||||
import XButton from '@/components/input/button.vue'
|
import XButton from '@/components/input/button.vue'
|
||||||
import {Placeholder} from '@tiptap/extension-placeholder'
|
import {Placeholder} from '@tiptap/extension-placeholder'
|
||||||
import {eventToHotkeyString} from '@github/hotkey'
|
import {eventToHotkeyString} from '@github/hotkey'
|
||||||
|
import {useBaseStore} from '@/stores/base'
|
||||||
|
|
||||||
const {t} = useI18n()
|
const {t} = useI18n()
|
||||||
|
|
||||||
@ -205,6 +206,8 @@ const {
|
|||||||
editShortcut?: string,
|
editShortcut?: string,
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const baseStore = useBaseStore()
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue', 'save'])
|
const emit = defineEmits(['update:modelValue', 'save'])
|
||||||
|
|
||||||
const inputHTML = ref('')
|
const inputHTML = ref('')
|
||||||
@ -363,6 +366,12 @@ const editor = useEditor({
|
|||||||
// JSON
|
// JSON
|
||||||
// this.$emit('update:modelValue', this.editor.getJSON())
|
// this.$emit('update:modelValue', this.editor.getJSON())
|
||||||
},
|
},
|
||||||
|
onFocus() {
|
||||||
|
baseStore.setEditorFocused(true)
|
||||||
|
},
|
||||||
|
onBlur() {
|
||||||
|
baseStore.setEditorFocused(false)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(inputHTML, (value) => {
|
watch(inputHTML, (value) => {
|
||||||
@ -475,7 +484,7 @@ function handleImagePaste(event) {
|
|||||||
function setFocusToEditor(event) {
|
function setFocusToEditor(event) {
|
||||||
const hotkeyString = eventToHotkeyString(event)
|
const hotkeyString = eventToHotkeyString(event)
|
||||||
if (!hotkeyString) return
|
if (!hotkeyString) return
|
||||||
if (hotkeyString !== editShortcut || editor.value?.isFocused) return
|
if (hotkeyString !== editShortcut || baseStore.editorFocused) return
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
editor.value?.commands.focus()
|
editor.value?.commands.focus()
|
||||||
|
@ -30,6 +30,7 @@ export const useBaseStore = defineStore('base', () => {
|
|||||||
const quickActionsActive = ref(false)
|
const quickActionsActive = ref(false)
|
||||||
const logoVisible = ref(true)
|
const logoVisible = ref(true)
|
||||||
const updateAvailable = ref(false)
|
const updateAvailable = ref(false)
|
||||||
|
const editorFocused = ref(false) // To allow tracking over multiple instances of the editor
|
||||||
|
|
||||||
function setLoading(newLoading: boolean) {
|
function setLoading(newLoading: boolean) {
|
||||||
loading.value = newLoading
|
loading.value = newLoading
|
||||||
@ -92,6 +93,10 @@ export const useBaseStore = defineStore('base', () => {
|
|||||||
updateAvailable.value = value
|
updateAvailable.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setEditorFocused(value: boolean) {
|
||||||
|
editorFocused.value = value
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSetCurrentProject(
|
async function handleSetCurrentProject(
|
||||||
{project, forceUpdate = false}: {project: IProject | null, forceUpdate?: boolean},
|
{project, forceUpdate = false}: {project: IProject | null, forceUpdate?: boolean},
|
||||||
) {
|
) {
|
||||||
@ -150,6 +155,7 @@ export const useBaseStore = defineStore('base', () => {
|
|||||||
quickActionsActive: readonly(quickActionsActive),
|
quickActionsActive: readonly(quickActionsActive),
|
||||||
logoVisible: readonly(logoVisible),
|
logoVisible: readonly(logoVisible),
|
||||||
updateAvailable: readonly(updateAvailable),
|
updateAvailable: readonly(updateAvailable),
|
||||||
|
editorFocused: readonly(editorFocused),
|
||||||
|
|
||||||
setLoading,
|
setLoading,
|
||||||
setReady,
|
setReady,
|
||||||
@ -161,6 +167,7 @@ export const useBaseStore = defineStore('base', () => {
|
|||||||
setBlurHash,
|
setBlurHash,
|
||||||
setLogoVisible,
|
setLogoVisible,
|
||||||
setUpdateAvailable,
|
setUpdateAvailable,
|
||||||
|
setEditorFocused,
|
||||||
|
|
||||||
handleSetCurrentProject,
|
handleSetCurrentProject,
|
||||||
loadApp,
|
loadApp,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user