提交 67bbb46e 编写于 作者: E Erich Gamma

Partial fix for #9500

上级 673d75e7
......@@ -16,18 +16,20 @@ import emmet = require('emmet');
export class EditorAccessor implements emmet.Editor {
editor: ICommonCodeEditor;
syntaxProfiles: any;
private _hasMadeEdits: boolean;
emmetSupportedModes = ['html', 'razor', 'css', 'less', 'sass', 'scss', 'stylus', 'xml', 'xsl', 'jade', 'handlebars', 'ejs', 'hbs', 'jsx', 'tsx', 'erb', 'php', 'twig'];
constructor(editor: ICommonCodeEditor) {
constructor(editor: ICommonCodeEditor, syntaxProfiles: any) {
this.editor = editor;
this.syntaxProfiles = syntaxProfiles;
this._hasMadeEdits = false;
}
public isEmmetEnabledMode(): boolean {
let syntax = this.getSyntax();
return (this.emmetSupportedModes.indexOf(syntax) !== -1);
return this.emmetSupportedModes.indexOf(this.getSyntax()) !== -1;
}
public getSelectionRange(): emmet.Range {
......@@ -119,6 +121,13 @@ export class EditorAccessor implements emmet.Editor {
let position = this.editor.getSelection().getStartPosition();
let modeId = this.editor.getModel().getModeIdAtPosition(position.lineNumber, position.column);
let syntax = modeId.split('.').pop();
// user can overwrite the syntax using the emmet syntaxProfiles setting
let profile = this.getSyntaxProfile(syntax);
if (profile) {
return profile;
}
if (/\b(razor|handlebars|erb|php|hbs|ejs|twig)\b/.test(syntax)) { // treat like html
return 'html';
}
......@@ -131,6 +140,13 @@ export class EditorAccessor implements emmet.Editor {
return syntax;
}
private getSyntaxProfile(syntax: string): string {
const profile = this.syntaxProfiles[syntax];
if (profile && typeof profile === 'string') {
return profile;
}
}
public getProfileName(): string {
return null;
}
......
......@@ -61,9 +61,9 @@ class LazyEmmet {
_emmet.preferences.define(key, preferences[key]);
}
}
let syntaxProfile = configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles;
let syntaxProfiles = configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles;
_emmet.profile.reset();
_emmet.loadProfiles(syntaxProfile);
_emmet.loadProfiles(syntaxProfiles);
}
private resetEmmetPreferences(configurationService:IConfigurationService, _emmet: typeof emmet) {
......@@ -110,7 +110,7 @@ export abstract class EmmetEditorAction extends EditorAction {
const configurationService = accessor.get(IConfigurationService);
const instantiationService = accessor.get(IInstantiationService);
let editorAccessor = new EditorAccessor(editor);
let editorAccessor = new EditorAccessor(editor, configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles);
if (!editorAccessor.isEmmetEnabledMode()) {
this.noExpansionOccurred(editor);
return ;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册