wangeditor
Version:
wangEditor - 轻量级 web 富文本编辑器,配置方便,使用简单,开源免费
27 lines (23 loc) • 701 B
text/typescript
/**
* @description 检查选区是否在代码中,即菜单是否应该 active
* @author lkw
*/
import Editor from '../../editor/index'
function isActive(editor: Editor): boolean {
const $selectionELem = editor.selection.getSelectionContainerElem()
if (!$selectionELem?.length) {
return false
}
if (
$selectionELem.getNodeName() == 'CODE' ||
$selectionELem.getNodeName() == 'PRE' ||
$selectionELem.parent().getNodeName() == 'CODE' ||
$selectionELem.parent().getNodeName() == 'PRE' ||
/hljs/.test($selectionELem.parent().attr('class'))
) {
return true
} else {
return false
}
}
export default isActive