Skip to content

Commit

Permalink
fix: table errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Jan 30, 2025
1 parent c7afbe1 commit 5fbdb9d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/components/src/table-block/view/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ export function createDragOverHandler(refs: Refs): (e: DragEvent) => void {
const info = dragInfo.current
if (!info) return

if (!contentRoot.offsetParent) return

const wrapperOffsetTop = (contentRoot.offsetParent as HTMLElement).offsetTop
const wrapperOffsetLeft = (contentRoot.offsetParent as HTMLElement)
.offsetLeft
Expand Down
21 changes: 14 additions & 7 deletions packages/crepe/src/feature/block-edit/menu/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
orderedListSchema,
paragraphSchema,
} from '@milkdown/kit/preset/commonmark'
import { NodeSelection } from '@milkdown/kit/prose/state'
import { TextSelection } from '@milkdown/kit/prose/state'
import { imageBlockSchema } from '@milkdown/kit/component/image-block'
import { createTable } from '@milkdown/kit/preset/gfm'
import {
Expand Down Expand Up @@ -230,15 +230,22 @@ export function getGroups(filter?: string, config?: BlockEditFeatureConfig) {
onRun: (ctx) => {
const view = ctx.get(editorViewCtx)
const { dispatch, state } = view
const tr = clearRange(state.tr)
let { tr } = state
tr = clearRange(tr)
const from = tr.selection.from
const table = createTable(ctx, 3, 3)
tr.replaceSelectionWith(table)
const { from } = tr.selection
const pos = from - table.nodeSize + 2
tr = tr.replaceSelectionWith(table)
dispatch(tr)

requestAnimationFrame(() => {
const selection = NodeSelection.create(view.state.tr.doc, pos)
dispatch(view.state.tr.setSelection(selection).scrollIntoView())
const docSize = view.state.doc.content.size
const $pos = view.state.doc.resolve(
from > docSize ? docSize : from < 0 ? 0 : from
)
const selection = TextSelection.near($pos)
const tr = view.state.tr
tr.setSelection(selection)
dispatch(tr.scrollIntoView())
})
},
})
Expand Down

0 comments on commit 5fbdb9d

Please sign in to comment.