diff --git a/CHANGELOG.md b/CHANGELOG.md index 748aa0e..646c8e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Released] +## [0.5.1] + +### Added + +- Context menu support to remove highlights. You can now remove highlights by right-clicking on them. Additionally, you can remove all highlights by right-clicking the editor tab. + ## [0.5.0] ### Rewrite diff --git a/package.json b/package.json index b5190d5..b32835a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "twitch-highlighter", "displayName": "Twitch Highlighter", "description": "Allow your Twitch viewers to help in spotting bugs, typos, etc. by sending a command in chat that will highlight the line of code they want you to check.", - "version": "0.5.0", + "version": "0.6.0", "preview": true, "publisher": "clarkio", "engines": { @@ -84,6 +84,11 @@ "command": "twitchHighlighter.disconnect", "title": "Stop Listening to Chat", "category": "Twitch Highlighter" + }, + { + "command": "twitchHighlighter.context.unhighlight", + "title": "Remove Highlight", + "category": "Twitch Highlighter" } ], "menus": { @@ -111,6 +116,10 @@ { "command": "twitchHighlighter.requestUnhighlightAll", "when": "false" + }, + { + "command": "twitchHighlighter.context.unhighlight", + "when": "false" } ], "view/title": [ @@ -126,6 +135,20 @@ "when": "view == twitchHighlighterTreeView || view == twitchHighlighterTreeView-explorer || view == twitchHighlighterTreeView-debug", "group": "edit" } + ], + "editor/context": [ + { + "command": "twitchHighlighter.context.unhighlight", + "group": "1_modification", + "when": "editorHasHighlights" + } + ], + "editor/title/context": [ + { + "command": "twitchHighlighter.unhighlightAll", + "group": "3_open", + "when": "editorHasHighlights" + } ] }, "viewsContainers": { diff --git a/src/app.ts b/src/app.ts index a95d55c..7dbb0ae 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; import { HighlighterAPI, IHighlightRequested, IUnhighlightRequested, IUnhighlightAllRequested } from './api'; -import { Commands, LogLevel, Configuration, Settings } from './enums'; +import { Commands, LogLevel, Configuration, Settings, AppContexts } from './enums'; import { Logger, log } from './logger'; import { HighlightManager, @@ -56,7 +56,9 @@ export class App implements vscode.Disposable { vscode.commands.registerCommand(Commands.requestHighlight, this.requestHighlightHandler, this), vscode.commands.registerCommand(Commands.requestUnhighlight, this.requestUnhighlightHandler, this), - vscode.commands.registerCommand(Commands.requestUnhighlightAll, this.requestUnhighlightAllHandler, this) + vscode.commands.registerCommand(Commands.requestUnhighlightAll, this.requestUnhighlightAllHandler, this), + + vscode.commands.registerCommand(Commands.contextMenuUnhighlight, this.contextMenuUnhighlightHandler, this) ); this.log('Initialized line highlighter.'); @@ -126,6 +128,23 @@ export class App implements vscode.Disposable { } } + /** + * Sets the 'editorHasHighlights' to true or false. + * The 'editorHasHighlights' context is used to determine if the + * 'Remove Highlight' and 'Remove All Highlights' context menu items + * are visible or not. + */ + private setEditorHasHighlightsContext() { + if (vscode.window.activeTextEditor) { + const editor = vscode.window.activeTextEditor; + if (this._highlightManager.GetDecorations(editor.document.fileName).length > 0) { + vscode.commands.executeCommand('setContext', AppContexts.editorHasHighlights, true); + } else { + vscode.commands.executeCommand('setContext', AppContexts.editorHasHighlights, false); + } + } + } + private onDidChangeActiveTextEditorHandler(editor?: vscode.TextEditor): void { if (editor) { this.currentDocument = editor.document; @@ -133,6 +152,7 @@ export class App implements vscode.Disposable { else { this.currentDocument = undefined; } + this.setEditorHasHighlightsContext(); } private refreshTreeviewHandler(): void { @@ -154,6 +174,7 @@ export class App implements vscode.Disposable { } private refresh(): void { + this.setEditorHasHighlightsContext(); vscode.window.visibleTextEditors.forEach(te => { te.setDecorations( this.highlightDecorationType, @@ -293,4 +314,11 @@ export class App implements vscode.Disposable { this._highlightManager.Clear(service); this._onUnhighlightAllRequested.fire({service, callerId}); } + + private contextMenuUnhighlightHandler() { + if (vscode.window.activeTextEditor) { + const lineNumber = vscode.window.activeTextEditor.selection.active.line; + this._highlightManager.Remove(vscode.window.activeTextEditor.document, 'self', lineNumber + 1); + } + } } diff --git a/src/enums/AppContexts.ts b/src/enums/AppContexts.ts new file mode 100644 index 0000000..a35aa12 --- /dev/null +++ b/src/enums/AppContexts.ts @@ -0,0 +1,3 @@ +export enum AppContexts { + 'editorHasHighlights' = 'editorHasHighlights' +} diff --git a/src/enums/Commands.ts b/src/enums/Commands.ts index 2068da7..3086e15 100644 --- a/src/enums/Commands.ts +++ b/src/enums/Commands.ts @@ -34,5 +34,6 @@ export enum Commands { 'signIn' = 'twitchHighlighter.signIn', 'signOut' = 'twitchHighlighter.signOut', 'connect' = 'twitchHighlighter.connect', - 'disconnect' = 'twitchHighlighter.disconnect' + 'disconnect' = 'twitchHighlighter.disconnect', + 'contextMenuUnhighlight' = 'twitchHighlighter.context.unhighlight' } diff --git a/src/enums/index.ts b/src/enums/index.ts index 2549174..6a37004 100644 --- a/src/enums/index.ts +++ b/src/enums/index.ts @@ -5,3 +5,4 @@ export * from './LogLevel'; export * from './Configuration'; export * from './KeytarKeys'; export * from './TwitchKeys'; +export * from './AppContexts'; diff --git a/src/extension.ts b/src/extension.ts index aa23e28..2469491 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -39,3 +39,7 @@ export function deactivate() { ttvchat.dispose(); liveshare.dispose(); } + +export const editorHasDecorations = () => { + return true; +} diff --git a/types/app.d.ts b/types/app.d.ts index 3977ce4..c9d2d22 100644 --- a/types/app.d.ts +++ b/types/app.d.ts @@ -17,6 +17,13 @@ export declare class App implements vscode.Disposable { private onDidChangeTextDocumentHandler; private onDidChangeConfigurationHandler; private onDidChangeVisibleTextEditorsHandler; + /** + * Sets the 'editorHasHighlights' to true or false. + * The 'editorHasHighlights' context is used to determine if the + * 'Remove Highlight' and 'Remove All Highlights' context menu items + * are visible or not. + */ + private setEditorHasHighlightsContext; private onDidChangeActiveTextEditorHandler; private refreshTreeviewHandler; private createTextEditorDecorationType; @@ -31,4 +38,5 @@ export declare class App implements vscode.Disposable { private requestHighlightHandler; private requestUnhighlightHandler; private requestUnhighlightAllHandler; + private contextMenuUnhighlightHandler; } diff --git a/types/enums/Commands.d.ts b/types/enums/Commands.d.ts index f64ea0c..04055eb 100644 --- a/types/enums/Commands.d.ts +++ b/types/enums/Commands.d.ts @@ -11,5 +11,6 @@ export declare enum Commands { 'signIn' = "twitchHighlighter.signIn", 'signOut' = "twitchHighlighter.signOut", 'connect' = "twitchHighlighter.connect", - 'disconnect' = "twitchHighlighter.disconnect" + 'disconnect' = "twitchHighlighter.disconnect", + 'contextMenuUnhighlight' = "twitchHighlighter.context.unhighlight" } diff --git a/types/enums/index.d.ts b/types/enums/index.d.ts index 2549174..6a37004 100644 --- a/types/enums/index.d.ts +++ b/types/enums/index.d.ts @@ -5,3 +5,4 @@ export * from './LogLevel'; export * from './Configuration'; export * from './KeytarKeys'; export * from './TwitchKeys'; +export * from './AppContexts'; diff --git a/types/extension.d.ts b/types/extension.d.ts index afd4c4a..9a82ffc 100644 --- a/types/extension.d.ts +++ b/types/extension.d.ts @@ -1,3 +1,4 @@ import * as vscode from 'vscode'; export declare function activate(context: vscode.ExtensionContext): import("./api").HighlighterAPI; export declare function deactivate(): void; +export declare const editorHasDecorations: () => boolean;