()
| 324 | |
| 325 | @action |
| 326 | backspace() { |
| 327 | if (this.isSingleNode()) { |
| 328 | this.deleteSelectedNode() |
| 329 | return |
| 330 | } |
| 331 | |
| 332 | const deleteCursor = this.cursor |
| 333 | // If there's a line cursor start, and the preceeding line is empty, delete that line (can be tree child) |
| 334 | const lineStartCursors = this.cursorMap.getLineStartCursorsForCursorPosition(this.cursor) |
| 335 | |
| 336 | for (const startCursor of lineStartCursors) { |
| 337 | if (!startCursor.listBlock.allowDelete()) { |
| 338 | continue |
| 339 | } |
| 340 | const unindentTarget = startCursor.listBlock.getUnindentTarget(startCursor.index) |
| 341 | if (unindentTarget) { |
| 342 | startCursor.listBlock.childSet.removeChild(startCursor.index) |
| 343 | const newlineNode = getBlankFillForCategory(unindentTarget.listBlock.childSet.nodeCategory) |
| 344 | unindentTarget.listBlock.childSet.insertNode(newlineNode, unindentTarget.index) |
| 345 | return |
| 346 | } |
| 347 | |
| 348 | if (startCursor.index !== 0 && startCursor.listBlock.allowDelete()) { |
| 349 | const prevLine = startCursor.listBlock.nodes[startCursor.index - 1] |
| 350 | if (prevLine.node.isEmpty()) { |
| 351 | startCursor.listBlock.childSet.removeChild(startCursor.index - 1) |
| 352 | return |
| 353 | } |
| 354 | } |
| 355 | if ( |
| 356 | startCursor.index < startCursor.listBlock.nodes.length && |
| 357 | startCursor.listBlock.nodes[startCursor.index].node.isEmpty() && |
| 358 | startCursor.listBlock.allowDelete() |
| 359 | ) { |
| 360 | const [leftCursor, isCursor] = this.cursorMap.getCursorLeftOfPosition(deleteCursor) |
| 361 | startCursor.listBlock.childSet.removeChild(startCursor.index) |
| 362 | this.placeCursorPosition(leftCursor, isCursor, true) |
| 363 | return |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | this.moveCursorLeft() |
| 368 | if (this.isSingleNode()) { |
| 369 | this.deleteSelectedNode() |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | replaceOrWrapSelectedNode(node: SplootNode) { |
| 374 | if (this.isSingleNode()) { |
no test coverage detected