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() editorView && editorView.destroy()
}) })
// focus
const focus = () => editorView.focus()
defineExpose({ focus })
// //
// //
const execCommand = ({ target, action }: RichTextCommand) => { const execCommand = ({ target, action }: RichTextCommand) => {

View File

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