Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit 1e91236

Browse files
committed
✨ highlight multiple lines
1 parent b12370e commit 1e91236

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

extension.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ const decoration = vscode.window.createTextEditorDecorationType({
1313

1414
let removeHighlightTimeout = false;
1515

16-
const highlight = lineNumber => {
16+
const highlight = (fromLine, toLine) => {
1717
const range = new vscode.Range(
18-
new vscode.Position(lineNumber, lineNumber),
19-
new vscode.Position(lineNumber, lineNumber))
18+
new vscode.Position(fromLine, 0),
19+
new vscode.Position(toLine, 0));
2020
const editor = vscode.window.activeTextEditor;
2121

2222
clearTimeout(removeHighlightTimeout);
2323
editor.setDecorations(decoration, [range]);
24-
removeHighlightTimeout = setTimeout(() =>
25-
editor.setDecorations(decoration, []),
24+
removeHighlightTimeout = setTimeout(
25+
() => editor.setDecorations(decoration, []),
2626
10000);
2727
};
2828

@@ -49,17 +49,20 @@ twitch.on('message', (channel, tags, message, self) => {
4949
}
5050

5151
try {
52-
const matches = /^(\d+)(.*)$/.exec(message.trim());
53-
const lineNumber = parseInt(matches[1]);
54-
let text = matches[2].trim();
52+
const matches = /^(\d+)([-,: ]\d+)?(.*)$/.exec(message.trim());
53+
const fromLine = parseInt(matches[1]);
54+
const toLine = (matches[2] && parseInt(matches[2].substring(1)))
55+
|| fromLine;
5556

56-
if (lineNumber <= 0) return;
57+
if (fromLine <= 0 || toLine < fromLine) return;
58+
59+
let text = matches[3].trim();
5760

5861
if (text.length === 0) text = 'No message';
5962

6063
vscode.window.showInformationMessage(
61-
`${tags['display-name']} is highlighting line ${lineNumber}: ${text}`)
62-
highlight(lineNumber - 1);
64+
`${tags['display-name']} is highlighting lines ${fromLine}-${toLine}: ${text}`)
65+
highlight(fromLine - 1, toLine - 1);
6366
}
6467
catch (err) {
6568
vscode.window.showErrorMessage(err);

0 commit comments

Comments
 (0)