mavonEditor icon indicating copy to clipboard operation
mavonEditor copied to clipboard

[Bug] 上传图片到服务器后光标会跑到文章末尾

Open fivecakes opened this issue 3 years ago • 3 comments

🐛 Bug Report

上传图片到服务器后光标会跑到文章末尾,而不是在刚刚编辑的地方

我看了代码,上传图片后调用$img2Url替换url,在$img2Url函数里调用了iRender(),而d_value被监听也调用了一次iRender()。

我在$img2Url调用结束后,以及iRender()函数的末尾打印光标位置都是正确的,但是在这之后光标位置跑到了文章末尾,应该是后面又做了一些处理,但是我没搞清楚后面又有哪些函数被调用。

fivecakes avatar Dec 16 '20 12:12 fivecakes

我测试了一下,光标是正确保留在原来位置,你可以在这个官方示例上试试,如果只是你的环境才有这个问题,那就需要你提供一个重现用例了。

ygj6 avatar Jan 03 '21 02:01 ygj6

@ygj6

官方示例图片没上传到服务器,错误是替换服务器返回的url时出现的,你可以在我这个示例中试一下http://mavoneditor.fivecakes.com

fivecakes avatar Jan 03 '21 08:01 fivecakes

这个大概是因为iRender()触发了编辑器的重新渲染,光标位置被重置了,再新版本未修复这个问题之前你可以使用如下方式规避这个问题 。

let obj = this.$refs.md.getTextareaDom();
let startPos = obj.selectionStart;
let endPos = obj.selectionEnd;

this.$refs.md.$img2Url(pos, "test.jpg");
setTimeout(function(){
    obj.selectionStart = startPos;
    obj.selectionEnd = endPos;    
},1)

ygj6 avatar Jan 03 '21 08:01 ygj6