提交 bc2dcbf9 编写于 作者: A Alex Dima

Move `CharacterPair` to `modes.ts` and adopt in `onEnter.ts`

上级 4a7d555d
......@@ -649,6 +649,8 @@ export interface ITaskSupport {
clean?():TPromise<void>;
}
export type CharacterPair = [string, string];
export interface IAutoClosingPairConditional extends IAutoClosingPair {
notIn?: string[];
}
......
......@@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import {Bracket, IAutoClosingPairConditional, ISuggestion} from 'vs/editor/common/modes';
import {CharacterPair} from 'vs/editor/common/modes/supports/richEditBrackets';
import {CharacterPair, Bracket, IAutoClosingPairConditional, ISuggestion} from 'vs/editor/common/modes';
/*
* This module exports common types and functionality shared between
......
......@@ -10,10 +10,9 @@
*/
import * as objects from 'vs/base/common/objects';
import {Bracket, IAutoClosingPairConditional} from 'vs/editor/common/modes';
import {Bracket, IAutoClosingPairConditional, CharacterPair} from 'vs/editor/common/modes';
import * as monarchCommon from 'vs/editor/common/modes/monarch/monarchCommon';
import {ILanguage, ILanguageBracket} from 'vs/editor/common/modes/monarch/monarchTypes';
import {CharacterPair} from 'vs/editor/common/modes/supports/richEditBrackets';
/*
* Type helpers
......
......@@ -8,14 +8,9 @@ import {onUnexpectedError} from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import {Position} from 'vs/editor/common/core/position';
import {IPosition, ITextModel, ITokenizedModel} from 'vs/editor/common/editorCommon';
import {IEnterAction, ILineContext, IMode, IRichEditOnEnter, IndentAction} from 'vs/editor/common/modes';
import {IEnterAction, ILineContext, IMode, IRichEditOnEnter, IndentAction, CharacterPair} from 'vs/editor/common/modes';
import {handleEvent} from 'vs/editor/common/modes/supports';
export interface IBracketPair {
open: string;
close: string;
}
export interface IIndentationRules {
decreaseIndentPattern: RegExp;
increaseIndentPattern: RegExp;
......@@ -30,12 +25,14 @@ export interface IOnEnterRegExpRules {
}
export interface IOnEnterSupportOptions {
brackets?: IBracketPair[];
brackets?: CharacterPair[];
indentationRules?: IIndentationRules;
regExpRules?: IOnEnterRegExpRules[];
}
interface IProcessedBracketPair extends IBracketPair {
interface IProcessedBracketPair {
open: string;
close: string;
openRegExp: RegExp;
closeRegExp: RegExp;
}
......@@ -54,18 +51,18 @@ export class OnEnterSupport implements IRichEditOnEnter {
constructor(modeId: string, opts?:IOnEnterSupportOptions) {
opts = opts || {};
opts.brackets = opts.brackets || [
{ open: '(', close: ')' },
{ open: '{', close: '}' },
{ open: '[', close: ']' }
['(', ')'],
['{', '}'],
['[', ']']
];
this._modeId = modeId;
this._brackets = opts.brackets.map((bracket) => {
return {
open: bracket.open,
openRegExp: OnEnterSupport._createOpenBracketRegExp(bracket.open),
close: bracket.close,
closeRegExp: OnEnterSupport._createCloseBracketRegExp(bracket.close),
open: bracket[0],
openRegExp: OnEnterSupport._createOpenBracketRegExp(bracket[0]),
close: bracket[1],
closeRegExp: OnEnterSupport._createCloseBracketRegExp(bracket[1]),
};
});
this._regExpRules = opts.regExpRules || [];
......
......@@ -9,8 +9,6 @@ import {Range} from 'vs/editor/common/core/range';
import {IRichEditBracket} from 'vs/editor/common/editorCommon';
import * as modes from 'vs/editor/common/modes';
export type CharacterPair = [string, string];
interface ISimpleInternalBracket {
open: string;
close: string;
......@@ -25,7 +23,7 @@ export class RichEditBrackets implements modes.IRichEditBrackets {
public textIsBracket: {[text:string]:IRichEditBracket;};
public textIsOpenBracket: {[text:string]:boolean;};
constructor(modeId: string, brackets: CharacterPair[]) {
constructor(modeId: string, brackets: modes.CharacterPair[]) {
this.brackets = brackets.map((b) => {
return {
modeId: modeId,
......
......@@ -4,13 +4,13 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import {ICommentsConfiguration, IRichEditBrackets, IRichEditCharacterPair, IRichEditOnEnter, IRichEditSupport} from 'vs/editor/common/modes';
import {ICommentsConfiguration, IRichEditBrackets, IRichEditCharacterPair, IRichEditOnEnter, IRichEditSupport, CharacterPair} from 'vs/editor/common/modes';
import {NullMode} from 'vs/editor/common/modes/nullMode';
import {CharacterPairSupport} from 'vs/editor/common/modes/supports/characterPair';
import {ICharacterPairContribution} from 'vs/editor/common/modes/supports/characterPair';
import {BracketElectricCharacterSupport, IBracketElectricCharacterContribution} from 'vs/editor/common/modes/supports/electricCharacter';
import {IIndentationRules, IOnEnterRegExpRules, IOnEnterSupportOptions, OnEnterSupport} from 'vs/editor/common/modes/supports/onEnter';
import {CharacterPair, RichEditBrackets} from 'vs/editor/common/modes/supports/richEditBrackets';
import {RichEditBrackets} from 'vs/editor/common/modes/supports/richEditBrackets';
export interface CommentRule {
lineComment?: string;
......@@ -82,22 +82,18 @@ export class RichEditSupport implements IRichEditSupport {
// on enter
let onEnter: IOnEnterSupportOptions = {};
let empty = true;
let {brackets, indentationRules, onEnterRules} = conf;
if (brackets) {
if (conf.brackets) {
empty = false;
onEnter.brackets = brackets.map(pair => {
let [open, close] = pair;
return { open, close };
});
onEnter.brackets = conf.brackets;
}
if (indentationRules) {
if (conf.indentationRules) {
empty = false;
onEnter.indentationRules = indentationRules;
onEnter.indentationRules = conf.indentationRules;
}
if (onEnterRules) {
if (conf.onEnterRules) {
empty = false;
onEnter.regExpRules = <any>onEnterRules;
onEnter.regExpRules = conf.onEnterRules;
}
if (!empty) {
......
......@@ -5,8 +5,8 @@
'use strict';
import * as assert from 'assert';
import {IndentAction} from 'vs/editor/common/modes';
import {IBracketPair, OnEnterSupport} from 'vs/editor/common/modes/supports/onEnter';
import {IndentAction, CharacterPair} from 'vs/editor/common/modes';
import {OnEnterSupport} from 'vs/editor/common/modes/supports/onEnter';
suite('OnEnter', () => {
......@@ -38,9 +38,9 @@ suite('OnEnter', () => {
});
test('uses brackets', () => {
var brackets: IBracketPair[] = [
{ open:'(', close:')' },
{ open:'begin', close:'end' }
var brackets: CharacterPair[] = [
['(', ')'],
['begin', 'end']
];
var support = new OnEnterSupport(null, {
brackets: brackets
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册