quarto-dev / quarto-dev/quarto

Add Copy Cell Command to VSCode

Open
#442 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
645
Forks
62
Avg merge
17h 42m
Merged PRs (30d)
13

Description

Currently .qmd in VSCode supports the run cell command, but no way of just copying or cutting a cell.

As I shift around cells and need copy snippets around regularly, the functionality of having a copy cell function is crucial for efficiency. As Quarto already supports the run cell command, it seems feasible to have a more broken down version of this which yanks the cell to the clipboard instead of in the interactive kernel.

Without knowing too much ts, the class could look something like this:

class CopyCurrentCellCommand extends RunCommand implements Command {
  constructor(host: ExtensionHost, engine: MarkdownEngine) {
    super(host, engine);
  }
  private static readonly id = "quarto.copyCurrentCell";
  public readonly id = CopyCurrentCellCommand.id;

  override async doExecute(
    editor: TextEditor,
    _tokens: Token[],
    _line: number,
    block?: Token
  ) {
    if (block && isExecutableLanguageBlock(block)) {
      const code = codeWithoutOptionsFromBlock(block);
      await this.copyToClipboard(code, editor);
    }
  }

  private async copyToClipboard(code: string, editor: TextEditor): Promise<void> {
    try {
      await navigator.clipboard.writeText(code);
      editor.showInformationMessage('Code copied to clipboard!');
    } catch (err) {
      editor.showErrorMessage('Failed to copy code to clipboard.');
    }
  }
}

this would be amazing. Thank you.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing RunCommand used for the VSCode run cell command, including codeWithoutOptionsFromBlock and the proposed CopyCurrentCellCommand entry point. Confirm how executable cells are identified and how commands are registered. Done means the current cell can be copied, and possibly cut as requested, to the clipboard.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.