Skip to content

Instantly share code, notes, and snippets.

@parithon
Last active April 11, 2019 02:57
Show Gist options
  • Save parithon/7b165c22e797186e7649378aa3a01351 to your computer and use it in GitHub Desktop.
Save parithon/7b165c22e797186e7649378aa3a01351 to your computer and use it in GitHub Desktop.
Overloaded removeHighlights method to allow us to remove lineNumbers by fileName or all highlights by a username.
--- extension.ts :: line 482 ---
function removeHighlight(username: string): void;
function removeHighlight(lineNumber: number, fileName: string, deferRefresh?: boolean): void;
function removeHighlight(
searchQuery: string | number,
fileName?: string,
deferRefresh?: boolean
) {
// If the searchQuery is a string (username)
if (isNaN(Number(searchQuery))) {
const username = searchQuery as string;
highlighters.forEach(highlighter => highlighter.removeDecorations(username));
}
// the searchQuery is a number (lineNumber)
else {
if (!fileName) { return; } // the fileName should always be truthy, but tslint generates warnings.
const existingHighlight = findHighlighter(fileName);
if (!existingHighlight) {
console.warn(`Highlight not found so can't unhighlight the line from file`);
return;
}
const lineNumber = searchQuery as number;
existingHighlight.removeDecoration(lineNumber);
}
if (!deferRefresh) {
triggerUpdateDecorations();
twitchHighlighterTreeView.refresh();
}
}
--- highlighter.ts :: line 32 ---
removeDecorations(username: string): Highlight[] {
this.highlights = this.highlights.filter(highlight => highlight.twitchUser !== username);
return this.highlights;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment