Skip to content

Commit 7f535e4

Browse files
committed
🐛 Fix pasting image appears in wrong location
Fixed #46 Fixed https://git.mczhengyi.top/zhengyi/halo-plugin-vditor/issues/88
1 parent d49db5f commit 7f535e4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

console/src/views/VditorMde.vue

+7-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const customInsertOpen = ref(false);
4242
const customInsertSchema = ref<Schema>(joeProgress);
4343
let lastSelectionRange: Range | undefined = undefined;
4444
// Image Upload
45-
let imageUploadCursor: Range | undefined;
4645
const imageUploadLock = false;
4746
let allowImageUpload: string[] = [];
4847
// Debug
@@ -189,8 +188,6 @@ onMounted(async () => {
189188
vditor.value.tip("当前已经存在正在上传的文件,请等待上传完成", 2000);
190189
return;
191190
}
192-
// Save cursor
193-
imageUploadCursor = getCursor();
194191
// Check extension name
195192
const extendName = files[0].name
196193
.slice(files[0].name.lastIndexOf(".") + 1)
@@ -201,21 +198,20 @@ onMounted(async () => {
201198
}
202199
// Upload
203200
if (props.uploadImage) {
201+
vditor.value.disabled();
204202
vditor.value.tip("正在上传图片...", 2000);
205203
props.uploadImage(files[0]).then((res: Attachment) => {
206-
if (!res.status) return;
207-
vditor.value.disabled();
208-
// Move cursor
209-
const tmpCursor = getCursor();
210-
setCursor(imageUploadCursor);
211-
imageUploadCursor = undefined;
212-
// Insert
204+
if (!res.status) {
205+
vditor.value.enable();
206+
return;
207+
}
208+
// Insert Image
213209
vditor.value.insertValue(
214210
`\n\n![${res.spec.displayName}](${res.status.permalink})\n\n`
215211
);
216212
// Restore cursor
217-
setCursor(tmpCursor);
218213
vditor.value.enable();
214+
vditor.value.focus();
219215
});
220216
}
221217
return null;

0 commit comments

Comments
 (0)