fix(editor): 修复滚动比例同步失效导致切换到底部
原 syncScrollRatio 封装在 display:'none' 之后重复读取源容器 scrollTop,此时浏览器已将其归零,导致比例计算为 0。改为提前 读取比例并直接应用,移除二次封装与调试日志。
This commit is contained in:
parent
914f168551
commit
ae6d80c9cc
@ -161,10 +161,11 @@ class TiptapEditorInstance {
|
|||||||
if (!this.isSourceMode) {
|
if (!this.isSourceMode) {
|
||||||
// 富文本 → 源码:导出当前 Markdown 到 textarea
|
// 富文本 → 源码:导出当前 Markdown 到 textarea
|
||||||
this.sourceTextarea.value = this.editor.getMarkdown()
|
this.sourceTextarea.value = this.editor.getMarkdown()
|
||||||
|
// 必须在 display:'none' 之前读取滚动比例——隐藏后 scrollTop 会被浏览器归零
|
||||||
|
const pmRatio = this.getScrollRatio(proseMirrorDom)
|
||||||
proseMirrorDom.style.display = 'none'
|
proseMirrorDom.style.display = 'none'
|
||||||
this.sourceTextarea.hidden = false
|
this.sourceTextarea.hidden = false
|
||||||
// 按滚动比例同步到源码视图,保持视觉位置一致
|
this.applyScrollRatio(this.sourceTextarea, pmRatio)
|
||||||
this.syncScrollRatio(proseMirrorDom, this.sourceTextarea)
|
|
||||||
this.sourceTextarea.focus()
|
this.sourceTextarea.focus()
|
||||||
this.toggleButton.textContent = '✎'
|
this.toggleButton.textContent = '✎'
|
||||||
this.toggleButton.title = '切换富文本'
|
this.toggleButton.title = '切换富文本'
|
||||||
@ -207,13 +208,6 @@ class TiptapEditorInstance {
|
|||||||
el.scrollTop = max * ratio
|
el.scrollTop = max * ratio
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 便捷封装:从源容器读取比例并应用到目标容器。
|
|
||||||
*/
|
|
||||||
private syncScrollRatio(from: HTMLElement, to: HTMLElement): void {
|
|
||||||
this.applyScrollRatio(to, this.getScrollRatio(from))
|
|
||||||
}
|
|
||||||
|
|
||||||
setMarkdown(content: string): void {
|
setMarkdown(content: string): void {
|
||||||
this.editor?.commands.setContent(content, { emitUpdate: false, contentType: 'markdown' })
|
this.editor?.commands.setContent(content, { emitUpdate: false, contentType: 'markdown' })
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user