logseq
logseq copied to clipboard
WIP Fix block selection logic
This fixes a few issues:
- Fixes #5870 Moving up/down while multiple blocks are selected now selects the one block up/down from the last block that was added to the selection (or the first/last block if you hit the top/bottom of the list). This mirrors the behavior of Finder, which I find nice and intuitive. Previous behavior was that it would just jump to the top/bottom of the list.
- (mentioned here) If you press up/down after indenting a block, it now moves the selection correctly. The old behavior was that it would jump to the beginning/end of the list, because the new block has a different DOM reference than before it was indented.
To accomplish this, I reworked many of the selection functions to use the HTML id attribute as the identifier for comparison between blocks (eg for indexOf in a list of blocks), instead of a DOM element reference. DOM element references can become invalid if React renders since the last one was saved, so this new approach should be much more reliable.
There are some other places that might also be updated in this fashion, but they weren't directly related to the changes I was making.
Still WIP because I have a few TODOs left in the code, and it's late.
💟
@phoenixeliot Hi. We're closing this as it's been WIP for awhile. We appreciate the fix and can reopen when it's ready for review. If possible, feel free to make a smaller change so we can deliver fixes incrementally