about summary refs log tree commit diff
path: root/users/Profpatsch
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2024-09-29T12·44+0200
committerProfpatsch <mail@profpatsch.de>2024-10-05T13·49+0000
commit02713e054ff33718bb82c326f461b7a903454f92 (patch)
tree77877afbb28e54cfdaee8d74758ae2189e8e329a /users/Profpatsch
parent9bec21ea1cb9137d8c5dae6ee2cb78aac1b5601a (diff)
refactor(users/Profpatsch/lyric/ext): move command into fn r/8760
Change-Id: I2d38455cdf881e03a390d129f9cee3f9eeca485d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12548
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch')
-rw-r--r--users/Profpatsch/lyric/extension/src/extension.ts74
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