treehousedev / treehouse

https://treehouse.sh
MIT License
154 stars 11 forks source link

lib: insert child on new node keydown #291

Closed ArcaTech closed 1 year ago

ArcaTech commented 1 year ago

Fixes #275

This one is kinda tricky. The ticket says the issue is with pasting into a new node. Here's what I did in my testing:

  1. Copy a node
  2. Open (zoom command) an existing node with no children
  3. Hit Command + K (pick-command command)

The last step fails.

Reason:

Opening a node with no children shows a panel with a NewNode as the body. The NewNode doesn't exist in the workspace yet. The actual node isn't created until a character is entered (oninput). Pressing Command + K doesn't count as oninput, so when the pick-command action is run, it sees that there's no node in context, and as a backup, it tries to set the context to the current path head. After zoom though, the path head isn't on the screen any more, so it crashes since the input control it's expecting isn't on screen.

Proposal:

This PR just creates the node (runs insert-child) any time a key is pressed (onkeydown), not just when an actual character is entered (oninput). Now, as soon as the user tries to Command + K, the actual node will be created, then they can actually paste.

I'm not sure this is how you actually want things to work though, so let me know what you think @progrium @taramk

progrium commented 1 year ago

Simple, elegant. Let's try it!