├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── .vscodeignore ├── LICENSE ├── README.md ├── commitlint.config.js ├── icon.png ├── package-lock.json ├── package.json ├── src ├── activateExtension.ts └── index.ts ├── tsconfig.base.json ├── tsconfig.json ├── tsconfig.script.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | .vsix 5 | 6 | # Editor-specific 7 | .idea/ 8 | *.sublime-project 9 | *.sublime-workspace 10 | .settings 11 | 12 | # Installed libs 13 | node_modules/ 14 | typings/ 15 | 16 | # Generated 17 | dist/ 18 | tmp/ 19 | coverage/ 20 | img/ 21 | spec-js/ 22 | .nyc_output/ 23 | rules/ 24 | .tmp/ 25 | 26 | # Misc 27 | npm-debug.log 28 | .DS_STORE -------------------------------------------------------------------------------- /.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 | } -------------------------------------------------------------------------------- /.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 | "${workspaceRoot}/dist/*" 18 | ], 19 | "preLaunchTask": "npm: build" 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" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "npm: watch" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /.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 | } -------------------------------------------------------------------------------- /.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 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 OJ Kwon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Deprecated 2 | 3 | VScode introduced native supports via https://code.visualstudio.com/updates/v1_82#_dim-unfocused-editors-and-terminals. 4 | Encourage to use native features instead. Thanks for using this extension. 5 | 6 | # Active document indicator 7 | 8 | VS Code extension to dim inactive document to find current working document easily. 9 | 10 | ![demo](https://user-images.githubusercontent.com/1210596/55941490-2c4ffc80-5bf7-11e9-8ed9-72ca72255c0a.gif) 11 | 12 | ## Installation 13 | 14 | Install through VS Code extensions. Search for `Active document indicator`. 15 | 16 | ## Settings 17 | 18 | #### activeDocumentIndicator.enabled (default: true) 19 | 20 | #### activeDocumentIndicator.opacity (default: 50) 21 | An integer between 0 and 100 used for the opacity percentage for non active document 22 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ['@commitlint/config-angular'] }; 2 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kwonoj/vscode-activedocumentindicator/dd9fcc89cab6f6df15ddc6adab453f8810127adf/icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vscode-activedocumentindicator", 3 | "displayName": "Active Document Indicator", 4 | "description": "Visual indicator to current active text document", 5 | "publisher": "ojkwon", 6 | "author": "OJ Kwon ", 7 | "license": "MIT", 8 | "version": "0.0.4", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/kwonoj/vscode-activedocumentindicator.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/kwonoj/vscode-activedocumentindicator/issues" 15 | }, 16 | "engines": { 17 | "vscode": "^1.56.0" 18 | }, 19 | "categories": [ 20 | "Other" 21 | ], 22 | "activationEvents": [ 23 | "*" 24 | ], 25 | "icon": "icon.png", 26 | "main": "./dist/index.bundle.js", 27 | "contributes": { 28 | "configuration": { 29 | "properties": { 30 | "activeDocumentIndicator.enabled": { 31 | "default": true, 32 | "type": "boolean" 33 | }, 34 | "activeDocumentIndicator.opacity": { 35 | "default": 50, 36 | "type": "number", 37 | "description": "An integer between 0 and 100 used for the opacity percentage for non active document" 38 | } 39 | } 40 | } 41 | }, 42 | "lint-staged": { 43 | "*.{ts,js}": [ 44 | "prettier --write --single-quote --print-width 120 --jsx-bracket-same-line true", 45 | "tslint --fix", 46 | "git add" 47 | ] 48 | }, 49 | "scripts": { 50 | "prepublish": "npm-run-all vscode:prepublish", 51 | "vscode:prepublish": "cross-env NODE_ENV=production npm-run-all clean build", 52 | "commit": "git-cz -S", 53 | "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", 54 | "lint": "tslint -c tslint.json -p tsconfig.json \"src/**/*.ts\" \"spec/**/*.ts\"", 55 | "lint:staged": "lint-staged", 56 | "clean": "shx rm -rf ./.tmp ./dist", 57 | "build:test": "tsc -p ./tsconfig.script.json", 58 | "build": "esbuild --bundle ./src/index.ts --outfile=./dist/index.bundle.js --minify --sourcemap --external:vscode --platform=node", 59 | "postinstall": "node ./node_modules/vscode/bin/install", 60 | "test:unit": "npm-run-all clean build:test build && node ./.tmp/test-ci.js", 61 | "test:e2e": "npm run compile && node ./node_modules/vscode/bin/test" 62 | }, 63 | "devDependencies": { 64 | "@commitlint/cli": "^12.1.4", 65 | "@commitlint/config-angular": "^12.1.4", 66 | "@types/mocha": "^8.2.2", 67 | "@types/node": "^15.6.1", 68 | "@types/shelljs": "^0.8.8", 69 | "@types/vscode": "^1.56.0", 70 | "conventional-changelog-cli": "^2.1.1", 71 | "cross-env": "^7.0.3", 72 | "cz-conventional-changelog": "^3.3.0", 73 | "esbuild": "^0.12.5", 74 | "husky": "^3.1.0", 75 | "lint-staged": "^11.0.0", 76 | "npm-run-all": "^4.1.5", 77 | "prettier": "^2.3.0", 78 | "rxjs": "^7.1.0", 79 | "shelljs": "^0.8.4", 80 | "shx": "^0.3.3", 81 | "ts-loader": "^8.0.9", 82 | "ts-node": "^10.0.0", 83 | "tslint": "^6.1.3", 84 | "tslint-no-unused-expression-chai": "0.1.4", 85 | "typescript": "^4.3.2", 86 | "vscode-test": "^1.5.2" 87 | }, 88 | "husky": { 89 | "hooks": { 90 | "commit-msg": "commitlint -e", 91 | "pre-commit": "lint-staged", 92 | "pre-push": "npm-run-all build:test" 93 | } 94 | }, 95 | "dependencies": {} 96 | } 97 | -------------------------------------------------------------------------------- /src/activateExtension.ts: -------------------------------------------------------------------------------- 1 | import { ExtensionContext, window, Range, TextEditor, workspace, TextEditorDecorationType } from 'vscode'; 2 | import { fromEventPattern } from 'rxjs'; 3 | import { startWith, debounceTime, withLatestFrom, map, scan, filter } from 'rxjs/operators'; 4 | 5 | /** 6 | * Create new decorations for given opacity. 7 | * 8 | */ 9 | const getOpacityDecoration = (raw: number) => 10 | window.createTextEditorDecorationType({ 11 | opacity: `${raw / 100}` 12 | }); 13 | 14 | /** 15 | * Returns full document's range. 16 | * @param editor 17 | */ 18 | const getFullDocumentRange = (editor: TextEditor) => { 19 | const invalidRange = new Range(0, 0, editor.document.lineCount /*intentionally missing the '-1' */, 0); 20 | return editor.document.validateRange(invalidRange); 21 | }; 22 | 23 | interface IndicatorConfiguration { 24 | enabled: boolean; 25 | opacity: number; 26 | } 27 | 28 | /** 29 | * Read current configurations 30 | */ 31 | const getConfiguration = (): IndicatorConfiguration => { 32 | const config = workspace.getConfiguration('activeDocumentIndicator'); 33 | 34 | return { 35 | enabled: config.get('enabled', true), 36 | opacity: config.get('opacity', 50) 37 | }; 38 | }; 39 | 40 | /** 41 | * Apply opacity decorations to non-active text editors, clear for active editor 42 | * @param activeEditor 43 | */ 44 | const applyDecoration = ([activeEditor, config]: [ 45 | TextEditor | undefined, 46 | { decoration: TextEditorDecorationType } | null 47 | ]) => { 48 | window.visibleTextEditors 49 | .map(editor => ({ editor, ranges: editor === activeEditor ? [] : [getFullDocumentRange(editor)] })) 50 | .forEach(({ editor, ranges }) => editor.setDecorations(config!.decoration, ranges)); 51 | }; 52 | 53 | /** 54 | * Creates Observable to subscribe configuration change with intiial value. Each time config changes, disposes existing decorations then emit new decorations. 55 | */ 56 | const getConfigChangeObservable = () => 57 | fromEventPattern(workspace.onDidChangeConfiguration, (_h, subscription) => subscription.dispose()).pipe( 58 | map(getConfiguration), 59 | startWith(getConfiguration()), 60 | scan( 61 | (prev: IndicatorConfiguration & { decoration: TextEditorDecorationType } | null, cur: IndicatorConfiguration) => { 62 | // Reset existing config based decorations 63 | if (!!prev && prev.decoration) { 64 | prev.decoration.dispose(); 65 | } 66 | 67 | return { 68 | ...cur, 69 | decoration: getOpacityDecoration(cur.opacity) 70 | } as any; 71 | }, 72 | null 73 | ) 74 | ); 75 | 76 | /** 77 | * Creates Observable to subscribe active editor changes. 78 | */ 79 | const getEditorChangeObservable = () => 80 | fromEventPattern(window.onDidChangeActiveTextEditor, (_h, subscription) => subscription.dispose()); 81 | 82 | /** 83 | * Activation extension 84 | */ 85 | const activate = (context: ExtensionContext) => { 86 | const subscription = getEditorChangeObservable() 87 | .pipe( 88 | startWith(window.activeTextEditor), 89 | withLatestFrom(getConfigChangeObservable()), 90 | debounceTime(100), 91 | filter(([, config]) => config!.enabled) 92 | ) 93 | .subscribe(applyDecoration); 94 | 95 | context.subscriptions.push({ dispose: subscription.unsubscribe.bind(subscription) }); 96 | }; 97 | 98 | export { activate }; 99 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { activate } from './activateExtension'; -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "removeComments": true, 4 | "preserveConstEnums": false, 5 | "sourceMap": true, 6 | "noImplicitAny": true, 7 | "noImplicitReturns": true, 8 | "suppressImplicitAnyIndexErrors": true, 9 | "strictNullChecks": true, 10 | "strict": true, 11 | "noUnusedLocals": true, 12 | "noImplicitThis": true, 13 | "noUnusedParameters": true, 14 | "moduleResolution": "node", 15 | "target": "es2017", 16 | "outDir": ".tmp", 17 | "lib": [ 18 | "es2017", 19 | "dom" 20 | ] 21 | } 22 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "esnext" 5 | } 6 | } -------------------------------------------------------------------------------- /tsconfig.script.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "commonjs" 5 | } 6 | } -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------