Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for showing history in a preview window to better search for … #260

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"dark": "resources/dark/remove.svg",
"light": "resources/light/remove.svg"
}
},
{
"command": "clipboard-manager.history.show-buffer",
"title": "Show History in Buffer",
"category": "Clipboard Manager"
}
],
"menus": {
Expand Down
1 change: 1 addition & 0 deletions src/commads/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum commandList {
removeClipboardHistory = "clipboard-manager.history.remove",
setClipboardValue = "clipboard-manager.setClipboardValue",
showClipboardInFile = "clipboard-manager.editor.showClipboardInFile",
showClipboardHistory = "clipboard-manager.history.show-buffer",
}
57 changes: 57 additions & 0 deletions src/commads/showClipboardHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as vscode from "vscode";
import { ClipboardManager, IClipboardItem } from "../manager";
import { commandList } from "./common";
export class ClipboardHistoryProvider
implements vscode.TextDocumentContentProvider
{
constructor(protected _manager: ClipboardManager) {}

protected createClipsString(clips: IClipboardItem[]): string {
return clips
.map(clip => {
const createdAt = new Date(clip.createdAt).toLocaleString();
const language = clip.language ? `${clip.language}` : "";
const statusLine = `${createdAt} - ${language} - ${clip.createdLocation?.uri.toString()}`;
const clipText = clip.value.trim();
const dashLine = "-".repeat(statusLine.length);
return `${statusLine}\n${dashLine}\n${clipText}`;
})
.join("\n\n");
}

public provideTextDocumentContent(_uri: vscode.Uri): string {
return this.createClipsString(this._manager.clips);
}
}

export class ShowClipboardHistory implements vscode.Disposable {
private _disposable: vscode.Disposable[] = [];

constructor(protected _manager: ClipboardManager) {
this._disposable.push(
vscode.commands.registerCommand(
commandList.showClipboardHistory,
this.execute,
this
)
);
}

protected async execute() {
const timestamp = Date.now();
const uri = vscode.Uri.parse(
`clipboard-history://history/clipboard-buffer.txt?${timestamp}`
);

const document = await vscode.workspace.openTextDocument(uri);

await vscode.window.showTextDocument(document, {
preview: true,
viewColumn: vscode.ViewColumn.Active,
});
}

public dispose() {
this._disposable.forEach(d => d.dispose());
}
}
13 changes: 13 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { ClipboardManager } from "./manager";
import { Monitor } from "./monitor";
import { ClipboardTreeDataProvider } from "./tree/history";
import { CopyToHistoryCommand } from "./commads/copyToHistory";
import {
ShowClipboardHistory,
ClipboardHistoryProvider,
} from "./commads/showClipboardHistory";

let manager: ClipboardManager;

Expand Down Expand Up @@ -60,6 +64,7 @@ export async function activate(context: vscode.ExtensionContext) {
disposable.push(new ShowClipboardInFile(manager));
disposable.push(new ClearClipboardHistory(manager));
disposable.push(new CopyToHistoryCommand(monitor));
disposable.push(new ShowClipboardHistory(manager));

const completion = new ClipboardCompletion(manager);
// disposable.push(completion);
Expand Down Expand Up @@ -87,6 +92,14 @@ export async function activate(context: vscode.ExtensionContext) {
const clipboardTreeDataProvider = new ClipboardTreeDataProvider(manager);
disposable.push(clipboardTreeDataProvider);

const clipboardHistoryProvider = new ClipboardHistoryProvider(manager);
disposable.push(
vscode.workspace.registerTextDocumentContentProvider(
"clipboard-history",
clipboardHistoryProvider
)
);

disposable.push(
vscode.window.registerTreeDataProvider(
"clipboardHistory",
Expand Down
41 changes: 41 additions & 0 deletions src/test/showClipboardHistory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as assert from "assert";
import * as sinon from "sinon";
import * as vscode from "vscode";
import { ClipboardManager } from "../manager";
import { ShowClipboardHistory } from "../commads/showClipboardHistory";
import { activateExtension, getExtension } from "./common";

suite("Show Clipboard History Tests", function () {
let sandbox: sinon.SinonSandbox;
let clipboardManager: ClipboardManager | undefined;
let showClipboardHistory: ShowClipboardHistory;

suiteSetup(async function () {
if (!(await activateExtension())) {
this.skip();
}
});

setup(function () {
sandbox = sinon.createSandbox();
clipboardManager = getExtension()?.exports.manager;
if(clipboardManager) {

Check failure on line 22 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Insert `·` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Insert `·`","line":22,"column":7,"nodeType":null,"messageId":"insert","endLine":22,"endColumn":7,"fix":{"range":[698,698],"text":" "}}
showClipboardHistory = new ShowClipboardHistory(clipboardManager);

Check failure on line 23 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (VSCode 1.65.0)

command 'clipboard-manager.history.show-buffer' already exists

Check failure on line 23 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (VSCode stable)

command 'clipboard-manager.history.show-buffer' already exists

Check failure on line 23 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (VSCode insiders)

command 'clipboard-manager.history.show-buffer' already exists

Check failure on line 23 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / macos (VSCode 1.65.0)

command 'clipboard-manager.history.show-buffer' already exists

Check failure on line 23 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / windows (VSCode 1.65.0)

command 'clipboard-manager.history.show-buffer' already exists
}
});

teardown(function () {
sandbox.restore();
showClipboardHistory.dispose();

Check failure on line 29 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (VSCode 1.65.0)

Cannot read property 'dispose' of undefined

Check failure on line 29 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (VSCode stable)

Cannot read properties of undefined (reading 'dispose')

Check failure on line 29 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / ubuntu (VSCode insiders)

Cannot read properties of undefined (reading 'dispose')

Check failure on line 29 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / macos (VSCode 1.65.0)

Cannot read property 'dispose' of undefined

Check failure on line 29 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / windows (VSCode 1.65.0)

Cannot read property 'dispose' of undefined
});

test("Show Clipboard History Command Execution", async function () {
const showTextDocumentStub = sandbox.stub(vscode.window, "showTextDocument");

Check failure on line 33 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Replace `vscode.window,·"showTextDocument"` with `⏎······vscode.window,⏎······"showTextDocument"⏎····` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Replace `vscode.window,·\"showTextDocument\"` with `⏎······vscode.window,⏎······\"showTextDocument\"⏎····`","line":33,"column":47,"nodeType":null,"messageId":"replace","endLine":33,"endColumn":80,"fix":{"range":[1013,1046],"text":"\n vscode.window,\n \"showTextDocument\"\n "}}
const openTextDocumentStub = sandbox.stub(vscode.workspace, "openTextDocument");

Check failure on line 34 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Replace `vscode.workspace,·"openTextDocument"` with `⏎······vscode.workspace,⏎······"openTextDocument"⏎····` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Replace `vscode.workspace,·\"openTextDocument\"` with `⏎······vscode.workspace,⏎······\"openTextDocument\"⏎····`","line":34,"column":47,"nodeType":null,"messageId":"replace","endLine":34,"endColumn":83,"fix":{"range":[1095,1131],"text":"\n vscode.workspace,\n \"openTextDocument\"\n "}}

await vscode.commands.executeCommand("clipboard-manager.history.show-buffer");

Check failure on line 36 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Replace `"clipboard-manager.history.show-buffer"` with `⏎······"clipboard-manager.history.show-buffer"⏎····` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Replace `\"clipboard-manager.history.show-buffer\"` with `⏎······\"clipboard-manager.history.show-buffer\"⏎····`","line":36,"column":42,"nodeType":null,"messageId":"replace","endLine":36,"endColumn":81,"fix":{"range":[1176,1215],"text":"\n \"clipboard-manager.history.show-buffer\"\n "}}

assert.ok(openTextDocumentStub.calledOnce, "openTextDocument should be called once");

Check failure on line 38 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Replace `openTextDocumentStub.calledOnce,·"openTextDocument·should·be·called·once"` with `⏎······openTextDocumentStub.calledOnce,⏎······"openTextDocument·should·be·called·once"⏎····` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Replace `openTextDocumentStub.calledOnce,·\"openTextDocument·should·be·called·once\"` with `⏎······openTextDocumentStub.calledOnce,⏎······\"openTextDocument·should·be·called·once\"⏎····`","line":38,"column":15,"nodeType":null,"messageId":"replace","endLine":38,"endColumn":88,"fix":{"range":[1233,1306],"text":"\n openTextDocumentStub.calledOnce,\n \"openTextDocument should be called once\"\n "}}
assert.ok(showTextDocumentStub.calledOnce, "showTextDocument should be called once");

Check failure on line 39 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Replace `showTextDocumentStub.calledOnce,·"showTextDocument·should·be·called·once"` with `⏎······showTextDocumentStub.calledOnce,⏎······"showTextDocument·should·be·called·once"⏎····` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Replace `showTextDocumentStub.calledOnce,·\"showTextDocument·should·be·called·once\"` with `⏎······showTextDocumentStub.calledOnce,⏎······\"showTextDocument·should·be·called·once\"⏎····`","line":39,"column":15,"nodeType":null,"messageId":"replace","endLine":39,"endColumn":88,"fix":{"range":[1323,1396],"text":"\n showTextDocumentStub.calledOnce,\n \"showTextDocument should be called once\"\n "}}
});
});

Check failure on line 41 in src/test/showClipboardHistory.test.ts

View workflow job for this annotation

GitHub Actions / lint

[eslint] reported by reviewdog 🐶 Insert `⏎` Raw Output: {"ruleId":"prettier/prettier","severity":2,"message":"Insert `⏎`","line":41,"column":4,"nodeType":null,"messageId":"insert","endLine":41,"endColumn":4,"fix":{"range":[1408,1408],"text":"\n"}}
Loading