Sign In Sign Up

Optimize SplitTree encoding with custom Codable

mitchellh ยท
2mo ago
+54 -4 ~4
Unlisted
See the bug in @bug.txt . This is caused by SplitTree (@macos/Sources/Features/Splits/SplitTree.swift ) encoding the full node for `zoomed`. We should change this to encode the path instead `root.path(to: zoomed)`. Let's do this by implementing a custom Codable for SplitTree.

Let me understand the bug first:

  1. The bug is that when a split is zoomed and window-save-state is enabled, the zoomed split gets "forever stuck" and can't be unzoomed, closed, or split further.

  2. The root cause mentioned is that SplitTree is encoding the full node for zoomed instead of encoding the path to the zoomed node.

  3. The solution is to implement a custom Codable for SplitTree that encodes/decodes the path to the zoomed node instead of the full node.

Let me look at the current SplitTree implementation to understand how it works:

Looking at SplitTree.swift:

  • It has root: Node? and zoomed: Node?
  • It implements Codable automatically (struct SplitTree<ViewType: NSView & Codable>: Codable)
  • There's already a Path struct and root.path(to: node) method available

The plan:

  1. First, let me check the current TODO list
  2. Plan this task using todo_write
  3. Look more closely at the SplitTree code to understand the current structure
  4. Implement custom Codable for SplitTree that:
    • For encoding: stores the path to zoomed node instead of the full node
    • For decoding: reconstructs the zoomed node from the path
  5. Test the build to make sure it compiles

Let me start by checking if there are existing TODOs, then plan this task.

I'll fix this bug by implementing custom Codable for SplitTree that stores the path to the zoomed node instead of the full node.

Read TODOs
Updated TODOs
Updated TODOs

Now I need to look at the Path struct and make sure it's Codable, and check what methods are available for path-to-node resolution.

I need to see if Path is Codable and check the Component enum:

I see that Path and Path.Component are not currently Codable. I need to make them Codable first, then implement the custom Codable for SplitTree.

Updated TODOs