未验证 提交 4cc84900 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #39483 from yitongding/addSelectedText

Add selected text to configuration variable #27466
......@@ -103,6 +103,22 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
return '';
}
private get selectedText(): string {
const activeEditor = this.editorService.getActiveEditor();
if (activeEditor) {
const editorControl = (<ICodeEditor>activeEditor.getControl());
if (editorControl) {
const editorModel = editorControl.getModel();
const editorSelection = editorControl.getSelection();
if (editorModel && editorSelection) {
return editorModel.getValueInRange(editorSelection);
}
}
}
return '';
}
private getFilePath(): string {
let input = this.editorService.getActiveEditorInput();
if (input instanceof DiffEditorInput) {
......
......@@ -56,6 +56,10 @@ suite('Configuration Resolver Service', () => {
assert.strictEqual(configurationResolverService.resolve(workspace, 'abc ${lineNumber} xyz'), `abc ${editorService.mockLineNumber} xyz`);
});
test('current selected text', () => {
assert.strictEqual(configurationResolverService.resolve(workspace, 'abc ${selectedText} xyz'), `abc ${editorService.mockSelectedText} xyz`);
});
test('substitute many', () => {
if (platform.isWindows) {
assert.strictEqual(configurationResolverService.resolve(workspace, '${workspaceFolder} - ${workspaceFolder}'), '\\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation');
......
......@@ -584,12 +584,14 @@ export class TestEditorService implements IWorkbenchEditorService {
public activeEditorOptions: IEditorOptions;
public activeEditorPosition: Position;
public mockLineNumber: number;
public mockSelectedText: string;
private callback: (method: string) => void;
constructor(callback?: (method: string) => void) {
this.callback = callback || ((s: string) => { });
this.mockLineNumber = 15;
this.mockSelectedText = 'selected text';
}
public openEditors(inputs: any[]): Promise {
......@@ -618,7 +620,8 @@ export class TestEditorService implements IWorkbenchEditorService {
getId: () => { return null; },
getControl: () => {
return {
getSelection: () => { return { positionLineNumber: this.mockLineNumber }; }
getSelection: () => { return { positionLineNumber: this.mockLineNumber }; },
getModel: () => { return { getValueInRange: () => this.mockSelectedText }; }
};
},
focus: () => { },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册