-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding an overload to TextEditor.edit for insertion of a SnippetString #17628
Changes from 5 commits
38a3a1a
75840d1
40522e2
9c42a68
a41b017
8a30392
f7587b3
3c817c7
c27b386
713aaff
95fc032
c21734f
ff2ea5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,6 +967,17 @@ declare module 'vscode' { | |
*/ | ||
edit(callback: (editBuilder: TextEditorEdit) => void, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>; | ||
|
||
/** | ||
* Inserts the given snippet template and enters snippet mode. | ||
* | ||
* If the editor is already in snippet mode, insertion fails and the returned promise resolves to false. | ||
* | ||
* @param template The snippet template to insert | ||
* @param posOrRange The position or replacement range representing the location of the insertion. | ||
* @return A promise that resolves with a value indicating if the snippet could be inserted. | ||
*/ | ||
insertSnippet(template: string, posOrRange: Position | Range): Thenable<boolean>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that you should be able to call this without being concerned with location. Sharing an argument for both position or range seems a little awkward as well. So long as I can alter the selection before starting. How should this work for multiple selections? In the case of overloading Another thought: Should we supply a callback to know when snippet mode was exited? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure, I was just wondering if reusing the name edit(snippet: SnippetString, options?:{/*undo stops control*/}): void;
edit(callback: (editBuilder: TextEditorEdit) => void, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
Not a fan because it really depends on the user tabbing through things to exit snippet mode. |
||
|
||
/** | ||
* Adds a set of decorations to the text editor. If a set of decorations already exists with | ||
* the given [decoration type](#TextEditorDecorationType), they will be replaced. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,4 +85,16 @@ declare module 'vscode' { | |
*/ | ||
getClickCommand?(node: T): string; | ||
} | ||
export interface TextEditor { | ||
/** | ||
* Inserts the given snippet template and enters snippet mode. | ||
* | ||
* If the editor is already in snippet mode, insertion fails and the returned promise resolves to false. | ||
* | ||
* @param template The snippet template to insert | ||
* @param posOrRange The position or replacement range representing the location of the insertion. | ||
* @return A promise that resolves with a value indicating if the snippet could be inserted. | ||
*/ | ||
insertSnippet(template: string, posOrRange: Position | Range): Thenable<boolean>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't needed as we make the change directly in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't think so, but the extensions project pulls from the publicly published vscode package instead of the vscode.d.ts in the main project. That's why I got the first build failure in the PR. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to get away with just using
insertSnippet
. The controller is already complexThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that this could be consolidated.