Skip to content

Commit

Permalink
Merge pull request #67 from YOCOING/feat/copy-whole-file
Browse files Browse the repository at this point in the history
[Feat] copy whole file if there is no selection
  • Loading branch information
givvemee authored Aug 13, 2024
2 parents 9dc4964 + dbc8083 commit 9d6f208
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function activate(context: vscode.ExtensionContext) {

const document = editor.document;
const selection = editor.selection;
const text = document.getText(selection);
// selection이 존재하지 않을 때는 전체 도큐먼트의 텍스트 복사
const text = selection.isEmpty ? document.getText() : document.getText(selection);
const includeFilePath = vscode.workspace
.getConfiguration("YOCO")
.get<boolean>("includeFilePath", false);
Expand Down
29 changes: 29 additions & 0 deletions src/test/utils/extensionWithoutSelection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { after, before } from "mocha";

import * as vscode from "vscode";

suite("Copy whole code if there is no selected part", () => {
before(async () => {
vscode.window.showInformationMessage("Test is running");
await vscode.commands.executeCommand("workbench.action.closeAllEditors");
vscode.window.showInformationMessage("Start testing copy text with file path.");
});

const content = "Extension without Selection Test";

// [test] 복사된 영역이 없을 때는 자동적으로 파일 전체로 인식
test("Copy full text to clipboard with no selection", async () => {
const document = await vscode.workspace.openTextDocument({
content,
language: "javascript",
});
const editor = await vscode.window.showTextDocument(document);

editor.selection = new vscode.Selection(0, 0, 0, 0);
await vscode.commands.executeCommand("YOCO.copyTextWithFilePath");
});

after(() => {
vscode.window.showInformationMessage("Test is done.");
});
});

0 comments on commit 9d6f208

Please sign in to comment.