(editor: Editor, at: Location | null = editor.selection)
| 40 | } |
| 41 | |
| 42 | export const handleInserInGrid = (editor: Editor, at: Location | null = editor.selection) => { |
| 43 | const { grid, start, end } = findGridOfEdges(editor, at) |
| 44 | // anchor 与 focus 在同一grid内 |
| 45 | if (grid) { |
| 46 | // 设置 selection 到 anchor |
| 47 | Transforms.collapse(editor, { edge: 'anchor' }) |
| 48 | } |
| 49 | // focus 在grid内 |
| 50 | else if (end) { |
| 51 | Transforms.collapse(editor, { edge: 'anchor' }) |
| 52 | return false |
| 53 | } |
| 54 | // anchor 在grid内 |
| 55 | else if (start) { |
| 56 | const [, startPath] = start |
| 57 | const grid = Grid.above(editor, startPath) |
| 58 | if (grid) { |
| 59 | const { children } = grid[0] |
| 60 | const path = startPath.slice(0, -1) |
| 61 | const rowIndex = path[path.length - 1] |
| 62 | if (rowIndex === 0) { |
| 63 | Grid.remove(editor, grid) |
| 64 | } else { |
| 65 | for (let r = children.length - 1; r >= rowIndex; r--) { |
| 66 | Grid.removeRow(editor, grid[1], r) |
| 67 | } |
| 68 | } |
| 69 | // 重新设置 anchor |
| 70 | const nextPath = rowIndex === 0 ? grid[1] : Path.next(grid[1]) |
| 71 | const { selection } = editor |
| 72 | if (selection) { |
| 73 | Transforms.select(editor, { |
| 74 | ...selection, |
| 75 | anchor: Editor.start(editor, { |
| 76 | path: nextPath, |
| 77 | offset: 0, |
| 78 | }), |
| 79 | }) |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | return true |
| 84 | } |
no test coverage detected
searching dependent graphs…