Composition / foldkit-builder

Text edited in place

A Block's view that draws a text prop with field(key) (see foldkit-composition) can be edited on the canvas, where it shows:

double-click, or Enter ─► EditingAsked ─► editing: { id, key, initial }   the field freezes at `initial`
typing ─► FieldTyped ─► setProp, in the session's one undo step
Enter or leaving it ─► EditingCommitted      Escape ─► EditingCancelled: the step is taken back
  • Each Message names the field as the canvas marks it, and the Builder checks it: text the Renderer does not draw as a field (Renderer.fields), a prop that is not text, or a field other than the one being edited is ignored.
  • One session is one undo step. Beginning ends whatever group came before (History.close), so two sessions of one prop undo apart, and a second ask for the field being edited (a double-click inside it) begins nothing. Escape, or text that ends where it began, takes the step back and leaves nothing to redo (History.revert). Where another edit came between (the inspector, an agent), the step is no longer the last: the text is written back as a step of its own, and a commit writes nothing the page already holds, so no step is empty. A session in which nothing was typed writes nothing when it ends, so a field only looked at does not put back over another's edit the text it showed.
  • While text is edited, the keys are the text's: keyPressed and keyCommand offer nothing, so Backspace deletes a letter, not the block.
  • Editing ends when its node is no longer the one selected, as a click elsewhere or a removal makes it, and at an undo or a redo, which change the page under the field.
  • The canvas freezes the field at initial so a redraw never rewrites the element under the caret; the text is read by foldkit-primitives' EditableText, which foldkit-mixins-builder attaches to the canvas.