basyura's blog

あしたになったらほんきだす。

inkdrop - active なノートを表示する

複数 book 運用で詳細表示してるときの状態を判定するのに queryContext だと不都合が多かったので sidebar.workspace を使うように改良。

inkdrop.commands.add(document.body, "mycmd:select-active", () => {
  const { sidebar } = inkdrop.store.getState();

  const status = "active";
  const bookId = sidebar.workspace.bookId;
  if (bookId != "") {
    inkdrop.commands.dispatch(
      document.body,
      "core:note-list-show-notes-in-book",
      { bookId, status }
    );
  } else {
    inkdrop.commands.dispatch(
      document.body,
      "core:note-list-show-notes-with-status",
      { status }
    );
  }
  inkdrop.commands.dispatch(document.body, "editor:focus");
});