├── src ├── types.d.ts ├── test │ ├── suite │ │ ├── extension.test.ts │ │ └── index.ts │ └── runTest.ts ├── regexecute.ts └── extension.ts ├── .gitignore ├── icon.png ├── click_the_star.png ├── regexworkbench.gif ├── .vscodeignore ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── tslint.json ├── tsconfig.json ├── media ├── js │ ├── strings.js │ ├── jquery-linedtextarea.js │ ├── regexworkbench.js │ └── jquery-3.4.1.min.js └── css │ ├── jquery-linedtextarea.css │ └── regexworkbench.css ├── TODO.md ├── CHANGELOG.md ├── package.json ├── README.md └── vsc-extension-quickstart.md /src/types.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@stephen-riley/pcre2-wasm'; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | tmp/ 6 | .DS_Store -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephen-riley/regexworkbench/HEAD/icon.png -------------------------------------------------------------------------------- /click_the_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephen-riley/regexworkbench/HEAD/click_the_star.png -------------------------------------------------------------------------------- /regexworkbench.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephen-riley/regexworkbench/HEAD/regexworkbench.gif -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | src/** 5 | .gitignore 6 | vsc-extension-quickstart.md 7 | **/tsconfig.json 8 | **/tslint.json 9 | **/*.map 10 | **/*.ts 11 | tmp/** -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "ms-vscode.vscode-typescript-tslint-plugin" 6 | ] 7 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-string-throw": true, 4 | "no-unused-expression": true, 5 | "no-duplicate-variable": true, 6 | "curly": true, 7 | "class-name": true, 8 | "semicolon": [ 9 | true, 10 | "always" 11 | ], 12 | "triple-equals": true 13 | }, 14 | "defaultSeverity": "warning" 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "target": "es6", 6 | "outDir": "out", 7 | "lib": [ 8 | "es6" 9 | ], 10 | "sourceMap": true, 11 | "rootDir": "src", 12 | "strict": true 13 | }, 14 | "exclude": [ 15 | "node_modules", 16 | ".vscode-test" 17 | ] 18 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off" 11 | } -------------------------------------------------------------------------------- /src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.equal(-1, [1, 2, 3].indexOf(5)); 13 | assert.equal(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from 'vscode-test'; 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error('Failed to run tests'); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /media/js/strings.js: -------------------------------------------------------------------------------- 1 | const Tooltips = { 2 | en: { 3 | '#match-btn': null, 4 | '#matchall-btn': null, 5 | '#split-btn': null, 6 | '#replace-btn': null, 7 | '#replaceall-btn': null, 8 | '#regex-section': null, 9 | '#i-switch': 'Case-insensitive pattern matching', 10 | '#m-switch': 'Treat search text as multiple lines (changes "^" and "$")', 11 | '#s-switch': 'Treat search text as a single line ("." matches newlines)', 12 | '#replacement-section': null, 13 | '#search-section': null, 14 | '#replaced-section': null, 15 | '#results-section': 'Match results. Group 0 is entire match; other groups are capture groups.', 16 | '#splitresults': null, 17 | '#folder': 'Open a file to use as search text' 18 | } 19 | }; 20 | 21 | export default Tooltips; -------------------------------------------------------------------------------- /src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as Mocha from 'mocha'; 3 | import * as glob from 'glob'; 4 | 5 | export function run(): Promise { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: 'tdd', 9 | }); 10 | mocha.useColors(true); 11 | 12 | const testsRoot = path.resolve(__dirname, '..'); 13 | 14 | return new Promise((c, e) => { 15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 16 | if (err) { 17 | return e(err); 18 | } 19 | 20 | // Add files to the test suite 21 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 22 | 23 | try { 24 | // Run the mocha test 25 | mocha.run(failures => { 26 | if (failures > 0) { 27 | e(new Error(`${failures} tests failed.`)); 28 | } else { 29 | c(); 30 | } 31 | }); 32 | } catch (err) { 33 | e(err); 34 | } 35 | }); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | - [x] Add status bar button for invocation (0.0.2) 4 | - [x] Store state in vscode `ExtensionContext.storagePath` 5 | - [x] Make a nice tree view instead of just dumping the output JSON (0.0.3) 6 | 7 | ## For 0.1.0 8 | 9 | - [x] Fix leading tabs and spaces when loading a file into search text 10 | - [x] Add tooltips to everything 11 | - [x] Put line numbers on text boxes 12 | 13 | ## For 1.0 14 | 15 | - [x] Rearrange UI to not be so vertical 16 | - [x] Add documentation and gif to README 17 | 18 | ## For 2.0 19 | 20 | - [x] Use PCRE2 for regex execution 21 | - [x] Show named captures in results pane 22 | 23 | ## Nice-to-have 24 | 25 | - [x] Support extended regexes (came with PCRE2) 26 | - [ ] Highlight matched text in search text 27 | - [ ] Highlight matched text in replaced text 28 | - [ ] Add drop-down of regex syntax patterns 29 | - [ ] Add a menu of full examples 30 | - [ ] Allow saving regex search/replace string pairs for later reuse [issue #10](https://github.com/stephen-riley/regexworkbench/issues/10) 31 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "preLaunchTask": "npm: watch" 20 | }, 21 | { 22 | "name": "Extension Tests", 23 | "type": "extensionHost", 24 | "request": "launch", 25 | "runtimeExecutable": "${execPath}", 26 | "args": [ 27 | "--extensionDevelopmentPath=${workspaceFolder}", 28 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "npm: watch" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "regexworkbench" extension will be documented in this file. 4 | 5 | ## [0.0.3](https://github.com/stephen-riley/regexworkbench/releases/tag/0.0.3) - Nov 9, 2019 6 | 7 | - Initial (useful) release. Invoke via the /:star:/ status bar item, or invoke the `Open regular expression workbench` command. 8 | 9 | ## [0.1.0](https://github.com/stephen-riley/regexworkbench/releases/tag/0.1.0) - Nov 26, 2019 10 | 11 | - Added line numbers in editors 12 | - Added tooltips to controls 13 | - Fixed whitespace issues in some editors 14 | 15 | ## [v1.0.0](https://github.com/stephen-riley/regexworkbench/releases/tag/v1.0.0) - Dec 6, 2019 16 | 17 | - Initial public release! 18 | 19 | ## [v1.0.1](https://github.com/stephen-riley/regexworkbench/releases/tag/v1.0.1) - Dec 9, 2019 20 | 21 | - Fixed some border color issues in light themes 22 | - Workbench changes UI as user changes theme in vscode 23 | 24 | ## [v2.0.2](https://github.com/stephen-riley/regexworkbench/releases/tag/v2.0.2) - Jan 14, 2020 25 | 26 | - Now uses PCRE2 for all regex execution (see [stephen-riley/pcre2-wasm](https://github.com/stephen-riley/pcre2-wasm) for how) 27 | - Fully supports named capture groups 28 | - Misc bug fixes 29 | 30 | ## [v2.0.4](https://github.com/stephen-riley/regexworkbench/releases/tag/v2.0.4) 31 | 32 | - Replacements now support `PCRE2_SUBSTITUTE_EXTENDED` syntax (eg. upper- and lower-case conversion 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "regexworkbench", 3 | "displayName": "Regex Workbench", 4 | "description": "A workbench to design, test, and experiment with regular expressions", 5 | "keywords": [ 6 | "regex", 7 | "regexes", 8 | "regexp", 9 | "workbench", 10 | "regular expression" 11 | ], 12 | "icon": "icon.png", 13 | "publisher": "stephen-riley", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/stephen-riley/regexworkbench" 17 | }, 18 | "version": "2.0.5", 19 | "preview": false, 20 | "engines": { 21 | "vscode": "^1.48.0" 22 | }, 23 | "categories": [ 24 | "Other" 25 | ], 26 | "activationEvents": [ 27 | "*", 28 | "onCommand:regexworkbench.start", 29 | "onWebviewPanel:regexworkbench" 30 | ], 31 | "main": "./out/extension.js", 32 | "contributes": { 33 | "commands": [ 34 | { 35 | "command": "regexworkbench.start", 36 | "title": "Open regular expression workbench", 37 | "category": "Regex Workbench" 38 | } 39 | ] 40 | }, 41 | "scripts": { 42 | "vscode:prepublish": "npm run compile", 43 | "compile": "tsc -p ./", 44 | "watch": "tsc -watch -p ./", 45 | "pretest": "npm run compile", 46 | "test": "node ./out/test/runTest.js" 47 | }, 48 | "devDependencies": { 49 | "@types/glob": "^7.1.3", 50 | "@types/mocha": "^5.2.6", 51 | "@types/node": "^10.17.28", 52 | "@types/vscode": "^1.48.0", 53 | "glob": "^7.1.6", 54 | "mocha": "^6.2.3", 55 | "tslint": "^5.20.1", 56 | "typescript": "^3.9.7", 57 | "vscode-test": "^1.4.0" 58 | }, 59 | "dependencies": { 60 | "@stephen-riley/pcre2-wasm": "^1.2.4" 61 | } 62 | } -------------------------------------------------------------------------------- /media/css/jquery-linedtextarea.css: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery Lined Textarea Plugin 3 | * http://alan.blog-city.com/jquerylinedtextarea.htm 4 | * 5 | * Copyright (c) 2010 Alan Williamson 6 | * 7 | * Released under the MIT License: 8 | * http://www.opensource.org/licenses/mit-license.php 9 | * 10 | * Usage: 11 | * Displays a line number count column to the left of the textarea 12 | * 13 | * Class up your textarea with a given class, or target it directly 14 | * with JQuery Selectors 15 | * 16 | * $(".lined").linedtextarea({ 17 | * selectedLine: 10, 18 | * selectedClass: 'lineselect' 19 | * }); 20 | * 21 | */ 22 | 23 | .linedwrap { 24 | border: 1px solid #c0c0c0; 25 | padding: 3px; 26 | } 27 | 28 | .linedtextarea { 29 | padding: 0px; 30 | margin: 0px; 31 | } 32 | 33 | .linedtextarea textarea, .linedwrap .codelines .lineno { 34 | font-size: 10pt; 35 | font-family: monospace; 36 | line-height: 15px !important; 37 | } 38 | 39 | .linedtextarea textarea { 40 | padding-right:0.3em; 41 | padding-top:0.3em; 42 | border: 0; 43 | } 44 | 45 | .linedwrap .lines { 46 | margin-top: 0px; 47 | width: 50px; 48 | float: left; 49 | overflow: hidden; 50 | border-right: 1px solid #c0c0c0; 51 | margin-right: 10px; 52 | } 53 | 54 | .linedwrap .codelines { 55 | padding-top: 5px; 56 | } 57 | 58 | .linedwrap .codelines .lineno { 59 | color:#AAAAAA; 60 | padding-right: 0.5em; 61 | padding-top: 0.0em; 62 | text-align: right; 63 | white-space: nowrap; 64 | } 65 | 66 | .linedwrap .codelines .lineselect { 67 | color: red; 68 | } -------------------------------------------------------------------------------- /src/regexecute.ts: -------------------------------------------------------------------------------- 1 | 2 | import PCRE from '@stephen-riley/pcre2-wasm'; 3 | import * as crypto from 'crypto'; 4 | 5 | 6 | export function match(subject: string, pattern: string, switches: string): any[] { 7 | let re: any; 8 | 9 | try { 10 | re = new PCRE(pattern, switches); 11 | const results: any = re.match(subject); 12 | return [results]; 13 | } catch (e) { 14 | throw e; 15 | } finally { 16 | if (re) { 17 | re.destroy(); 18 | } 19 | } 20 | } 21 | 22 | export function matchAll(subject: string, pattern: string, switches: string): any[] { 23 | let re: any; 24 | 25 | try { 26 | re = new PCRE(pattern, switches); 27 | const results: any = re.matchAll(subject); 28 | return results; 29 | } catch (e) { 30 | throw e; 31 | } finally { 32 | if (re) { 33 | re.destroy(); 34 | } 35 | } 36 | } 37 | 38 | export function split(subject: string, pattern: string, switches: string): any[] { 39 | let re: any; 40 | const id = generateRandomId(); 41 | 42 | try { 43 | re = new PCRE(pattern, switches); 44 | const result: string = re.substituteAll(subject, id); 45 | return result.split(id); 46 | } catch (e) { 47 | throw e; 48 | } finally { 49 | if (re) { 50 | re.destroy(); 51 | } 52 | } 53 | } 54 | 55 | export function replace(subject: string, pattern: string, switches: string, replacement: string): any { 56 | let re: any; 57 | 58 | try { 59 | const matches = match(subject, pattern, switches); 60 | re = new PCRE(pattern, switches); 61 | const result: string = re.substitute(subject, replacement); 62 | return { result, matches: matches }; 63 | } catch (e) { 64 | throw e; 65 | } finally { 66 | if (re) { 67 | re.destroy(); 68 | } 69 | } 70 | } 71 | 72 | export function replaceAll(subject: string, pattern: string, switches: string, replacement: string): any { 73 | let re: any; 74 | 75 | try { 76 | const matches = matchAll(subject, pattern, switches); 77 | re = new PCRE(pattern, switches); 78 | const result: string = re.substituteAll(subject, replacement); 79 | return { result, matches: matches }; 80 | } catch (e) { 81 | throw e; 82 | } finally { 83 | if (re) { 84 | re.destroy(); 85 | } 86 | } 87 | } 88 | 89 | function generateRandomId() { 90 | return `--${crypto.randomBytes(16).toString("hex")}--`; 91 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Preview 2 | 3 | ![demo](regexworkbench.gif) 4 | 5 | Just click the regex star at the bottom right to get started. 6 | 7 | ![click the star](click_the_star.png) 8 | 9 | ## Description 10 | 11 | A regular expression workbench for Visual Studio Code in the style of [Komodo's](https://www.activestate.com/products/komodo-ide/). Just click on the slash-star-slash icon in the lower right. 12 | 13 | Currently supports match, match all, split, replace, and replace all. 14 | 15 | ## How does it work? 16 | 17 | The workbench uses the [PCRE2](https://www.pcre.org/) (Perl Compatible Regular Expressions) library, compiled to WebAssembly. See [@stephen-riley/pcre2-wasm](https://github.com/stephen-riley/pcre2-wasm) for that project. PCRE2 is a significant upgrade compared to the current Javascript RegExp functionality (though [there is hope!](https://v8.dev/features/regexp-match-indices)). 18 | 19 | Some important things to note about PCRE2 as used in this extension: 20 | 21 | * This PCRE2 is compiled with [UTF-16 LE](https://en.wikipedia.org/wiki/UTF-16#Byte_order_encoding_schemes) character units under the hood, so you should have no problem with Unicode characters. 22 | * It does _not_ support Python replacement group references; eg. `"\1 \2"`. You must use `"$1 $2"`. `\1` is still supported as a backreference in regular expression patterns; eg. `((?i)rah)\s+\1`. 23 | * Named capture groups are supported in three syntaxes: `(?...)`, `(?'name'...)`, and `(?P...)`. 24 | * You can use named capture groups in the replacement text with the syntax `${name}`. 25 | 26 | ## Why the delay in loading this extension? 27 | 28 | At the time of writing, the V8 Javascript engine running Visual Studio Code _always_ runs WebAssembly modules through its [TurboFan optimizing compiler](https://v8.dev/blog/launching-ignition-and-turbofan). PCRE2 has some seriously nontrivial logic in it that TurboFan takes 6-7 seconds to process. You will therefore notice a similar delay between launching vscode and seeing the Regular Expression Workbench icon appearing in the lower right. See [this repo](https://github.com/stephen-riley/pcre2-wasm/tree/turbofan-bug-demo) for further information. 29 | 30 | ## Sideloading from a local build 31 | 32 | If you want to run a customized version, here's how to sideload your own build. 33 | 34 | Make sure you have Node.js installed, then run: 35 | 36 | `npm install -g vsce` 37 | 38 | Clone the repo and `cd` into its directory, then run: 39 | 40 | `vsce package` 41 | 42 | `code --install-extension regexworkbench-.vsix` 43 | 44 | (The `version` comes from `package.json`.) 45 | -------------------------------------------------------------------------------- /vsc-extension-quickstart.md: -------------------------------------------------------------------------------- 1 | # Welcome to your VS Code Extension 2 | 3 | ## What's in the folder 4 | 5 | * This folder contains all of the files necessary for your extension. 6 | * `package.json` - this is the manifest file in which you declare your extension and command. 7 | * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. 8 | * `src/extension.ts` - this is the main file where you will provide the implementation of your command. 9 | * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. 10 | * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. 11 | 12 | ## Get up and running straight away 13 | 14 | * Press `F5` to open a new window with your extension loaded. 15 | * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. 16 | * Set breakpoints in your code inside `src/extension.ts` to debug your extension. 17 | * Find output from your extension in the debug console. 18 | 19 | ## Make changes 20 | 21 | * You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. 22 | * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. 23 | 24 | ## Explore the API 25 | 26 | * You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. 27 | 28 | ## Run tests 29 | 30 | * Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. 31 | * Press `F5` to run the tests in a new window with your extension loaded. 32 | * See the output of the test result in the debug console. 33 | * Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder. 34 | * The provided test runner will only consider files matching the name pattern `**.test.ts`. 35 | * You can create folders inside the `test` folder to structure your tests any way you want. 36 | 37 | ## Go further 38 | 39 | * Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). 40 | * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace. 41 | * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). 42 | -------------------------------------------------------------------------------- /media/css/regexworkbench.css: -------------------------------------------------------------------------------- 1 | 2 | :root { 3 | --border-color: #c0c0c0; 4 | } 5 | 6 | body { 7 | font-family: sans-serif; 8 | padding-top: 20px; 9 | } 10 | 11 | textarea { 12 | font-family: var(--vscode-editor-font-family); 13 | background-color: var(--vscode-editor-background); 14 | color: var(--vscode-editor-foreground); 15 | } 16 | 17 | textarea::-webkit-scrollbar { 18 | display: none; 19 | } 20 | 21 | button { 22 | border-radius: 0; 23 | background-color: var(--vscode-editor-background); 24 | color: var(--vscode-editor-foreground); 25 | } 26 | 27 | button.selected.vscode-light { 28 | background-color: var(--vscode-button-background); 29 | color: var(--vscode-button-foreground); 30 | } 31 | 32 | button.selected.vscode-dark { 33 | background-color: var(--vscode-button-background); 34 | color: var(--vscode-button-foreground); 35 | } 36 | 37 | button.selected.vscode-high-contrast { 38 | background-color: var(--vscode-editor-background); 39 | color: var(--vscode-editor-foreground); 40 | outline: 2px solid var(--border-color); 41 | } 42 | 43 | .nl { 44 | display: block; 45 | padding-bottom: 3px; 46 | } 47 | 48 | .ta { 49 | width: 100%; 50 | } 51 | 52 | #container { 53 | display: grid; 54 | grid-template-columns: 58% 42%; 55 | } 56 | 57 | .col1 { 58 | grid-column-start: 1; 59 | grid-column-end: 1; 60 | } 61 | 62 | .col2 { 63 | grid-column-start: 2; 64 | grid-column-end: 2; 65 | } 66 | 67 | .col-all { 68 | grid-column-start: 1; 69 | grid-column-end: 3; 70 | } 71 | 72 | .section-header { 73 | display: block; 74 | } 75 | 76 | .section { 77 | padding-bottom: 15px; 78 | padding-right: 20px; 79 | } 80 | 81 | .selected { 82 | background-color: #c0c0ff; 83 | color: var(--vscode-editor-background); 84 | } 85 | 86 | .switchpanel { 87 | font-family: monospace; 88 | font-weight: bold; 89 | } 90 | 91 | .switch { 92 | border: 1px solid var(--border-color); 93 | } 94 | 95 | .regex-panel table { 96 | width: 100%; 97 | border: none; 98 | } 99 | 100 | #regex { 101 | height: 25vh; 102 | padding: 4px; 103 | white-space: pre; 104 | grid-row: 1; 105 | font-family: var(--vscode-editor-font-family); 106 | font-size: 11px; 107 | } 108 | 109 | #search { 110 | padding: 4px 0 4px 4px; 111 | height: 25vh; 112 | overflow: auto; 113 | font-family: var(--vscode-editor-font-family); 114 | font-size: 11px; 115 | background-color: var(--vscode-editor-background); 116 | color: var(--vscode-editor-foreground); 117 | white-space: pre; 118 | grid-row: 2; 119 | } 120 | 121 | #replacement { 122 | padding: 4px; 123 | height: 25vh; 124 | overflow: auto; 125 | font-family: var(--vscode-editor-font-family); 126 | font-size: 11px; 127 | background-color: var(--vscode-editor-background); 128 | color: var(--vscode-editor-foreground); 129 | white-space: pre; 130 | grid-row: 1; 131 | } 132 | 133 | #replaced { 134 | padding: 4px; 135 | height: 25vh; 136 | overflow: auto; 137 | font-family: var(--vscode-editor-font-family); 138 | font-size: 11px; 139 | background-color: var(--vscode-editor-background); 140 | color: var(--vscode-editor-foreground); 141 | white-space: pre; 142 | grid-row: 2; 143 | } 144 | 145 | #splitresults { 146 | font-family: var(--vscode-editor-font-family); 147 | font-size: 11px; 148 | height: 25vh; 149 | grid-row: 3; 150 | } 151 | 152 | #results { 153 | padding: 4px; 154 | height: 25vh; 155 | font-family: var(--vscode-editor-font-family); 156 | font-size: 11px; 157 | outline: 1px solid var(--border-color); 158 | overflow-y: scroll; 159 | grid-row: 3; 160 | } 161 | 162 | #results::-webkit-scrollbar { 163 | display: none; 164 | } 165 | 166 | #results table { 167 | border-collapse: collapse; 168 | border-spacing: 0; 169 | } 170 | 171 | #results td:first-child { 172 | padding-left: 20px; 173 | } 174 | 175 | #results td.bold { 176 | font-weight: bold; 177 | padding-left: 0px; 178 | text-decoration: underline; 179 | } 180 | 181 | #results th { 182 | font-weight: normal; 183 | color: gray; 184 | text-align: left; 185 | padding-top: 5px; 186 | } 187 | 188 | #splitresults { 189 | height: 150px; 190 | font-family: var(--vscode-editor-font-family); 191 | outline: 1px solid var(--border-color); 192 | overflow: scroll; 193 | white-space: pre; 194 | } 195 | 196 | .folder { 197 | float: right; 198 | cursor: default; 199 | border: 1px solid var(--border-color); 200 | font-size: 0.8em; 201 | padding: 0 2px 0 2px; 202 | } 203 | 204 | .folder:active { 205 | background-color: var(--vscode-button-background); 206 | } 207 | 208 | .lines { 209 | width: 25px !important; 210 | margin-right: 3px !important; 211 | } -------------------------------------------------------------------------------- /media/js/jquery-linedtextarea.js: -------------------------------------------------------------------------------- 1 | /** 2 | * NOTE: This is a modified version of Alan Williamson's jquery-linedtextarea plugin. 3 | * The objective of the modifications is to use relative sizing for everything 4 | * so that dynamic resizing of the lined textareas is possible. Also note that, 5 | * due to Chromium 66+ restrictions on reading external CSS rules from javascript, 6 | * you must specify any percentage-based widths on the textareas in their declaration 7 | * (eg. ). 8 | * 9 | * Original attribution below: 10 | * 11 | * jQuery Lined Textarea Plugin 12 | * http://alan.blog-city.com/jquerylinedtextarea.htm 13 | * 14 | * Copyright (c) 2010 Alan Williamson 15 | * 16 | * This version contains improvement for working with a 17 | * large number of lines. 18 | * 19 | * Available at 20 | * https://github.com/cotenoni/jquery-linedtextarea 21 | * 22 | * Version: 23 | * $Id: jquery-linedtextarea.js 464 2010-01-08 10:36:33Z alan $ 24 | * 25 | * Released under the MIT License: 26 | * http://www.opensource.org/licenses/mit-license.php 27 | * 28 | * Usage: 29 | * Displays a line number count column to the left of the textarea 30 | * 31 | * Class up your textarea with a given class, or target it directly 32 | * with JQuery Selectors 33 | * 34 | * $(".lined").linedtextarea({ 35 | * selectedLine: 10, 36 | * selectedClass: 'lineselect' 37 | * }); 38 | * 39 | * History: 40 | * - 2010.02.20: Fixed performance problem with high numbers of line 41 | * - 2010.01.08: Fixed a Google Chrome layout problem 42 | * - 2010.01.07: Refactored code for speed/readability; Fixed horizontal sizing 43 | * - 2010.01.06: Initial Release 44 | * 45 | */ 46 | (function ($) { 47 | 48 | $.fn.linedtextarea = function (options) { 49 | 50 | // Get the Options 51 | var opts = $.extend({}, $.fn.linedtextarea.defaults, options); 52 | var LINEHEIGHT = 15; 53 | 54 | /* 55 | * Helper function to make sure the line numbers are always 56 | * kept up to the current system 57 | */ 58 | var fillOutLines = function (codeLines, h, lineNo) { 59 | while ((codeLines.height() - h) <= 0) { 60 | if (lineNo == opts.selectedLine) 61 | codeLines.append("
" + lineNo + "
"); 62 | else 63 | codeLines.append("
" + lineNo + "
"); 64 | 65 | lineNo++; 66 | } 67 | return lineNo; 68 | }; 69 | 70 | /* 71 | * Iterate through each of the elements are to be applied to 72 | */ 73 | return this.each(function () { 74 | var lineNo = 1; 75 | var textarea = $(this); 76 | 77 | /* Turn off the wrapping of as we don't want to screw up the line numbers */ 78 | textarea.attr("wrap", "off"); 79 | textarea.css({ resize: 'none' }); 80 | var originalTextareaCssWidth = textarea.get(0).style.width || (textarea.css('width') + 'px'); 81 | 82 | /* Wrap the text area in the elements we need */ 83 | textarea.wrap("
"); 84 | var linedTextAreaDiv = textarea.parent().wrap("
"); 85 | var linedWrapDiv = linedTextAreaDiv.parent(); 86 | 87 | linedWrapDiv.prepend("
"); 88 | var linesComputedWidth = $('.lines').outerWidth(); // support overriding the gutter width 89 | 90 | var linesDiv = linedWrapDiv.find(".lines"); 91 | linesDiv.height(textarea.height() + 6); 92 | 93 | /* Draw the number bar; filling it out where necessary */ 94 | linesDiv.append("
"); 95 | var codeLinesDiv = linesDiv.find(".codelines"); 96 | lineNo = fillOutLines(codeLinesDiv, linesDiv.height(), 1); 97 | 98 | /* Move the textarea to the selected line */ 99 | if (opts.selectedLine != -1 && !isNaN(opts.selectedLine)) { 100 | var fontSize = parseInt(textarea.height() / (lineNo - 2)); 101 | var position = parseInt(fontSize * opts.selectedLine) - (textarea.height() / 2); 102 | textarea[0].scrollTop = position; 103 | } 104 | 105 | /* Set the width */ 106 | textarea.css('width', `calc(100% - ${linesComputedWidth * 1.5}px)`); 107 | linedWrapDiv.css('width', originalTextareaCssWidth); 108 | 109 | /* React to the scroll event */ 110 | var tid = null; 111 | textarea.scroll(function (tn) { 112 | if (tid === null) { 113 | var that = this; 114 | 115 | // We use a timeout as to avoid appending/redrawing 116 | // the div on every scroll event. This does add some latency 117 | // before the right line number is displayed, but makes possible 118 | // scrolling with a very high number of lines 119 | tid = setTimeout(function () { 120 | codeLinesDiv.empty(); 121 | 122 | // Calculare the line numbers to display 123 | var domTextArea = $(that)[0]; 124 | var scrollTop = domTextArea.scrollTop; 125 | var firstLine = Math.floor((scrollTop / LINEHEIGHT) + 1); 126 | var remainingScroll = (scrollTop / LINEHEIGHT) % 1; 127 | 128 | fillOutLines(codeLinesDiv, linesDiv.height(), firstLine); 129 | codeLinesDiv.css({ 'margin-top': (-1 * (remainingScroll * LINEHEIGHT)) + "px" }); 130 | tid = null; 131 | }, 150); 132 | } 133 | }); 134 | 135 | 136 | /* Should the textarea get resized outside of our control */ 137 | textarea.resize(function (tn) { 138 | var domTextArea = $(this)[0]; 139 | linesDiv.height(domTextArea.clientHeight + 6); 140 | }); 141 | 142 | }); 143 | }; 144 | 145 | // default options 146 | $.fn.linedtextarea.defaults = { 147 | selectedLine: -1, 148 | selectedClass: 'lineselect' 149 | }; 150 | 151 | })(jQuery); -------------------------------------------------------------------------------- /media/js/regexworkbench.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import Tooltips from './strings.js'; 4 | 5 | const displayMap = { 6 | 'match-btn': [['mode', 'regex', 'search', 'results'], showMatchUI], 7 | 'matchall-btn': [['mode', 'regex', 'search', 'results'], showMatchUI], 8 | 'split-btn': [['mode', 'regex', 'search', 'splitresults'], showMatchUI], 9 | 'replace-btn': [['mode', 'regex', 'replacement', 'search', 'replaced', 'results'], showReplaceUI], 10 | 'replaceall-btn': [['mode', 'regex', 'replacement', 'search', 'replaced', 'results'], showReplaceUI], 11 | }; 12 | 13 | const vscode = acquireVsCodeApi(); 14 | 15 | function showMatchUI() { 16 | $('#regex-section').removeClass("col1").addClass("col-all"); 17 | $('#search-section').removeClass("col1").addClass("col-all"); 18 | } 19 | 20 | function showReplaceUI() { 21 | $('#regex-section').removeClass("col-all").addClass("col1"); 22 | $('#search-section').removeClass("col-all").addClass("col1"); 23 | } 24 | 25 | function updateModeButtons(el) { 26 | $('.mode-btn').each((_, btn) => { 27 | if (btn.id === el.target.id) { 28 | $(btn).addClass('selected'); 29 | } else { 30 | $(btn).removeClass('selected') 31 | } 32 | }); 33 | 34 | const selectedId = $('.selected')[0].id; 35 | const toBeDisplayed = displayMap[selectedId][0].reduce((m, x) => { 36 | m[`${x}-section`] = 0; 37 | return m; 38 | }, {}); 39 | 40 | $('.section').each((_, section) => { 41 | if (section.id in toBeDisplayed) { 42 | $(`#${section.id}`).show(); 43 | } else { 44 | $(`#${section.id}`).hide(); 45 | } 46 | }); 47 | 48 | displayMap[selectedId][1](); 49 | 50 | execute(); 51 | }; 52 | 53 | function execute() { 54 | $('#results').empty(); 55 | $('#splitresults').empty(); 56 | 57 | const selectedId = $('.selected')[0].id.replace("-btn", ""); 58 | 59 | vscode.postMessage({ 60 | command: 'execute', 61 | type: selectedId, 62 | regex: $('#regex').val(), 63 | flags: getSwitches(), 64 | subject: $('#search').val(), 65 | replacement: $('#replacement').val(), 66 | }); 67 | } 68 | 69 | function processResults(r) { 70 | switch (r.op) { 71 | case 'match': 72 | buildResultsTable(r.results, $('#results')); 73 | break; 74 | case 'matchAll': 75 | buildResultsTable(r.results, $('#results')); 76 | break; 77 | case 'split': { 78 | const items = r.results.map(s => s.replace(/[\r\n]/g, " ")); 79 | const results = items.map(item => `${item}`).join(''); 80 | $('#splitresults').empty().html(results); 81 | break; 82 | } 83 | case 'replace': 84 | buildResultsTable(r.results.matches, $('#results')); 85 | $('#replaced').val(r.results.result); 86 | break; 87 | case 'replaceAll': 88 | buildResultsTable(r.results.matches, $('#results')); 89 | $('#replaced').val(r.results.result); 90 | break; 91 | case 'ERROR': 92 | $('#results').html(r.results.message); 93 | $('#splitresults').html(r.results.message); 94 | break; 95 | } 96 | 97 | updateStateInHost(); 98 | } 99 | 100 | function buildResultsTable(results, parent) { 101 | const tr = html => `${html}`; 102 | const th = (arry, attrs) => arry.reduce((s, html) => s += `${html}`, ''); 103 | const td = (arry, attrs) => arry.reduce((s, html) => s += `${html}`, ''); 104 | 105 | let table = ''; 106 | table += tr(td(['Group', 'Span', 'Value'], 'class="bold"')); 107 | 108 | let matchIndex = 0; 109 | results.forEach(e => { 110 | table += tr(th([`Match ${matchIndex}`, `${e[0].start}-${e[0].end}`, e[0].match])); 111 | 112 | if (e.length > 0) { 113 | let groupIndex = 1; 114 | while (groupIndex < e.length) { 115 | const g = e[groupIndex]; 116 | const title = 'name' in g 117 | ? `Group ${groupIndex} (${g.name})` 118 | : `Group ${groupIndex}`; 119 | 120 | table += tr(td([title, `${g.start}-${g.end}`, g.match])); 121 | groupIndex++; 122 | } 123 | } 124 | matchIndex++; 125 | }); 126 | 127 | table += '
'; 128 | 129 | $(parent).empty().html($(table)); 130 | wireThClick(); 131 | } 132 | 133 | function getSwitches() { 134 | const switches = $('.switch.selected').get().reduce((p, el) => p + el.id.replace("-switch", ""), ""); 135 | return switches; 136 | }; 137 | 138 | let regexTimeoutHandle; 139 | function onRegexChange(_) { 140 | if (regexTimeoutHandle) { 141 | clearTimeout(regexTimeoutHandle); 142 | regexTimeoutHandle = undefined; 143 | } 144 | 145 | regexTimeoutHandle = setTimeout(execute, 300); 146 | }; 147 | 148 | let searchTimeoutHandle; 149 | function onSearchChange(_) { 150 | if (searchTimeoutHandle) { 151 | clearTimeout(searchTimeoutHandle); 152 | searchTimeoutHandle = undefined; 153 | } 154 | 155 | searchTimeoutHandle = setTimeout(execute, 300); 156 | }; 157 | 158 | let replacementTimeoutHandle; 159 | function onReplacementChange(_) { 160 | if (replacementTimeoutHandle) { 161 | clearTimeout(replacementTimeoutHandle); 162 | replacementTimeoutHandle = undefined; 163 | } 164 | 165 | replacementTimeoutHandle = setTimeout(execute, 500); 166 | }; 167 | 168 | function updateStateInHost() { 169 | const state = { 170 | regex: $('#regex').val(), 171 | search: $('#search').val(), 172 | replacement: $('#replacement').val(), 173 | mode: $('.mode-btn.selected')[0].id.replace("-btn", ""), 174 | switches: { 175 | i: $('#i-switch.selected').length > 0, 176 | m: $('#m-switch.selected').length > 0, 177 | s: $('#s-switch.selected').length > 0, 178 | x: $('#x-switch.selected').length > 0 179 | } 180 | }; 181 | 182 | vscode.postMessage({ 183 | command: "stateChange", 184 | text: JSON.stringify(state) 185 | }); 186 | }; 187 | 188 | function onSwitchClick(e) { 189 | const el = $(e.target); 190 | 191 | if (el.attr('class').split(/\s+/).includes('selected')) { 192 | el.removeClass('selected'); 193 | } else { 194 | el.addClass('selected'); 195 | } 196 | execute(); 197 | }; 198 | 199 | function getVscodeTheme() { 200 | const theme = $('body').attr('class').split(' ').reduce((res, c) => c.startsWith('vscode-') ? c : res, ""); 201 | return theme; 202 | }; 203 | 204 | function applyVscodeThemeCss() { 205 | const theme = getVscodeTheme(); 206 | $('*').addClass(theme); 207 | }; 208 | 209 | function infoWindow(msg) { 210 | vscode.postMessage({ command: 'info', text: msg }); 211 | }; 212 | 213 | function setUiState(state) { 214 | $('#regex').val(state.regex); 215 | $('#search').val(state.search); 216 | $('#replacement').val(state.replacement); 217 | 218 | const buttonId = `#${state.mode}-btn`; 219 | $(buttonId).click(); 220 | 221 | if (state.switches.i) { 222 | $('#i-switch').click(); 223 | } 224 | if (state.switches.m) { 225 | $('#m-switch').click(); 226 | } 227 | if (state.switches.s) { 228 | $('#s-switch').click(); 229 | } 230 | if (state.switches.x) { 231 | $('#x-switch').click(); 232 | } 233 | }; 234 | 235 | function wireThClick() { 236 | $('th').unbind(); 237 | 238 | $('th').click(e => { 239 | const el = $(e.target); 240 | let curNode = el.parent().next(); 241 | 242 | while (true) { 243 | const firstChild = curNode.children().first(); 244 | 245 | const childTag = firstChild.prop('tagName'); 246 | if (childTag === undefined) { 247 | break; 248 | } 249 | if (childTag.toLowerCase() === 'th') { 250 | break; 251 | } 252 | 253 | curNode.toggle(); 254 | curNode = curNode.next(); 255 | } 256 | }); 257 | } 258 | 259 | function setTooltips() { 260 | const browserLang = navigator.language.substring(0, 2); 261 | const lang = browserLang in Tooltips 262 | ? browserLang 263 | : 'en'; 264 | 265 | const strings = Tooltips[lang]; 266 | 267 | for (const el in strings) { 268 | if (strings[el] !== null) { 269 | $(el).prop('title', strings[el]); 270 | } 271 | } 272 | } 273 | 274 | function wireUpThemeDetection() { 275 | const observer = new MutationObserver(mutations => { 276 | mutations.forEach(m => { 277 | if (m.attributeName === "class") { 278 | applyVscodeThemeCss(); 279 | } 280 | }); 281 | }); 282 | 283 | observer.observe($('body').get(0), { 284 | attributes: true 285 | }); 286 | } 287 | 288 | $(document).ready(() => { 289 | 290 | wireUpThemeDetection(); 291 | 292 | $(".lined").linedtextarea(); 293 | 294 | $('#regex').bind('input propertychange', onRegexChange); 295 | $('#search').bind('input propertychange', onSearchChange); 296 | $('#replacement').bind('input propertychange', onReplacementChange); 297 | 298 | $('.mode-btn').click(updateModeButtons); 299 | $('.switch').click(onSwitchClick); 300 | 301 | $('.folder').click(() => { vscode.postMessage({ command: "loadsearchtext" }); }); 302 | 303 | setTooltips(); 304 | 305 | window.addEventListener('message', e => { 306 | const message = e.data; 307 | switch (message.command) { 308 | case 'setState': 309 | setUiState(message.state); 310 | break; 311 | case 'results': 312 | processResults(message); 313 | break; 314 | } 315 | }); 316 | 317 | var waitForFinalEvent = (() => { 318 | var timers = {}; 319 | return (callback, ms, uniqueId) => { 320 | if (!uniqueId) { 321 | uniqueId = "Don't call this twice without a uniqueId"; 322 | } 323 | if (timers[uniqueId]) { 324 | clearTimeout(timers[uniqueId]); 325 | } 326 | timers[uniqueId] = setTimeout(callback, ms); 327 | }; 328 | })(); 329 | 330 | $(window).resize(() => { 331 | waitForFinalEvent(() => { 332 | vscode.postMessage({ command: "refresh" }); 333 | }, 500, "reload handler"); 334 | }); 335 | 336 | vscode.postMessage({ command: "ready" }); 337 | 338 | }); -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | 2 | import * as vscode from 'vscode'; 3 | import * as path from 'path'; 4 | import * as fs from 'fs'; 5 | import PCRE from '@stephen-riley/pcre2-wasm'; 6 | import * as regexecute from './regexecute'; 7 | 8 | const cmdId = 'regexworkbench.start'; 9 | const regexKey = "regexworkbench.regex"; 10 | const searchKey = "regexworkbench.search"; 11 | const replacementKey = "regexworkbench.replacement"; 12 | const modeKey = "regexworkbench.mode"; 13 | const iKey = "regexworkbench.i"; 14 | const mKey = "regexworkbench.m"; 15 | const sKey = "regexworkbench.s"; 16 | const xKey = "regexworkbench.x"; 17 | 18 | interface RegexWorkbenchPanelState { 19 | regex: string; 20 | replacement: string; 21 | search: string; 22 | mode: string; 23 | switches: { 24 | i: boolean; 25 | m: boolean; 26 | s: boolean; 27 | x: boolean; 28 | }; 29 | } 30 | 31 | const defaultState: RegexWorkbenchPanelState = { 32 | regex: "(there)", 33 | search: "hello there!", 34 | replacement: "world", 35 | mode: "replace", 36 | switches: { 37 | i: false, 38 | m: false, 39 | s: false, 40 | x: false, 41 | } 42 | }; 43 | 44 | let statusBarItem: vscode.StatusBarItem; 45 | let extensionContext: vscode.ExtensionContext; 46 | 47 | // this method is called when your extension is activated 48 | // your extension is activated the very first time the command is executed 49 | export async function activate(context: vscode.ExtensionContext) { 50 | extensionContext = context; 51 | 52 | context.subscriptions.push( 53 | vscode.commands.registerCommand(cmdId, () => { 54 | RegexWorkbenchPanel.createOrShow(context.extensionPath); 55 | }) 56 | ); 57 | 58 | statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); 59 | statusBarItem.command = cmdId; 60 | context.subscriptions.push(statusBarItem); 61 | 62 | PCRE.init(); 63 | 64 | statusBarItem.text = `/$(star)/`; 65 | statusBarItem.show(); 66 | 67 | if (vscode.window.registerWebviewPanelSerializer) { 68 | // Make sure we register a serializer in activation event 69 | vscode.window.registerWebviewPanelSerializer(RegexWorkbenchPanel.viewType, { 70 | async deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any) { 71 | RegexWorkbenchPanel.revive(webviewPanel, context.extensionPath); 72 | } 73 | }); 74 | } 75 | } 76 | 77 | class RegexWorkbenchPanel { 78 | /** 79 | * Track the currently panel. Only allow a single panel to exist at a time. 80 | */ 81 | public static currentPanel: RegexWorkbenchPanel | undefined; 82 | 83 | public static readonly viewType = 'regexworkbench'; 84 | 85 | private readonly _panel: vscode.WebviewPanel; 86 | private readonly _extensionPath: string; 87 | private _disposables: vscode.Disposable[] = []; 88 | 89 | private _pcre: any; 90 | 91 | private _state: RegexWorkbenchPanelState = defaultState; 92 | 93 | public static createOrShow(extensionPath: string) { 94 | const column = vscode.window.activeTextEditor 95 | ? vscode.window.activeTextEditor.viewColumn 96 | : undefined; 97 | 98 | if (RegexWorkbenchPanel.currentPanel) { 99 | RegexWorkbenchPanel.currentPanel._panel.reveal(column); 100 | return; 101 | } 102 | 103 | const panel = vscode.window.createWebviewPanel( 104 | RegexWorkbenchPanel.viewType, 105 | 'Regex Workbench', 106 | column || vscode.ViewColumn.One, 107 | { 108 | enableScripts: true, 109 | localResourceRoots: [vscode.Uri.file(path.join(extensionPath, 'media'))] 110 | } 111 | ); 112 | 113 | RegexWorkbenchPanel.currentPanel = new RegexWorkbenchPanel(panel, extensionPath); 114 | } 115 | 116 | public static revive(panel: vscode.WebviewPanel, extensionPath: string) { 117 | RegexWorkbenchPanel.currentPanel = new RegexWorkbenchPanel(panel, extensionPath); 118 | } 119 | 120 | private constructor(panel: vscode.WebviewPanel, extensionPath: string) { 121 | this._panel = panel; 122 | this._extensionPath = extensionPath; 123 | 124 | this._readState(); 125 | this._update(); 126 | 127 | this._panel.onDidDispose(() => this.dispose(), null, this._disposables); 128 | 129 | this._panel.onDidChangeViewState( 130 | (_: any) => { 131 | if (this._panel.visible) { 132 | this._update(); 133 | } 134 | }, 135 | null, 136 | this._disposables 137 | ); 138 | 139 | this._panel.webview.onDidReceiveMessage( 140 | (message: any) => { 141 | switch (message.command) { 142 | case 'stateChange': 143 | this._state = JSON.parse(message.text); 144 | if (this._state.regex === "JSR:reset") { 145 | this._resetState(); 146 | } else { 147 | this._writeState(); 148 | } 149 | return; 150 | case 'ready': 151 | this._setState(); 152 | return; 153 | case 'info': 154 | vscode.window.showErrorMessage(message.text); 155 | return; 156 | case 'loadsearchtext': 157 | this._loadSearchTextFile(); 158 | return; 159 | case 'execute': 160 | this._executeRegex(message); 161 | return; 162 | case 'refresh': 163 | this._update(); 164 | } 165 | }, 166 | null, 167 | this._disposables 168 | ); 169 | } 170 | 171 | public dispose() { 172 | RegexWorkbenchPanel.currentPanel = undefined; 173 | 174 | this._writeState(); 175 | 176 | this._panel.dispose(); 177 | 178 | this._pcre.dispose(); 179 | 180 | while (this._disposables.length) { 181 | const x = this._disposables.pop(); 182 | if (x) { 183 | x.dispose(); 184 | } 185 | } 186 | } 187 | 188 | private _executeRegex(msg: any): any { 189 | try { 190 | switch (msg.type) { 191 | case 'match': { 192 | const res = regexecute.match(msg.subject, msg.regex, msg.flags); 193 | this._panel.webview.postMessage({ command: 'results', op: 'match', results: res }); 194 | break; 195 | } 196 | case 'matchall': { 197 | const res = regexecute.matchAll(msg.subject, msg.regex, msg.flags); 198 | this._panel.webview.postMessage({ command: 'results', op: 'matchAll', results: res }); 199 | break; 200 | } 201 | case 'split': { 202 | const res = regexecute.split(msg.subject, msg.regex, msg.flags); 203 | this._panel.webview.postMessage({ command: 'results', op: 'split', results: res }); 204 | break; 205 | } 206 | case 'replace': { 207 | const res = regexecute.replace(msg.subject, msg.regex, msg.flags, msg.replacement); 208 | this._panel.webview.postMessage({ command: 'results', op: 'replace', results: res }); 209 | break; 210 | } 211 | case 'replaceall': { 212 | const res = regexecute.replaceAll(msg.subject, msg.regex, msg.flags, msg.replacement); 213 | this._panel.webview.postMessage({ command: 'results', op: 'replaceAll', results: res }); 214 | break; 215 | } 216 | } 217 | } 218 | catch (e) { 219 | let message = "Invalid regular expression"; 220 | 221 | message = 'message' in e ? message + `: ${e.message}` : message; 222 | message = 'offset' in e ? message + ` (offset ${e.offset})` : message; 223 | 224 | this._panel.webview.postMessage({ command: 'results', op: 'ERROR', results: { message } }); 225 | } 226 | } 227 | 228 | private _loadSearchTextFile() { 229 | const options: vscode.OpenDialogOptions = { 230 | canSelectMany: false, 231 | openLabel: 'Open', 232 | filters: { 'All files': ['*'] } 233 | }; 234 | 235 | vscode.window.showOpenDialog(options).then(fileUri => { 236 | if (fileUri && fileUri[0]) { 237 | const text = fs.readFileSync(fileUri[0].fsPath, { encoding: 'utf-8' }); 238 | this._state.search = text; 239 | this._setState(); 240 | } 241 | }); 242 | } 243 | 244 | private _setState() { 245 | this._panel.webview.postMessage({ command: 'setState', state: this._state }); 246 | } 247 | 248 | private _readState() { 249 | const state = { 250 | regex: extensionContext.globalState.get(regexKey) || defaultState.regex, 251 | search: extensionContext.globalState.get(searchKey) || defaultState.search, 252 | replacement: extensionContext.globalState.get(replacementKey) || defaultState.replacement, 253 | mode: extensionContext.globalState.get(modeKey) || defaultState.mode, 254 | switches: { 255 | i: extensionContext.globalState.get(iKey) || defaultState.switches.i, 256 | m: extensionContext.globalState.get(mKey) || defaultState.switches.m, 257 | s: extensionContext.globalState.get(sKey) || defaultState.switches.s, 258 | x: extensionContext.globalState.get(xKey) || defaultState.switches.x, 259 | } 260 | }; 261 | 262 | this._state = state.regex !== undefined ? state : defaultState; 263 | } 264 | 265 | private _writeState() { 266 | extensionContext.globalState.update(regexKey, this._state.regex); 267 | extensionContext.globalState.update(searchKey, this._state.search); 268 | extensionContext.globalState.update(replacementKey, this._state.replacement); 269 | extensionContext.globalState.update(modeKey, this._state.mode); 270 | extensionContext.globalState.update(iKey, this._state.switches.i); 271 | extensionContext.globalState.update(mKey, this._state.switches.m); 272 | extensionContext.globalState.update(sKey, this._state.switches.s); 273 | extensionContext.globalState.update(xKey, this._state.switches.x); 274 | } 275 | 276 | private _resetState() { 277 | this._state = defaultState; 278 | this._writeState(); 279 | this._setState(); 280 | } 281 | 282 | private _update() { 283 | const webview = this._panel.webview; 284 | this._panel.title = "Regex Workbench"; 285 | this._panel.webview.html = this._getHtmlForWebview(); 286 | } 287 | 288 | private _getNonce() { 289 | let text = ''; 290 | const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 291 | for (let i = 0; i < 32; i++) { 292 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 293 | } 294 | return text; 295 | } 296 | 297 | private _getHtmlForWebview() { 298 | const webview = this._panel.webview; 299 | 300 | const nonce = this._getNonce(); 301 | 302 | const [workbenchjsUri, workbenchcssUri, jqueryjsUri, linedtajsUri, linedtacssUri] = 303 | ["js/regexworkbench.js", "css/regexworkbench.css", "js/jquery-3.4.1.min.js", "js/jquery-linedtextarea.js", "css/jquery-linedtextarea.css"] 304 | .map(script => { 305 | const pathOnDisk = vscode.Uri.file(path.join(this._extensionPath, 'media', script)); 306 | const uri = webview.asWebviewUri(pathOnDisk); 307 | return uri; 308 | }); 309 | 310 | const doc = ` 311 | 312 | 313 | 314 | 315 | 316 | 320 | 321 | 322 | 323 | 324 | Regular Expression Workbench 325 | 326 | 327 | 328 |
329 | 330 | 331 | 332 | 333 | 334 |
335 | 336 |
337 |
338 | Regular Expression 339 |
340 | 341 | 342 | 345 | 354 | 355 |
343 | 344 | 346 | 347 |  / 348 | i 349 | m 350 | s 351 | x 352 | 353 |
356 |
357 |
358 | 359 |
360 | Replacement 361 | 362 |
363 | 364 |
365 | 366 | Search Text 367 | open 368 | 369 | 370 |
371 | 372 |
373 | Replaced Text 374 | 375 |
376 | 377 |
378 | Replace Results 379 |
380 |
381 | 382 |
383 | Split Results 384 |
385 |
386 |
387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | `; 395 | 396 | return doc; 397 | } 398 | } -------------------------------------------------------------------------------- /media/js/jquery-3.4.1.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */ 2 | !function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],E=C.document,r=Object.getPrototypeOf,s=t.slice,g=t.concat,u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.4.1",k=function(e,t){return new k.fn.init(e,t)},p=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;function d(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp($),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+$),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),ne=function(e,t,n){var r="0x"+t-65536;return r!=r||n?t:r<0?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(m.childNodes),m.childNodes),t[m.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&((e?e.ownerDocument||e:m)!==C&&T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!A[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&U.test(t)){(s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=k),o=(l=h(t)).length;while(o--)l[o]="#"+s+" "+xe(l[o]);c=l.join(","),f=ee.test(t)&&ye(e.parentNode)||e}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){A(t,!0)}finally{s===k&&e.removeAttribute("id")}}}return g(t.replace(B,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[k]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:m;return r!==C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),m!==C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=k,!C.getElementsByName||!C.getElementsByName(k).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+k+"-]").length||v.push("~="),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+k+"+*").length||v.push(".#.+[+~]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",$)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e===C||e.ownerDocument===m&&y(m,e)?-1:t===C||t.ownerDocument===m&&y(m,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e===C?-1:t===C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]===m?-1:s[r]===m?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if((e.ownerDocument||e)!==C&&T(e),d.matchesSelector&&E&&!A[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){A(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=p[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&p(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,n,r){return m(n)?k.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?k.grep(e,function(e){return e===n!==r}):"string"!=typeof n?k.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(k.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||q,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:L.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof k?t[0]:t,k.merge(this,k.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),D.test(r[1])&&k.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(k):k.makeArray(e,this)}).prototype=k.fn,q=k(E);var H=/^(?:parents|prev(?:Until|All))/,O={children:!0,contents:!0,next:!0,prev:!0};function P(e,t){while((e=e[t])&&1!==e.nodeType);return e}k.fn.extend({has:function(e){var t=k(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i,ge={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?k.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;nx",y.noCloneChecked=!!me.cloneNode(!0).lastChild.defaultValue;var Te=/^key/,Ce=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Ee=/^([^.]*)(?:\.(.+)|)/;function ke(){return!0}function Se(){return!1}function Ne(e,t){return e===function(){try{return E.activeElement}catch(e){}}()==("focus"===t)}function Ae(e,t,n,r,i,o){var a,s;if("object"==typeof t){for(s in"string"!=typeof n&&(r=r||n,n=void 0),t)Ae(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=Se;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return k().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=k.guid++)),e.each(function(){k.event.add(this,t,i,r,n)})}function De(e,i,o){o?(Q.set(e,i,!1),k.event.add(e,i,{namespace:!1,handler:function(e){var t,n,r=Q.get(this,i);if(1&e.isTrigger&&this[i]){if(r.length)(k.event.special[i]||{}).delegateType&&e.stopPropagation();else if(r=s.call(arguments),Q.set(this,i,r),t=o(this,i),this[i](),r!==(n=Q.get(this,i))||t?Q.set(this,i,!1):n={},r!==n)return e.stopImmediatePropagation(),e.preventDefault(),n.value}else r.length&&(Q.set(this,i,{value:k.event.trigger(k.extend(r[0],k.Event.prototype),r.slice(1),this)}),e.stopImmediatePropagation())}})):void 0===Q.get(e,i)&&k.event.add(e,i,ke)}k.event={global:{},add:function(t,e,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Q.get(t);if(v){n.handler&&(n=(o=n).handler,i=o.selector),i&&k.find.matchesSelector(ie,i),n.guid||(n.guid=k.guid++),(u=v.events)||(u=v.events={}),(a=v.handle)||(a=v.handle=function(e){return"undefined"!=typeof k&&k.event.triggered!==e.type?k.event.dispatch.apply(t,arguments):void 0}),l=(e=(e||"").match(R)||[""]).length;while(l--)d=g=(s=Ee.exec(e[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=k.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=k.event.special[d]||{},c=k.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&k.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(t,r,h,a)||t.addEventListener&&t.addEventListener(d,a)),f.add&&(f.add.call(t,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),k.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Q.hasData(e)&&Q.get(e);if(v&&(u=v.events)){l=(t=(t||"").match(R)||[""]).length;while(l--)if(d=g=(s=Ee.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d){f=k.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,v.handle)||k.removeEvent(e,d,v.handle),delete u[d])}else for(d in u)k.event.remove(e,d+t[l],n,r,!0);k.isEmptyObject(u)&&Q.remove(e,"handle events")}},dispatch:function(e){var t,n,r,i,o,a,s=k.event.fix(e),u=new Array(arguments.length),l=(Q.get(this,"events")||{})[s.type]||[],c=k.event.special[s.type]||{};for(u[0]=s,t=1;t\x20\t\r\n\f]*)[^>]*)\/>/gi,qe=/\s*$/g;function Oe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&k(e).children("tbody")[0]||e}function Pe(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function Re(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Me(e,t){var n,r,i,o,a,s,u,l;if(1===t.nodeType){if(Q.hasData(e)&&(o=Q.access(e),a=Q.set(t,o),l=o.events))for(i in delete a.handle,a.events={},l)for(n=0,r=l[i].length;n")},clone:function(e,t,n){var r,i,o,a,s,u,l,c=e.cloneNode(!0),f=oe(e);if(!(y.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||k.isXMLDoc(e)))for(a=ve(c),r=0,i=(o=ve(e)).length;r").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Vt,Gt=[],Yt=/(=)\?(?=&|$)|\?\?/;k.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Gt.pop()||k.expando+"_"+kt++;return this[e]=!0,e}}),k.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Yt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Yt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Yt,"$1"+r):!1!==e.jsonp&&(e.url+=(St.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||k.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?k(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Gt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Vt=E.implementation.createHTMLDocument("").body).innerHTML="
",2===Vt.childNodes.length),k.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=D.exec(e))?[t.createElement(i[1])]:(i=we([e],t,o),o&&o.length&&k(o).remove(),k.merge([],i.childNodes)));var r,i,o},k.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(k.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},k.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){k.fn[t]=function(e){return this.on(t,e)}}),k.expr.pseudos.animated=function(t){return k.grep(k.timers,function(e){return t===e.elem}).length},k.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=k.css(e,"position"),c=k(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=k.css(e,"top"),u=k.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,k.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):c.css(f)}},k.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){k.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===k.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===k.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=k(e).offset()).top+=k.css(e,"borderTopWidth",!0),i.left+=k.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-k.css(r,"marginTop",!0),left:t.left-i.left-k.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===k.css(e,"position"))e=e.offsetParent;return e||ie})}}),k.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;k.fn[t]=function(e){return _(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),k.each(["top","left"],function(e,n){k.cssHooks[n]=ze(y.pixelPosition,function(e,t){if(t)return t=_e(e,n),$e.test(t)?k(e).position()[n]+"px":t})}),k.each({Height:"height",Width:"width"},function(a,s){k.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){k.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return _(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?k.css(e,t,i):k.style(e,t,n,i)},s,n?e:void 0,n)}})}),k.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){k.fn[n]=function(e,t){return 0