diff options
Diffstat (limited to 'users/Profpatsch/lyric')
-rw-r--r-- | users/Profpatsch/lyric/extension/src/extension.ts | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/users/Profpatsch/lyric/extension/src/extension.ts b/users/Profpatsch/lyric/extension/src/extension.ts index 4f46e0a1ed7c..f1c2310228c4 100644 --- a/users/Profpatsch/lyric/extension/src/extension.ts +++ b/users/Profpatsch/lyric/extension/src/extension.ts @@ -4,45 +4,47 @@ import * as net from 'net'; export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(...registerCheckLineTimestamp(context)); context.subscriptions.push( - vscode.commands.registerCommand('extension.jumpToLrcPosition', () => { - const editor = vscode.window.activeTextEditor; + vscode.commands.registerCommand('extension.jumpToLrcPosition', jumpToLrcPosition), + ); +} - if (!editor) { - vscode.window.showInformationMessage('No active editor found.'); - return; - } +function jumpToLrcPosition() { + const editor = vscode.window.activeTextEditor; - const ext = new Ext(editor); - const position = editor.selection.active; - const res = ext.getTimestampFromLine(position); + if (!editor) { + vscode.window.showInformationMessage('No active editor found.'); + return; + } - if (!res) { - return; - } - const { milliseconds, seconds } = res; - - // Prepare JSON command to send to the socket - const jsonCommand = { - command: ['seek', seconds, 'absolute'], - }; - - const socket = new net.Socket(); - - const socketPath = process.env.HOME + '/tmp/mpv-socket'; - socket.connect(socketPath, () => { - socket.write(JSON.stringify(jsonCommand)); - socket.write('\n'); - vscode.window.showInformationMessage( - `Sent command to jump to [${formatTimestamp(milliseconds)}].`, - ); - socket.end(); - }); - - socket.on('error', err => { - vscode.window.showErrorMessage(`Failed to send command: ${err.message}`); - }); - }), - ); + const ext = new Ext(editor); + const position = editor.selection.active; + const res = ext.getTimestampFromLine(position); + + if (!res) { + return; + } + const { milliseconds, seconds } = res; + + // Prepare JSON command to send to the socket + const jsonCommand = { + command: ['seek', seconds, 'absolute'], + }; + + const socket = new net.Socket(); + + const socketPath = process.env.HOME + '/tmp/mpv-socket'; + socket.connect(socketPath, () => { + socket.write(JSON.stringify(jsonCommand)); + socket.write('\n'); + vscode.window.showInformationMessage( + `Sent command to jump to [${formatTimestamp(milliseconds)}].`, + ); + socket.end(); + }); + + socket.on('error', err => { + vscode.window.showErrorMessage(`Failed to send command: ${err.message}`); + }); } // If the difference to the timestamp on the next line is larger than 10 seconds, underline the next line and show a warning message on hover |