Skip to content

Commit afc8251

Browse files
committed
粘贴插入图片时,会自动滚动到起始位置问题修复
目前发现这种恢复的方式是验证多次后的相对好的方案,默认的focus方法 不能解决
1 parent ca3b492 commit afc8251

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/extensions/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,25 @@ export const getDefaultExtensions = ({
175175
FileHandler.configure({
176176
allowedMimeTypes: file?.allowedMimeTypes,
177177
onPaste(editor: Editor, files: any) {
178+
//记录 已有位置
179+
const pageContainer = document.querySelector(
180+
`${container} .umo-zoomable-container`,
181+
) as HTMLElement
182+
const scrollTop = pageContainer?.scrollTop || 0
178183
for (const file of files) {
179184
editor.commands.insertFile({
180185
file,
181186
uploadFileMap: uploadFileMap.value,
182187
autoType: true,
183188
})
184189
}
190+
// 恢复滚动位置
191+
if (pageContainer) {
192+
// 使用 setTimeout 确保 DOM 更新完成后再恢复滚动位置
193+
setTimeout(() => {
194+
pageContainer.scrollTop = scrollTop
195+
}, 0)
196+
}
185197
},
186198
onDrop: (editor: Editor, files: any, pos: number) => {
187199
for (const file of files) {

0 commit comments

Comments
 (0)