| 1 | import * as vscode from "vscode"; |
| 2 | import { output } from "./output"; |
| 3 | import { editorsContainRegexFile } from "./utils"; |
| 4 | import { regexButtons } from "./regexButtons"; |
| 5 | import { highlighter } from "./highlighter"; |
| 6 | import decorationSelector from "./decorationSelector"; |
| 7 | |
| 8 | export function activate(context: vscode.ExtensionContext) { |
| 9 | output.activate(); |
| 10 | regexButtons.activate(context); |
| 11 | highlighter.activate(context); |
| 12 | |
| 13 | if (editorsContainRegexFile()) { |
| 14 | highlighter.run(); |
| 15 | regexButtons.show(); |
| 16 | } |
| 17 | |
| 18 | const activeEditorListener = vscode.window.onDidChangeActiveTextEditor( |
| 19 | (editor) => { |
| 20 | if (editor && editor.document.uri.scheme === "file") { |
| 21 | if (editorsContainRegexFile()) { |
| 22 | highlighter.run(); |
| 23 | regexButtons.show(); |
| 24 | } else { |
| 25 | highlighter.reset(); |
| 26 | regexButtons.hide(); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | ); |
| 31 | |
| 32 | const textDocumentListener = vscode.workspace.onDidChangeTextDocument( |
| 33 | (event) => { |
| 34 | if (editorsContainRegexFile() && event.document.uri.scheme === "file") { |
| 35 | highlighter.run(); |
| 36 | } |
| 37 | } |
| 38 | ); |
| 39 | |
| 40 | context.subscriptions.push(activeEditorListener, textDocumentListener); |
| 41 | } |
| 42 | |
| 43 | export function deactivate() { |
| 44 | decorationSelector.dispose(); |
| 45 | highlighter.dispose(); |
| 46 | |
| 47 | regexButtons.dispose(); |
| 48 | |
| 49 | output.dispose(); |
| 50 | |
| 51 | } |