fix: 修复禁用状态下scroll-to-head功能失效

This commit is contained in:
86driver 2021-04-29 23:29:49 +08:00
parent bc6cbbd8f4
commit 79d13267cb
4 changed files with 9 additions and 1 deletions

View File

@ -37,6 +37,7 @@ export default function disableInit(editor: Editor) {
$menuDom = $(`<div class="w-e-menue-mantle" style="z-index:${menuZindexValue}"></div>`)
editor.$toolbarElem.append($menuDom)
isCurtain = true
editor.isEnable = false
}
// 销毁幕布并显示可编辑区域
@ -46,6 +47,7 @@ export default function disableInit(editor: Editor) {
$menuDom.remove()
editor.$textElem.show()
isCurtain = false
editor.isEnable = true
}
return { disable, enable }

View File

@ -65,6 +65,7 @@ class Editor {
public zIndex: ZIndex
public change: Change
public history: History
public isEnable: Boolean
// 实例销毁前需要执行的钩子集合
private beforeDestroyHooks: Function[] = []
@ -112,6 +113,7 @@ class Editor {
const { disable, enable } = disableInit(this)
this.disable = disable
this.enable = enable
this.isEnable = true
}
/**

View File

@ -11,7 +11,9 @@ import Editor from '../index'
* @param id id
*/
const scrollToHead = (editor: Editor, id: string) => {
const $textElem = editor.$textElem
const $textElem = editor.isEnable
? editor.$textElem
: editor.$textContainerElem.find('.w-e-content-mantle')
const $targetHead = $textElem.find(`[id='${id}']`)
const targetTop = $targetHead.getOffsetData().top
$textElem.scrollTop(targetTop)

View File

@ -44,8 +44,10 @@ describe('Editor disable', () => {
disabledObj.disable()
expect(editor.$textElem.elems[0].style.display).toBe('none')
expect(editor.isEnable).toBe(false)
disabledObj.enable()
expect(editor.isEnable).toBe(true)
expect(editor.$textElem.elems[0].style.display).toBe('block')
})