Skip to content

Commit

Permalink
fix: divider - 键盘删除
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfupeng1988 committed Feb 23, 2022
1 parent 2652241 commit 31db059
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
13 changes: 6 additions & 7 deletions packages/basic-modules/src/assets/divider.less
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
@import "../../../vars.less";

.w-e-textarea-divider {
padding: 10px 0;
cursor: pointer;
padding: 20px 20px;
margin: 20px auto;
border-radius: 3px;

&:hover {
background-color: @textarea-slight-bg-color;
}
// &:hover {
// background-color: @textarea-slight-bg-color;
// }

hr {
display: block;
width: 90%;
margin: 20px auto;
border: 0;
height: 1px;
background-color: @textarea-border-color;
Expand Down
4 changes: 2 additions & 2 deletions packages/basic-modules/src/modules/divider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import withDivider from './plugin'
import { renderDividerConf } from './render-elem'
import { dividerToHtmlConf } from './elem-to-html'
import { parseHtmlConf } from './parse-elem-html'
import { insertDividerMenuConf, deleteDividerMenuConf } from './menu/index'
import { insertDividerMenuConf } from './menu/index'

const image: Partial<IModuleConf> = {
renderElems: [renderDividerConf],
elemsToHtml: [dividerToHtmlConf],
parseElemsHtml: [parseHtmlConf],
menus: [insertDividerMenuConf, deleteDividerMenuConf],
menus: [insertDividerMenuConf],
editorPlugin: withDivider,
}

Expand Down
15 changes: 8 additions & 7 deletions packages/basic-modules/src/modules/divider/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import InsertDividerMenu from './InsertDividerMenu'
import DeleteDividerMenu from './DeleteDividerMenu'
// import DeleteDividerMenu from './DeleteDividerMenu.ts'

export const insertDividerMenuConf = {
key: 'divider',
Expand All @@ -13,9 +13,10 @@ export const insertDividerMenuConf = {
},
}

export const deleteDividerMenuConf = {
key: 'deleteDivider',
factory() {
return new DeleteDividerMenu()
},
}
// export const deleteDividerMenuConf = {
// key: 'deleteDivider',
// factory() {
// return new DeleteDividerMenu()
// },
// }
// divider 可用键盘删除了,所以注释掉该菜单 wangfupeng 22.02.23
27 changes: 17 additions & 10 deletions packages/basic-modules/src/modules/divider/render-elem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Element as SlateElement } from 'slate'
import { jsx, VNode } from 'snabbdom'
import { h, VNode } from 'snabbdom'
import { IDomEditor, DomEditor } from '@wangeditor/core'

function renderDivider(
Expand All @@ -17,15 +17,22 @@ function renderDivider(
// 是否选中
const selected = DomEditor.isNodeSelected(editor, elemNode)

const vnode = (
<div
contentEditable={false}
className="w-e-textarea-divider"
data-selected={selected ? 'true' : ''} // 标记为 选中
style={renderStyle}
>
<hr />
</div>
const vnode = h(
'div',
{
props: {
contentEditable: false,
className: 'w-e-textarea-divider',
},
dataset: {
selected: selected ? 'true' : '',
},
style: renderStyle,
on: {
mousedown: event => event.preventDefault(),
},
},
[h('hr')]
)
// 【注意】void node 中,renderElem 不用处理 children 。core 会统一处理。

Expand Down
3 changes: 0 additions & 3 deletions packages/editor/src/init-default-config/config/hoverbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ const COMMON_HOVERBAR_KEYS = {
'deleteTable',
],
},
divider: {
menuKeys: ['deleteDivider'],
},
}

export function genDefaultHoverbarKeys() {
Expand Down

0 comments on commit 31db059

Please sign in to comment.