Auto-collapse on DONE

Is there a way to auto-collapse a block when it’s marked DONE?

2 Likes
  • Is this about saving just one click?
  • Is collapsing necessary or is hiding children enough?
  • Should old tasks become collapsed as well or only what is DONE from now on?

Sorry for the delay.

  • Is this about saving just one click?

Yes, when using keyboard it saves Ctrl + ArrowUp

  • Is collapsing necessary or is hiding children enough?

What is “hiding children”, sorry? If you mean recursive or not, then no, recursive nested blocks should not react.

  • Should old tasks become collapsed as well or only what is DONE from now on?

Why old tasks? I mean only the current one, that you’re DONE-ing.

Try adding the following code in file custom.js :

document.addEventListener("keyup", (e)=>{
    if (e.code === "Enter" && e.ctrlKey) {
        const block = logseq.api.get_current_block()
        if (block.marker === "DONE") logseq.api.set_block_collapsed(block.uuid, true)
    }
});
2 Likes

I guess it needs to be modified to work.

Currently it works only when you leave the DONE state, not when you enter it.

In other words this snippet collapses the block when you transition from DONE to the no-marker state.
One obvious quick-fix would be to replace DONE with DOING. But it doesn’t look quite right now :slight_smile:

document.addEventListener("keyup", (e) => {
  if (e.code === "Enter" && e.ctrlKey) {
    const block = logseq.api.get_current_block();
    if (block.marker === "DOING") 
      logseq.api.set_block_collapsed(block.uuid, true);
  }
});
  • To me it works when I enter the DONE state.
  • Sounds like in your system the code runs before the block gets updated.
    • Could add some delay, though your quick-fix is simpler.

That the outcome is different for our setups looks really odd.
I’ll experiment with delays, thanks!