Bottom-up Editing In Tree Structures
I'm going to show how to make constrained tree structure editing to feel as if editing a flat sequence of cells. This is something I had to figure out for textended.
To derive the operations, I had to first figure out editing for a flat sequence of cells. To figure it out I actually implemented a flat document model and set of editing operations to modify it. Such editor can be composed from four primitive operations which I named by their function:
- Collapse takes a list of cells and replaces them with a blank cell. Without the blank cell we would have to ask where the cursor goes after the action.
- Join left/right takes the current cell and joins it with an adjacent left/right cell.
- Put inserts a text or list of cells into a given position.
- Split left/right splits the current cell to left or right direction.
In a flat document model Collapse-Put and Join-Split are symmetric operations. The editing remains fairly similar to editing in a plaintext editor. The same set of operations can be implemented in a tree structure. In summary, reasonable amount of structures are destroyed so the exact same operations can be done without violating constraints. To minimize damage the operations are allowed to wrap tokens into 'placeholder' structures.
- Collapse breaks open the structure through "fault lines". If the structure doesn't resize, it'll be wrapped. If the resulting flatter structure isn't allowed inside the structure, it'll be wrapped to denote that it is incorrect.
- Join either removes or dissolves and wraps the containing cell to get the cell that ends up being joined without having to create an empty cell.
- Split searches for location that would allow insertion of the structure. If such location is not found, it dissolves and wraps the largest structure before inserting itself in.
- Put first attempts to just insert the new data. If it violates constraints, then it attempts to insert the data with a wrapping. If it still violates constraints, then it dissolves and wraps the containing structure.
I have implemented some of the behavior into the editor, and found it promising this far. More accurate description of implementation can be eventually found in the specification of the editor.