open-editor
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -12,2 +12,17 @@ import {PathLike} from 'line-column-path'; | ||
readonly editor?: string; | ||
/** | ||
Wait until the editor is closed. | ||
@default false | ||
@example | ||
``` | ||
import openEditor from 'open-editor'; | ||
await openEditor(['unicorn.js:5:3'], {wait: true}); | ||
console.log('File was closed'); | ||
``` | ||
*/ | ||
readonly wait?: boolean; | ||
} | ||
@@ -33,6 +48,8 @@ | ||
/** | ||
Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit. | ||
Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit unless you specify `wait: true` in the options. | ||
@param files - Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`. | ||
@returns Promise<void> - If options.wait is true, the returned promise resolves as soon as the editor closes. Otherwise it resolves when the editor starts. | ||
@example | ||
@@ -55,3 +72,3 @@ ``` | ||
*/ | ||
export default function openEditor(files: readonly PathLike[], options?: Options): void; | ||
export default function openEditor(files: readonly PathLike[], options?: Options): Promise<void>; | ||
@@ -58,0 +75,0 @@ /** |
43
index.js
@@ -15,3 +15,3 @@ import process from 'node:process'; | ||
if (editor.id === 'vscode') { | ||
if (['vscode', 'vscodium'].includes(editor.id)) { | ||
editorArguments.push('--goto'); | ||
@@ -23,4 +23,9 @@ } | ||
if (['sublime', 'atom', 'vscode'].includes(editor.id)) { | ||
if (['sublime', 'atom', 'vscode', 'vscodium'].includes(editor.id)) { | ||
editorArguments.push(stringifyLineColumnPath(parsed)); | ||
if (options.wait) { | ||
editorArguments.push('--wait'); | ||
} | ||
continue; | ||
@@ -31,2 +36,7 @@ } | ||
editorArguments.push(stringifyLineColumnPath(parsed, {column: false})); | ||
if (options.wait) { | ||
editorArguments.push('--wait'); | ||
} | ||
continue; | ||
@@ -36,5 +46,14 @@ } | ||
if (editor.id === 'textmate') { | ||
editorArguments.push('--line', stringifyLineColumnPath(parsed, { | ||
file: false, | ||
}), parsed.file); | ||
editorArguments.push( | ||
'--line', | ||
stringifyLineColumnPath(parsed, { | ||
file: false, | ||
}), | ||
parsed.file, | ||
); | ||
if (options.wait) { | ||
editorArguments.push('--wait'); | ||
} | ||
continue; | ||
@@ -44,3 +63,7 @@ } | ||
if (['vim', 'neovim'].includes(editor.id)) { | ||
editorArguments.push(`+call cursor(${parsed.line}, ${parsed.column})`, parsed.file); | ||
editorArguments.push( | ||
`+call cursor(${parsed.line}, ${parsed.column})`, | ||
parsed.file, | ||
); | ||
continue; | ||
@@ -59,3 +82,3 @@ } | ||
export default function openEditor(files, options) { | ||
export default async function openEditor(files, options) { | ||
const result = getEditorInfo(files, options); | ||
@@ -81,2 +104,8 @@ const stdio = result.isTerminalEditor ? 'inherit' : 'ignore'; | ||
if (options.wait) { | ||
return new Promise(resolve => { | ||
subprocess.on('exit', resolve); | ||
}); | ||
} | ||
if (result.isTerminalEditor) { | ||
@@ -83,0 +112,0 @@ subprocess.on('exit', process.exit); |
{ | ||
"name": "open-editor", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Open files in your editor at a specific line and column", | ||
@@ -51,3 +51,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"env-editor": "^1.0.0", | ||
"env-editor": "^1.1.0", | ||
"execa": "^5.1.1", | ||
@@ -54,0 +54,0 @@ "line-column-path": "^3.0.0", |
@@ -10,2 +10,3 @@ # open-editor | ||
- Visual Studio Code | ||
- VSCodium | ||
- WebStorm* | ||
@@ -47,3 +48,3 @@ - TextMate | ||
Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit. | ||
Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit unless you specify `wait: true` in the options. | ||
@@ -60,2 +61,17 @@ #### files | ||
##### wait | ||
Type: `boolean`\ | ||
Default: `false` | ||
Wait until the editor is closed. | ||
```js | ||
import openEditor from 'open-editor'; | ||
await openEditor(['unicorn.js:5:3'], {wait: true}); | ||
console.log('File was closed'); | ||
``` | ||
##### editor | ||
@@ -70,3 +86,3 @@ | ||
### getEditorRunConfig(files, options?) | ||
### getEditorInfo(files, options?) | ||
@@ -73,0 +89,0 @@ Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8733
157
108
Updatedenv-editor@^1.1.0