diff options
author | Profpatsch <mail@profpatsch.de> | 2024-09-29T13·10+0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2024-10-05T13·49+0000 |
commit | fa18fea20e0c67bdebed0e98e333ffee7532ed26 (patch) | |
tree | 199d087565b38a7babace71274aae7cc2c969f6c /users/Profpatsch | |
parent | 02713e054ff33718bb82c326f461b7a903454f92 (diff) |
refactor(users/Profpatsch/lyric/ext): use document directly r/8761
Change-Id: I6869743727d3b16b74c498b4cd60b33c3ed3997d Reviewed-on: https://cl.tvl.fyi/c/depot/+/12549 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch')
-rw-r--r-- | users/Profpatsch/lyric/extension/src/extension.ts | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/users/Profpatsch/lyric/extension/src/extension.ts b/users/Profpatsch/lyric/extension/src/extension.ts index f1c2310228c4..ded2a8ab0d9c 100644 --- a/users/Profpatsch/lyric/extension/src/extension.ts +++ b/users/Profpatsch/lyric/extension/src/extension.ts @@ -16,7 +16,7 @@ function jumpToLrcPosition() { return; } - const ext = new Ext(editor); + const ext = new Ext(editor.document); const position = editor.selection.active; const res = ext.getTimestampFromLine(position); @@ -56,41 +56,40 @@ export function registerCheckLineTimestamp(_context: vscode.ExtensionContext) { vscode.workspace.onDidChangeTextDocument(e => { changesToCheck.add(e.document); if (vscode.window.activeTextEditor?.document === e.document) { - doEditorChecks(vscode.window.activeTextEditor, everSeen, changesToCheck); + doEditorChecks(vscode.window.activeTextEditor.document, everSeen, changesToCheck); } }), vscode.workspace.onDidOpenTextDocument(e => { changesToCheck.add(e); everSeen.add(e); if (vscode.window.activeTextEditor?.document === e) { - doEditorChecks(vscode.window.activeTextEditor, everSeen, changesToCheck); + doEditorChecks(vscode.window.activeTextEditor.document, everSeen, changesToCheck); } }), vscode.window.onDidChangeActiveTextEditor(editor => { if (editor) { - doEditorChecks(editor, everSeen, changesToCheck); + doEditorChecks(editor.document, everSeen, changesToCheck); } }), vscode.window.onDidChangeVisibleTextEditors(editors => { for (const editor of editors) { - doEditorChecks(editor, everSeen, changesToCheck); + doEditorChecks(editor.document, everSeen, changesToCheck); } }), ]; } function doEditorChecks( - editor: vscode.TextEditor, + document: vscode.TextDocument, everSeen: Set<vscode.TextDocument>, changesToCheck: Set<vscode.TextDocument>, ) { - const ext = new Ext(editor); - const document = editor.document; + const ext = new Ext(document); - if (!everSeen.has(editor.document)) { - changesToCheck.add(editor.document); - everSeen.add(editor.document); + if (!everSeen.has(document)) { + changesToCheck.add(document); + everSeen.add(document); } if (!changesToCheck.has(document)) { @@ -152,7 +151,7 @@ function nextLineTimestampSmallerThanCurrent(ext: Ext, line: number): string | u } class Ext { - constructor(public editor: vscode.TextEditor) {} + constructor(public document: vscode.TextDocument) {} getTimeDifferenceToNextLineTimestamp(position: vscode.Position) { const thisLineTimestamp = this.getTimestampFromLine(position); @@ -169,8 +168,7 @@ class Ext { } getTimestampFromLine(position: vscode.Position) { - const document = this.editor.document; - const lineText = document.lineAt(position.line).text; + const lineText = this.document.lineAt(position.line).text; // Extract timestamp [mm:ss.ms] from the current line const match = lineText.match(/\[(\d+:\d+\.\d+)\](.*)/); |