Skip to content

Commit

Permalink
ergeat jbbae
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Jan 22, 2021
1 parent 3387409 commit 6707eeb
Show file tree
Hide file tree
Showing 37 changed files with 2,123 additions and 1,117 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -100,8 +100,10 @@
"@types/wicg-file-system-access": "^2020.9.1",
"@webcomponents/webcomponentsjs": "^2.5.0",
"clone-deep": "^4.0.1",
"electron-context-menu": "^2.4.0",
"electron-squirrel-startup": "^1.0.0",
"hast-util-to-html": "^7.1.2",
"immer": "^8.0.1",
"lit-element": "^2.4.0",
"lit-html": "^1.3.0",
"mdast-util-compact": "^3.0.0",
Expand Down
36 changes: 36 additions & 0 deletions src/ast/backspace-paragraph.ts
@@ -0,0 +1,36 @@
import {visit, EXIT} from "unist-utils-core"
import * as md from "mdast"
import compact from "mdast-util-compact"

export default function backspaceParagraph(
root: md.Parent,
target: md.Paragraph,
id?: string
): void {
visit(root, target, (node, index, parents) => {
let parent = parents[parents.length - 1]

let previous = parent.children[index - 1]
if (!previous) {
throw new RangeError(
"can't merge backwards when there is nothing behind"
)
}

if (Array.isArray(previous.children)) {
let length = previous.children.length
previous.children.splice(length, 0, ...node.children)
parent.children[index - 1] = compact(previous)
// TODO come back and use merge
if (id) {
let child = previous.children[length - 1]
child.id = id
}
} else {
throw new TypeError("line before somehow has no children?")
}

parent.children.splice(index, 1)
return EXIT
})
}

0 comments on commit 6707eeb

Please sign in to comment.