Skip to content

Commit

Permalink
fix(copy-to-clipboard): refactor clipboard function and use vscode API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiszamanidis committed Aug 29, 2023
1 parent 4cffda9 commit 9bbce6a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- [BrianKmdy](https://github.com/BrianKmdy)
- [tomoum](https://github.com/tomoum)
- [grooc](https://github.com/grooc)
- [jackiotyu](https://github.com/jackiotyu)
5 changes: 2 additions & 3 deletions src/git/operations/worktree/gitWorktreeAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ const gitWorktreeAdd = async (): Promise<void> => {
}
} catch (e: any) {
const errorMessage = e.message;
const buttonName = "Open an Issue";
// const buttonName = "Copy Error and Open an Issue";
const buttonName = "Copy Error and Open an Issue";
const answer = await showErrorMessageWithButton({ errorMessage, buttonName });

if (answer !== buttonName) return;

// await copyToClipboard(errorMessage);
await copyToClipboard(errorMessage);
await openBrowser(OPEN_ISSUE_URL);
}
};
Expand Down
5 changes: 2 additions & 3 deletions src/git/operations/worktree/gitWorktreeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ const gitWorktreeList = async (): Promise<void> => {
await moveIntoWorktree(workspaceFolder, worktree.detail);
} catch (e: any) {
const errorMessage = e.message;
const buttonName = "Open an Issue";
// const buttonName = "Copy Error and Open an Issue";
const buttonName = "Copy Error and Open an Issue";
const answer = await showErrorMessageWithButton({ errorMessage, buttonName });

if (answer !== buttonName) return;

// await copyToClipboard(errorMessage);
await copyToClipboard(errorMessage);
await openBrowser(OPEN_ISSUE_URL);
}
};
Expand Down
5 changes: 2 additions & 3 deletions src/git/operations/worktree/gitWorktreeRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ const gitWorktreeRemove = async (): Promise<void> => {
await showInformationMessage(`Worktree named '${worktree.label}' was removed successfully`);
} catch (e: any) {
const errorMessage = e.message;
const buttonName = "Open an Issue";
// const buttonName = "Copy Error and Open an Issue";
const buttonName = "Copy Error and Open an Issue";
const answer = await showErrorMessageWithButton({ errorMessage, buttonName });

if (answer !== buttonName) return;

// await copyToClipboard(errorMessage);
await copyToClipboard(errorMessage);
await openBrowser(OPEN_ISSUE_URL);
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export const getCurrentPath = () => vscode.workspace.rootPath;

export const getWorkspaceFilePath = () => vscode.workspace.workspaceFile;

// TODO: fix this function
export const copyToClipboard = async (content = "") =>
await require("child_process").spawn("clip").stdin.end(util.inspect(content));
await vscode.env.clipboard.writeText(util.inspect(content));

const calculateBrowserStart = async () => {
let start = "xdg-open";
Expand Down

1 comment on commit 9bbce6a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 81%
88.23% (15/17) 100% (0/0) 80% (4/5)

Please sign in to comment.