Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The downside is if you select & delete two functions, and I concurrently insert a new function in the middle of that range, then the merged result will delete my function.

If the document has a syntax tree format, you would get the right thing if you require that range operations are broken into subranges correspond to subtrees.

Let me work this out where I imagine range operations occur as the insertion of a pair of special characters [range-delete-start] and [range-delete-end], so then we can understand results in terms of merging insertions.

Following your example, if the original is:

  f(x) { ... }
  g(x) { ... }
I delete this whole block; broken into subtree operations that becomes

  [range-delete-start]
  f(x) { ... }
  [range-delete-end]
  [range-delete-start]
  g(x) { ... }
  [range-delete-end]
You simultaneously insert a function:

  f(x) { ... }
  [insert-start]
  h(x) { ... }
  [insert-end]
  g(x) { ... }
CRDT rules for the merge are that when an insert operation occurs at the same location the start or end of a range delete the insert is merged to occur outside of the deletion range: the insert range should be placed after an identically-located [range-delete-end] and before an identically-located [range-delete-start]. Then the merged edit is :

  [range-delete-start]
  f(x) { ... }
  [range-delete-end]
  [insert-start]
  h(x) { ... }
  [insert-end]
  [range-delete-start]
  g(x) { ... }
  [range-delete-end]
which simplifies to a result of:

  h(x) { ... }


If you're operating at the AST level, you don't need range deletes to make the merge result work. In my head I'm imagining a document (at the top level) being a list of functions. Deleting two functions is expressed as deleting the AST node for the function definitions from that list. You don't need a range delete operator to do that - you just delete both function subtrees explicitly.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: