Skip to content

Commit 2fbd3ee

Browse files
committed
fix: error of insert action
1 parent 1a7eeab commit 2fbd3ee

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/components/CodemirrorEditor/InsertFormDialog.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup>
2-
import { ref } from 'vue'
2+
import { ref, toRaw } from 'vue'
33
import { useStore } from '@/stores'
44
import { createTable } from '@/utils'
55
66
const store = useStore()
77
8-
const { formatContent, toggleShowInsertFormDialog } = store
8+
const { toggleShowInsertFormDialog } = store
99
1010
const rowNum = ref(3)
1111
const colNum = ref(3)
@@ -24,12 +24,8 @@ function insertTable() {
2424
cols: colNum.value,
2525
data: tableData.value,
2626
})
27-
store.editor.operation(() => {
28-
store.editor.replaceSelection(`\n${table}\n`, `end`)
29-
})
30-
store.editorRefresh()
27+
toRaw(store.editor).replaceSelection(`\n${table}\n`, `end`)
3128
resetVal()
32-
formatContent()
3329
toggleShowInsertFormDialog()
3430
}
3531
</script>

src/views/CodemirrorEditor.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import { onMounted, ref } from 'vue'
2+
import { onMounted, ref, toRaw } from 'vue'
33
import { storeToRefs } from 'pinia'
44
import { ElMessage } from 'element-plus'
55
import CodeMirror from 'codemirror'
@@ -180,10 +180,10 @@ function uploaded(imageUrl) {
180180
const cursor = editor.value.getCursor()
181181
const markdownImage = `![](${imageUrl})`
182182
// 将 Markdown 形式的 URL 插入编辑框光标所在位置
183-
editor.value.replaceSelection(`\n${markdownImage}\n`, cursor)
183+
toRaw(store.editor).replaceSelection(`\n${markdownImage}\n`, cursor)
184184
ElMessage.success(`图片上传成功`)
185-
formatContent()
186-
onEditorRefresh()
185+
// formatContent()
186+
// onEditorRefresh()
187187
}
188188
function uploadImage(file, cb) {
189189
isImgLoading.value = true

0 commit comments

Comments
 (0)