fix: 添加模板时形状内文字异常自动聚焦

This commit is contained in:
pipipi-pikachu 2022-06-18 09:25:13 +08:00
parent fb8a6f8c39
commit 7318755011
2 changed files with 13 additions and 3 deletions

View File

@ -121,6 +121,10 @@ onUnmounted(() => {
editorView && editorView.destroy()
})
// focus
const focus = () => editorView.focus()
defineExpose({ focus })
//
//
const execCommand = ({ target, action }: RichTextCommand) => {

View File

@ -25,7 +25,7 @@
v-contextmenu="contextmenus"
@mousedown="$event => handleSelectElement($event)"
@touchstart="$event => handleSelectElement($event)"
@dblclick="editable = true"
@dblclick="startEdit()"
>
<svg
overflow="visible"
@ -60,12 +60,12 @@
<div class="shape-text" :class="[text.align, { 'editable': editable || text.content }]">
<ProsemirrorEditor
ref="prosemirrorEditorRef"
v-if="editable || text.content"
:elementId="elementInfo.id"
:defaultColor="text.defaultColor"
:defaultFontName="text.defaultFontName"
:editable="!elementInfo.lock"
:autoFocus="true"
:value="text.content"
@update="value => updateText(value)"
@blur="checkEmptyText()"
@ -79,7 +79,7 @@
</template>
<script lang="ts" setup>
import { computed, PropType, ref, watch } from 'vue'
import { computed, nextTick, PropType, ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore } from '@/store'
import { PPTShapeElement, ShapeText } from '@/types/slides'
@ -168,6 +168,12 @@ const checkEmptyText = () => {
addHistorySnapshot()
}
}
const prosemirrorEditorRef = ref<typeof ProsemirrorEditor>()
const startEdit = () => {
editable.value = true
nextTick(() => prosemirrorEditorRef.value && prosemirrorEditorRef.value.focus())
}
</script>
<style lang="scss" scoped>