import type { Command } from '@blockeditor/block-std';

export const selectBlock: Command<'focusBlock'> = (ctx, next) => {
  const { focusBlock, std } = ctx;
  if (!focusBlock) {
    return;
  }

  const { selection } = std;

  selection.setGroup('note', [
    selection.create('block', { path: focusBlock.path }),
  ]);

  return next();
};

declare global {
  namespace BlockEditor {
    interface Commands {
      selectBlock: typeof selectBlock;
    }
  }
}
