From 2a1528635f9c773bc0882f247d747dce9d60aeed Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Mon, 27 Jun 2016 15:29:33 +0300 Subject: [PATCH] [emmet] Support all the features (#8155) * [emmet] Support all the features * Fix TSLint errors * [emmet] Fix problem with CSS `url()` without quotes * [emmet] Do not save files without a name * [emmet] Clarifying the method name * [emmet] Add Promise error handler * [emmet] Correct support for paths * Fix TSLint errors * Space before the closing bracket. * More guidelines * [emmet] Add class BasicEmmetEditorAction * Fix bad copyright statement --- .../parts/emmet/node/actions/balance.ts | 39 ++++++ .../parts/emmet/node/actions/base64.ts | 120 ++++++++++++++++++ .../parts/emmet/node/actions/editPoints.ts | 39 ++++++ .../parts/emmet/node/actions/evaluateMath.ts | 26 ++++ .../emmet/node/actions/expandAbbreviation.ts | 45 +++++++ .../emmet/node/actions/incrementDecrement.ts | 91 +++++++++++++ .../parts/emmet/node/actions/matchingPair.ts | 26 ++++ .../parts/emmet/node/actions/mergeLines.ts | 26 ++++ .../emmet/node/actions/reflectCssValue.ts | 26 ++++ .../parts/emmet/node/actions/removeTag.ts | 26 ++++ .../parts/emmet/node/actions/selectItem.ts | 39 ++++++ .../parts/emmet/node/actions/splitJoinTag.ts | 26 ++++ .../emmet/node/actions/updateImageSize.ts | 26 ++++ .../parts/emmet/node/actions/updateTag.ts | 45 +++++++ .../node/actions/wrapWithAbbreviation.ts | 45 +++++++ .../parts/emmet/node/editorAccessor.ts | 9 +- .../parts/emmet/node/emmet.contribution.ts | 59 +++------ src/vs/workbench/parts/emmet/node/emmet.d.ts | 7 +- .../parts/emmet/node/emmetActions.ts | 91 +------------ .../parts/emmet/node/emmetEditorAction.ts | 29 +++++ .../parts/emmet/node/fileAccessor.ts | 27 ++++ 21 files changed, 735 insertions(+), 132 deletions(-) create mode 100644 src/vs/workbench/parts/emmet/node/actions/balance.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/base64.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/editPoints.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/evaluateMath.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/expandAbbreviation.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/incrementDecrement.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/matchingPair.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/mergeLines.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/reflectCssValue.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/removeTag.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/selectItem.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/splitJoinTag.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/updateImageSize.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/updateTag.ts create mode 100644 src/vs/workbench/parts/emmet/node/actions/wrapWithAbbreviation.ts create mode 100644 src/vs/workbench/parts/emmet/node/emmetEditorAction.ts create mode 100644 src/vs/workbench/parts/emmet/node/fileAccessor.ts diff --git a/src/vs/workbench/parts/emmet/node/actions/balance.ts b/src/vs/workbench/parts/emmet/node/actions/balance.ts new file mode 100644 index 0000000000000..f180a5961fe21 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/balance.ts @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class BalanceInwardAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.balanceInward'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'balance_inward'); + } +} + +class BalanceOutwardAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.balanceOutward'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'balance_outward'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(BalanceInwardAction, + BalanceInwardAction.ID, + nls.localize('balanceInward', "Emmet: Balance (inward)"), void 0, 'Emmet: Balance (inward)')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(BalanceOutwardAction, + BalanceOutwardAction.ID, + nls.localize('balanceOutward', "Emmet: Balance (outward)"), void 0, 'Emmet: Balance (outward)')); diff --git a/src/vs/workbench/parts/emmet/node/actions/base64.ts b/src/vs/workbench/parts/emmet/node/actions/base64.ts new file mode 100644 index 0000000000000..44f60f6e4e137 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/base64.ts @@ -0,0 +1,120 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); + +import * as Paths from 'vs/base/common/paths'; +import {fileExists} from 'vs/base/node/pfs'; +import {createPath} from '../fileAccessor'; +import {EmmetEditorAction} from '../emmetActions'; +import {Action} from 'vs/base/common/actions'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; +import {IQuickOpenService, IInputOptions} from 'vs/workbench/services/quickopen/common/quickOpenService'; +import {IMessageService, Severity} from 'vs/platform/message/common/message'; + +class EncodeDecodeDataUrlAction extends EmmetEditorAction { + + static ID = 'editor.emmet.action.encodeDecodeDataUrl'; + private imageFilePath: string = null; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, + @IConfigurationService configurationService: IConfigurationService, + @IQuickOpenService private quickOpenService: IQuickOpenService, + @IMessageService private messageService: IMessageService) { + super(descriptor, editor, configurationService); + } + + public runEmmetAction(_module) { + const currentLine = this.editorAccessor.getCurrentLine(); + if (!this.isDataURI(currentLine)) { + this.encodeDecode(_module); + return; + } + + let options: IInputOptions = { + prompt: nls.localize('enterImagePath', "Enter path to file (absolute or relative)"), + placeHolder: nls.localize('path', "Path to file") + }; + + const quickPromise = this.quickOpenService.input(options) + .then(path => { + if (!this.isValidInput(path)) { + quickPromise.cancel(); + } + + this.imageFilePath = path; + + const fullpath = createPath(this.editorAccessor.getFilePath(), path); + return fileExists(fullpath); + }) + .then(status => { + if (!status) { + this.encodeDecode(_module, this.imageFilePath); + return; + } + + const message = nls.localize('warnEscalation', "File **{0}** already exists. Do you want to overwrite the existing file?", this.imageFilePath); + const actions = [ + new Action('cancel', nls.localize('cancel', "Cancel"), '', true), + new Action('ok', nls.localize('ok', "OK"), '', true, () => { + this.encodeDecode(_module, this.imageFilePath); + return null; + }) + ]; + this.messageService.show(Severity.Warning, { message, actions }); + }); + } + + public encodeDecode(_module: any, filepath?: string) { + this.editorAccessor.prompt = (): string => { + return filepath; + }; + + if (!_module.run('encode_decode_data_url', this.editorAccessor)) { + this.editorAccessor.noExpansionOccurred(); + } + } + + private isValidInput(input: any): boolean { + if (input === undefined) { + return false; + } + + // Validate all segments of path without absolute and empty segments + // Valid: `images/test.png`, `./test.png`, `../images/test.png`, `\images\test.png` + let isValidFilePath = true; + const filePathSegments = Paths.normalize(input).split('/').filter(segment => { + return segment.length !== 0 && segment !== '..'; + }); + + for (let i = 0; i < filePathSegments.length; i++) { + if (!Paths.isValidBasename(filePathSegments[i])) { + isValidFilePath = false; + break; + } + } + + if (!isValidFilePath) { + const message = nls.localize('invalidFileNameError', "The name **{0}** is not valid as a file or folder name. Please choose a different name.", input); + this.messageService.show(Severity.Error, message); + return false; + } + + return true; + } + + private isDataURI(data: string): boolean { + return /(?:src=|url\()['"]?data:/.test(data); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(EncodeDecodeDataUrlAction, + EncodeDecodeDataUrlAction.ID, + nls.localize('encodeDecodeDataUrl', "Emmet: Encode\\Decode data:URL image"), void 0, 'Emmet: Encode\\Decode data:URL image')); diff --git a/src/vs/workbench/parts/emmet/node/actions/editPoints.ts b/src/vs/workbench/parts/emmet/node/actions/editPoints.ts new file mode 100644 index 0000000000000..a983009d3ec07 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/editPoints.ts @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class PreviousEditPointAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.previousEditPoint'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'prev_edit_point'); + } +} + +class NextEditPointAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.nextEditPoint'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'next_edit_point'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(PreviousEditPointAction, + PreviousEditPointAction.ID, + nls.localize('previousEditPoint', "Emmet: Previous Edit Point"), void 0, 'Emmet: Previous Edit Point')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(NextEditPointAction, + NextEditPointAction.ID, + nls.localize('nextEditPoint', "Emmet: Next Edit Point"), void 0, 'Emmet: Next Edit Point')); diff --git a/src/vs/workbench/parts/emmet/node/actions/evaluateMath.ts b/src/vs/workbench/parts/emmet/node/actions/evaluateMath.ts new file mode 100644 index 0000000000000..1fbc4abefb3ba --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/evaluateMath.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class EvaluateMathAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.evaluateMath'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'evaluate_math_expression'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(EvaluateMathAction, + EvaluateMathAction.ID, + nls.localize('evaluateMathExpression', "Emmet: Evaluate Math Expression"), void 0, 'Emmet: Evaluate Math Expression')); diff --git a/src/vs/workbench/parts/emmet/node/actions/expandAbbreviation.ts b/src/vs/workbench/parts/emmet/node/actions/expandAbbreviation.ts new file mode 100644 index 0000000000000..d952799711f18 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/expandAbbreviation.ts @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +import editorCommon = require('vs/editor/common/editorCommon'); +import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry'; +import {KeyCode} from 'vs/base/common/keyCodes'; +import {KbExpr} from 'vs/platform/keybinding/common/keybindingService'; + +class ExpandAbbreviationAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.expandAbbreviation'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'expand_abbreviation'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ExpandAbbreviationAction, + ExpandAbbreviationAction.ID, + nls.localize('expandAbbreviationAction', "Emmet: Expand Abbreviation"), void 0, 'Emmet: Expand Abbreviation')); + + +KeybindingsRegistry.registerCommandRule({ + id: ExpandAbbreviationAction.ID, + weight: KeybindingsRegistry.WEIGHT.editorContrib(), + when: KbExpr.and( + KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), + KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION), + KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS), + KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS), + KbExpr.has('config.emmet.triggerExpansionOnTab') + ), + primary: KeyCode.Tab +}); diff --git a/src/vs/workbench/parts/emmet/node/actions/incrementDecrement.ts b/src/vs/workbench/parts/emmet/node/actions/incrementDecrement.ts new file mode 100644 index 0000000000000..05317ee150cc1 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/incrementDecrement.ts @@ -0,0 +1,91 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class IncrementNumberByOneTenthAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.incrementNumberByOneTenth'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'increment_number_by_01'); + } +} + +class IncrementNumberByOneAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.incrementNumberByOne'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'increment_number_by_1'); + } +} + +class IncrementNumberByTenAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.incrementNumberByTen'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'increment_number_by_10'); + } +} + +class DecrementNumberByOneTenthAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.decrementNumberByOneTenth'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'decrement_number_by_01'); + } +} + +class DecrementNumberByOneAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.decrementNumberByOne'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'decrement_number_by_1'); + } +} + +class DecrementNumberByTenAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.decrementNumberByTen'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'decrement_number_by_10'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IncrementNumberByOneTenthAction, + IncrementNumberByOneTenthAction.ID, + nls.localize('incrementNumberByOneTenth', "Emmet: Increment by 0.1"), void 0, 'Emmet: Increment by 0.1')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(DecrementNumberByOneTenthAction, + DecrementNumberByOneTenthAction.ID, + nls.localize('decrementNumberByOneTenth', "Emmet: Decrement by 0.1"), void 0, 'Emmet: Decrement by 0.1')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IncrementNumberByOneAction, + IncrementNumberByOneAction.ID, + nls.localize('incrementNumberByOne', "Emmet: Increment by 1"), void 0, 'Emmet: Increment by 1')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(DecrementNumberByOneAction, + DecrementNumberByOneAction.ID, + nls.localize('decrementNumberByOne', "Emmet: Decrement by 1"), void 0, 'Emmet: Decrement by 1')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IncrementNumberByTenAction, + IncrementNumberByTenAction.ID, + nls.localize('incrementNumberByTen', "Emmet: Increment by 10"), void 0, 'Emmet: Increment by 10')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(DecrementNumberByTenAction, + DecrementNumberByTenAction.ID, + nls.localize('decrementNumberByTen', "Emmet: Decrement by 10"), void 0, 'Emmet: Decrement by 10')); diff --git a/src/vs/workbench/parts/emmet/node/actions/matchingPair.ts b/src/vs/workbench/parts/emmet/node/actions/matchingPair.ts new file mode 100644 index 0000000000000..0d6bf2361ec2d --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/matchingPair.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class GoToMatchingPairAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.matchingPair'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'matching_pair'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(GoToMatchingPairAction, + GoToMatchingPairAction.ID, + nls.localize('matchingPair', "Emmet: Go to Matching Pair"), void 0, 'Emmet: Go to Matching Pair')); diff --git a/src/vs/workbench/parts/emmet/node/actions/mergeLines.ts b/src/vs/workbench/parts/emmet/node/actions/mergeLines.ts new file mode 100644 index 0000000000000..5ee7befa80605 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/mergeLines.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class MergeLinesAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.mergeLines'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'merge_lines'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(MergeLinesAction, + MergeLinesAction.ID, + nls.localize('mergeLines', "Emmet: Merge Lines"), void 0, 'Emmet: Merge Lines')); diff --git a/src/vs/workbench/parts/emmet/node/actions/reflectCssValue.ts b/src/vs/workbench/parts/emmet/node/actions/reflectCssValue.ts new file mode 100644 index 0000000000000..a0b896d240332 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/reflectCssValue.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class ReflectCSSValueAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.reflectCSSValue'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'reflect_css_value'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ReflectCSSValueAction, + ReflectCSSValueAction.ID, + nls.localize('reflectCSSValue', "Emmet: Reflect CSS Value"), void 0, 'Emmet: Reflect CSS Value')); diff --git a/src/vs/workbench/parts/emmet/node/actions/removeTag.ts b/src/vs/workbench/parts/emmet/node/actions/removeTag.ts new file mode 100644 index 0000000000000..1b2a348d36b8e --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/removeTag.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class RemoveTagAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.removeTag'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'remove_tag'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(RemoveTagAction, + RemoveTagAction.ID, + nls.localize('removeTag', "Emmet: Remove Tag"), void 0, 'Emmet: Remove Tag')); diff --git a/src/vs/workbench/parts/emmet/node/actions/selectItem.ts b/src/vs/workbench/parts/emmet/node/actions/selectItem.ts new file mode 100644 index 0000000000000..05bedf079d09a --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/selectItem.ts @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class SelectPreviousItemAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.selectPreviousItem'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'select_previous_item'); + } +} + +class SelectNextItemAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.selectNextItem'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'select_next_item'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(SelectPreviousItemAction, + SelectPreviousItemAction.ID, + nls.localize('selectPreviousItem', "Emmet: Select Previous Item"), void 0, 'Emmet: Select Previous Item')); + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(SelectNextItemAction, + SelectNextItemAction.ID, + nls.localize('selectNextItem', "Emmet: Select Next Item"), void 0, 'Emmet: Select Next Item')); diff --git a/src/vs/workbench/parts/emmet/node/actions/splitJoinTag.ts b/src/vs/workbench/parts/emmet/node/actions/splitJoinTag.ts new file mode 100644 index 0000000000000..c52785b3a5ae1 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/splitJoinTag.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class SplitJoinTagAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.splitJoinTag'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'split_join_tag'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(SplitJoinTagAction, + SplitJoinTagAction.ID, + nls.localize('splitJoinTag', "Emmet: Split/Join Tag"), void 0, 'Emmet: Split/Join Tag')); diff --git a/src/vs/workbench/parts/emmet/node/actions/updateImageSize.ts b/src/vs/workbench/parts/emmet/node/actions/updateImageSize.ts new file mode 100644 index 0000000000000..b984d4e621532 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/updateImageSize.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {BasicEmmetEditorAction} from '../emmetEditorAction'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +class UpdateImageSizeAction extends BasicEmmetEditorAction { + + static ID = 'editor.emmet.action.updateImageSize'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService, 'update_image_size'); + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(UpdateImageSizeAction, + UpdateImageSizeAction.ID, + nls.localize('updateImageSize', "Emmet: Update Image Size"), void 0, 'Emmet: Update Image Size')); diff --git a/src/vs/workbench/parts/emmet/node/actions/updateTag.ts b/src/vs/workbench/parts/emmet/node/actions/updateTag.ts new file mode 100644 index 0000000000000..491ab4bcd3777 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/updateTag.ts @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {EmmetEditorAction} from '../emmetActions'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; +import {IQuickOpenService, IInputOptions} from 'vs/workbench/services/quickopen/common/quickOpenService'; + +class UpdateTagAction extends EmmetEditorAction { + + static ID = 'editor.emmet.action.updateTag'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, + @IQuickOpenService private quickOpenService: IQuickOpenService, + @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService); + } + + public runEmmetAction(_module) { + let options: IInputOptions = { + prompt: nls.localize('enterTag', 'Enter Tag'), + placeHolder: nls.localize('tag', 'Tag') + }; + this.quickOpenService.input(options).then(tag => { + this.wrapAbbreviation(_module, tag); + }); + } + + private wrapAbbreviation(_module: any, tag) { + if (!_module.run('update_tag', this.editorAccessor, tag)) { + this.editorAccessor.noExpansionOccurred(); + } + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(UpdateTagAction, + UpdateTagAction.ID, + nls.localize('updateTag', "Emmet: Update Tag"), void 0, 'Emmet: Update Tag')); diff --git a/src/vs/workbench/parts/emmet/node/actions/wrapWithAbbreviation.ts b/src/vs/workbench/parts/emmet/node/actions/wrapWithAbbreviation.ts new file mode 100644 index 0000000000000..375790e50a97f --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/actions/wrapWithAbbreviation.ts @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import nls = require('vs/nls'); +import {EmmetEditorAction} from '../emmetActions'; + +import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; +import {IQuickOpenService, IInputOptions} from 'vs/workbench/services/quickopen/common/quickOpenService'; + +class WrapWithAbbreviationAction extends EmmetEditorAction { + + static ID = 'editor.emmet.action.wrapWithAbbreviation'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, + @IQuickOpenService private quickOpenService: IQuickOpenService, + @IConfigurationService configurationService: IConfigurationService) { + super(descriptor, editor, configurationService); + } + + public runEmmetAction(_module) { + let options: IInputOptions = { + prompt: nls.localize('enterAbbreviation', "Enter Abbreviation"), + placeHolder: nls.localize('abbreviation', "Abbreviation") + }; + this.quickOpenService.input(options).then(abbreviation => { + this.wrapAbbreviation(_module, abbreviation); + }); + } + + private wrapAbbreviation(_module: any, abbreviation) { + if (!_module.run('wrap_with_abbreviation', this.editorAccessor, abbreviation)) { + this.editorAccessor.noExpansionOccurred(); + } + } +} + +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(WrapWithAbbreviationAction, + WrapWithAbbreviationAction.ID, + nls.localize('wrapWithAbbreviationAction', "Emmet: Wrap with Abbreviation"), void 0, 'Emmet: Wrap with Abbreviation')); diff --git a/src/vs/workbench/parts/emmet/node/editorAccessor.ts b/src/vs/workbench/parts/emmet/node/editorAccessor.ts index c84943b31ed17..ad77d9d543e14 100644 --- a/src/vs/workbench/parts/emmet/node/editorAccessor.ts +++ b/src/vs/workbench/parts/emmet/node/editorAccessor.ts @@ -44,8 +44,8 @@ export class EditorAccessor implements emmet.Editor { public getCurrentLineRange(): emmet.Range { let currentLine = this.editor.getSelection().startLineNumber; return { - start: this.getOffsetFromPosition({ lineNumber: currentLine, column: 1}), - end: this.getOffsetFromPosition({ lineNumber: currentLine + 1, column: 1}) + start: this.getOffsetFromPosition({ lineNumber: currentLine, column: 1 }), + end: this.getOffsetFromPosition({ lineNumber: currentLine + 1, column: 1 }) }; } @@ -104,6 +104,7 @@ export class EditorAccessor implements emmet.Editor { } let range = new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column); this.editor.setSelection(range); + this.editor.revealRange(range); } public getSyntax(): string { @@ -126,7 +127,7 @@ export class EditorAccessor implements emmet.Editor { return null; } - public prompt(title: string): void { + public prompt(title: string): any { // } @@ -140,7 +141,7 @@ export class EditorAccessor implements emmet.Editor { } public getFilePath(): string { - return ''; + return this.editor.getModel().uri.fsPath; } private getPositionFromOffset(offset: number): IPosition { diff --git a/src/vs/workbench/parts/emmet/node/emmet.contribution.ts b/src/vs/workbench/parts/emmet/node/emmet.contribution.ts index 4c768795d3c44..793b9b849781f 100644 --- a/src/vs/workbench/parts/emmet/node/emmet.contribution.ts +++ b/src/vs/workbench/parts/emmet/node/emmet.contribution.ts @@ -2,52 +2,29 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ + 'use strict'; import nls = require('vs/nls'); import {Registry} from 'vs/platform/platform'; -import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; import {IConfigurationRegistry, Extensions as ConfigurationExtensions} from 'vs/platform/configuration/common/configurationRegistry'; -import editorCommon = require('vs/editor/common/editorCommon'); -import {ExpandAbbreviationAction, WrapWithAbbreviationAction, RemoveTagAction, UpdateTagAction} from './emmetActions'; -import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry'; -import {KeyCode} from 'vs/base/common/keyCodes'; -import {KbExpr} from 'vs/platform/keybinding/common/keybindingService'; - -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ExpandAbbreviationAction, - ExpandAbbreviationAction.ID, - nls.localize('expandAbbreviationAction', - "Emmet: Expand Abbreviation"), void 0, 'Emmet: Expand Abbreviation')); - -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(WrapWithAbbreviationAction, - WrapWithAbbreviationAction.ID, - nls.localize('wrapWithAbbreviationAction', - "Emmet: Wrap with Abbreviation"), void 0, 'Emmet: Wrap with Abbreviation')); - -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(RemoveTagAction, - RemoveTagAction.ID, - nls.localize('removeTag', - "Emmet: Remove Tag"), void 0, 'Emmet: Remove Tag')); - -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(UpdateTagAction, - UpdateTagAction.ID, - nls.localize('updateTag', - "Emmet: Update Tag"), void 0, 'Emmet: Update Tag')); - -KeybindingsRegistry.registerCommandRule({ - id: ExpandAbbreviationAction.ID, - weight: KeybindingsRegistry.WEIGHT.editorContrib(), - when: KbExpr.and( - KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), - KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION), - KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS), - KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS), - KbExpr.has('config.emmet.triggerExpansionOnTab') - ), - primary: KeyCode.Tab -}); +import './actions/expandAbbreviation'; +import './actions/balance'; +import './actions/matchingPair'; +import './actions/wrapWithAbbreviation'; +import './actions/editPoints'; +import './actions/selectItem'; +import './actions/splitJoinTag'; +import './actions/removeTag'; +import './actions/mergeLines'; +import './actions/updateImageSize'; +import './actions/evaluateMath'; +import './actions/incrementDecrement'; +import './actions/reflectCssValue'; +import './actions/base64'; +import './actions/updateTag'; // Configuration: emmet const configurationRegistry = Registry.as(ConfigurationExtensions.Configuration); @@ -65,12 +42,12 @@ configurationRegistry.registerConfiguration({ 'emmet.preferences': { 'type': 'object', 'default': {}, - 'description': nls.localize('emmetPreferences', 'Preferences used to modify behavior of some actions and resolvers of Emmet.') + 'description': nls.localize('emmetPreferences', "Preferences used to modify behavior of some actions and resolvers of Emmet.") }, 'emmet.syntaxProfiles': { 'type': 'object', 'default': {}, - 'description': nls.localize('emmetSyntaxProfiles', 'Define profile for specified syntax or use your own profile with specific rules.') + 'description': nls.localize('emmetSyntaxProfiles', "Define profile for specified syntax or use your own profile with specific rules.") } } }); diff --git a/src/vs/workbench/parts/emmet/node/emmet.d.ts b/src/vs/workbench/parts/emmet/node/emmet.d.ts index 97aa42e38ae72..f1c66a265a967 100644 --- a/src/vs/workbench/parts/emmet/node/emmet.d.ts +++ b/src/vs/workbench/parts/emmet/node/emmet.d.ts @@ -116,12 +116,15 @@ declare module 'emmet' { * Ask user to enter something * @param {String} title Dialog title * @return {String} Entered data - * @since 0.65 */ - prompt(title: string): void + prompt(title: string): string; getSelection(): string; + /** + * Returns current editor's file path + * @return {String} + */ getFilePath(): string; } diff --git a/src/vs/workbench/parts/emmet/node/emmetActions.ts b/src/vs/workbench/parts/emmet/node/emmetActions.ts index a62b3eb8c1196..8d0e41e73ac25 100644 --- a/src/vs/workbench/parts/emmet/node/emmetActions.ts +++ b/src/vs/workbench/parts/emmet/node/emmetActions.ts @@ -10,9 +10,8 @@ import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/e import {EditorAction} from 'vs/editor/common/editorAction'; import {Behaviour} from 'vs/editor/common/editorActionEnablement'; import {EditorAccessor} from './editorAccessor'; -import {IQuickOpenService, IInputOptions} from 'vs/workbench/services/quickopen/common/quickOpenService'; +import * as fileAccessor from './fileAccessor'; import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; -import nls = require('vs/nls'); interface IEmmetConfiguration { emmet: { @@ -25,7 +24,7 @@ interface IEmmetConfiguration { export abstract class EmmetEditorAction extends EditorAction { protected editorAccessor: EditorAccessor; - private configurationService:IConfigurationService = null; + private configurationService: IConfigurationService = null; constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, configurationService: IConfigurationService) { super(descriptor, editor, Behaviour.TextFocus); @@ -38,7 +37,7 @@ export abstract class EmmetEditorAction extends EditorAction { for (let key in preferences) { try { _module.preferences.set(key, preferences[key]); - } catch(err) { + } catch (err) { _module.preferences.define(key, preferences[key]); } } @@ -54,7 +53,7 @@ export abstract class EmmetEditorAction extends EditorAction { for (let key in preferences) { try { _module.preferences.remove(key); - } catch(err) { + } catch (err) { } } } @@ -64,6 +63,8 @@ export abstract class EmmetEditorAction extends EditorAction { public run(): TPromise { return new TPromise((c, e) => { require(['emmet'], (_module) => { + _module.file(fileAccessor); + try { if (!this.editorAccessor.isEmmetEnabledMode()) { this.editorAccessor.noExpansionOccurred(); @@ -80,83 +81,3 @@ export abstract class EmmetEditorAction extends EditorAction { }); } } - -export class ExpandAbbreviationAction extends EmmetEditorAction { - static ID = 'editor.emmet.action.expandAbbreviation'; - - constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { - super(descriptor, editor, configurationService); - } - - public runEmmetAction(_module) { - if (!_module.run('expand_abbreviation', this.editorAccessor)) { - this.editorAccessor.noExpansionOccurred(); - } - } -} - -export class RemoveTagAction extends EmmetEditorAction { - static ID = 'editor.emmet.action.removeTag'; - - constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService) { - super(descriptor, editor, configurationService); - } - - public runEmmetAction(_module) { - if (!_module.run('remove_tag', this.editorAccessor)) { - this.editorAccessor.noExpansionOccurred(); - } - } -} - -export class UpdateTagAction extends EmmetEditorAction { - static ID = 'editor.emmet.action.updateTag'; - - constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, - @IQuickOpenService private quickOpenService: IQuickOpenService, - @IConfigurationService configurationService: IConfigurationService) { - super(descriptor, editor, configurationService); - } - - public runEmmetAction(_module) { - let options: IInputOptions = { - prompt: nls.localize('enterTag', "Enter Tag"), - placeHolder: nls.localize('tag', "Tag") - }; - this.quickOpenService.input(options).then(tag => { - this.wrapAbbreviation(_module, tag); - }); - } - - private wrapAbbreviation(_module: any, tag) { - if (!_module.run('update_tag', this.editorAccessor, tag)) { - this.editorAccessor.noExpansionOccurred(); - } - } -} - -export class WrapWithAbbreviationAction extends EmmetEditorAction { - static ID = 'editor.emmet.action.wrapWithAbbreviation'; - - constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, - @IQuickOpenService private quickOpenService: IQuickOpenService, - @IConfigurationService configurationService: IConfigurationService) { - super(descriptor, editor, configurationService); - } - - public runEmmetAction(_module) { - let options: IInputOptions = { - prompt: nls.localize('enterAbbreviation', "Enter Abbreviation"), - placeHolder: nls.localize('abbreviation', "Abbreviation") - }; - this.quickOpenService.input(options).then(abbreviation => { - this.wrapAbbreviation(_module, abbreviation); - }); - } - - private wrapAbbreviation(_module: any, abbreviation) { - if (!_module.run('wrap_with_abbreviation', this.editorAccessor, abbreviation)) { - this.editorAccessor.noExpansionOccurred(); - } - } -} diff --git a/src/vs/workbench/parts/emmet/node/emmetEditorAction.ts b/src/vs/workbench/parts/emmet/node/emmetEditorAction.ts new file mode 100644 index 0000000000000..8a01d48b1d9c6 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/emmetEditorAction.ts @@ -0,0 +1,29 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {EmmetEditorAction} from './emmetActions'; +import {EditorAccessor} from './editorAccessor'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; + +export class BasicEmmetEditorAction extends EmmetEditorAction { + + protected editorAccessor: EditorAccessor; + private emmetActionName: string; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService, actionName: string) { + super(descriptor, editor, configurationService); + this.editorAccessor = new EditorAccessor(editor); + this.emmetActionName = actionName; + } + + public runEmmetAction(_module) { + if (!_module.run(this.emmetActionName, this.editorAccessor)) { + this.editorAccessor.noExpansionOccurred(); + } + } +} diff --git a/src/vs/workbench/parts/emmet/node/fileAccessor.ts b/src/vs/workbench/parts/emmet/node/fileAccessor.ts new file mode 100644 index 0000000000000..23bced5e27ae6 --- /dev/null +++ b/src/vs/workbench/parts/emmet/node/fileAccessor.ts @@ -0,0 +1,27 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import fs = require('fs'); +import {dirname, join} from 'vs/base/common/paths'; +import {mkdirp, writeFile} from 'vs/base/node/pfs'; + +export function createPath(parent: string, fileName: string): string { + var stat = fs.statSync(parent); + if (stat && !stat.isDirectory()) { + parent = dirname(parent); + } + + return join(parent, fileName); +}; + +export function save(file: string, content: string): any { + mkdirp(dirname(file)).then(() => { + return writeFile(file, content, 'ascii'); + }, err => { + // + }); +}