Skip to content

Commit 20a2bff

Browse files
committed
Add two new commands for forcing to finding inplace and in new file
1 parent dc051d1 commit 20a2bff

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
"command": "snippet.find",
4747
"category": "Snippet"
4848
},
49+
{
50+
"title": "Find Inplace",
51+
"command": "snippet.findInplace",
52+
"category": "Snippet"
53+
},
54+
{
55+
"title": "Find in new editor window",
56+
"command": "snippet.findInNewEditor",
57+
"category": "Snippet"
58+
},
4959
{
5060
"title": "Find snippet from selected text",
5161
"command": "snippet.findSelectedText",
@@ -87,7 +97,9 @@
8797
},
8898
"activationEvents": [
8999
"onCommand:snippet.find",
90-
"onCommand:snippet.findSelectedText"
100+
"onCommand:snippet.findSelectedText",
101+
"onCommand:snippet.findInplace",
102+
"onCommand:snippet.findInNewEditor"
91103
],
92104
"devDependencies": {
93105
"typescript": "^2.6.1",

src/extension.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,40 @@ import * as vscode from 'vscode'
66
export function activate(ctx: vscode.ExtensionContext) {
77
ctx.subscriptions.push(vscode.commands.registerCommand(
88
'snippet.find', find))
9+
ctx.subscriptions.push(vscode.commands.registerCommand(
10+
'snippet.findInplace', findInplace))
11+
ctx.subscriptions.push(vscode.commands.registerCommand(
12+
'snippet.findInNewEditor', findInNewEditor))
913
ctx.subscriptions.push(vscode.commands.registerCommand(
1014
'snippet.findSelectedText', findSelectedText))
1115
}
1216

1317
function find() {
18+
let configuration = vscode.workspace.getConfiguration('snippet')
19+
let openInNewEditor: boolean = configuration["openInNewEditor"]
20+
21+
vscode.window.showInputBox()
22+
.then(query => {
23+
asyncRequest(query, function (data) {
24+
insertText(data, openInNewEditor)
25+
})
26+
});
27+
}
28+
29+
function findInplace() {
1430
vscode.window.showInputBox()
1531
.then(query => {
1632
asyncRequest(query, function (data) {
17-
insertText(data)
33+
insertText(data, false)
34+
})
35+
});
36+
}
37+
38+
function findInNewEditor() {
39+
vscode.window.showInputBox()
40+
.then(query => {
41+
asyncRequest(query, function (data) {
42+
insertText(data, true)
1843
})
1944
});
2045
}
@@ -29,8 +54,11 @@ function findSelectedText() {
2954
let selection = editor.selection;
3055
let query = editor.document.getText(selection);
3156

57+
let configuration = vscode.workspace.getConfiguration('snippet')
58+
let openInNewEditor: boolean = configuration["openInNewEditor"]
59+
3260
asyncRequest(query, function (data) {
33-
insertText(data)
61+
insertText(data, openInNewEditor)
3462
})
3563
}
3664

@@ -81,9 +109,7 @@ function asyncRequest(queryRaw: string, callback: (data: string) => void) {
81109
})
82110
}
83111

84-
function insertText(content: string) {
85-
let configuration = vscode.workspace.getConfiguration('snippet')
86-
let openInNewEditor: boolean = configuration["openInNewEditor"]
112+
function insertText(content: string, openInNewEditor = true) {
87113

88114
if (openInNewEditor) {
89115
let language = vscode.window.activeTextEditor.document.languageId

0 commit comments

Comments
 (0)