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

Remove `regexBrackets`

上级 b3e9164e
......@@ -685,27 +685,6 @@ export interface IBracketPair {
isElectric:boolean;
}
/**
* Regular expression based brackets. These are always electric.
*/
export interface IRegexBracketPair {
openTrigger?: string; // The character that will trigger the evaluation of 'open'.
open: RegExp; // The definition of when an opening brace is detected. This regex is matched against the entire line upto, and including the last typed character (the trigger character).
closeComplete?: string; // How to complete a matching open brace. Matches from 'open' will be expanded, e.g. '</$1>'
matchCase?: boolean; // If set to true, the case of the string captured in 'open' will be detected an applied also to 'closeComplete'.
// This is useful for cases like BEGIN/END or begin/end where the opening and closing phrases are unrelated.
// For identical phrases, use the $1 replacement syntax above directly in closeComplete, as it will
// include the proper casing from the captured string in 'open'.
// Upper/Lower/Camel cases are detected. Camel case dection uses only the first two characters and assumes
// that 'closeComplete' contains wors separated by spaces (e.g. 'End Loop')
closeTrigger?: string; // The character that will trigger the evaluation of 'close'.
close?: RegExp; // The definition of when a closing brace is detected. This regex is matched against the entire line upto, and including the last typed character (the trigger character).
tokenType?: string; // The type of the token. Matches from 'open' or 'close' will be expanded, e.g. 'keyword.$1'.
// Only used to auto-(un)indent a closing bracket.
}
export interface IAutoClosingPairConditional extends IAutoClosingPair {
notIn?: string[];
}
......
......@@ -20,7 +20,6 @@ export interface IDocComment {
export interface IBracketElectricCharacterContribution {
brackets: Modes.IBracketPair[];
regexBrackets?: Modes.IRegexBracketPair[];
docComment?: IDocComment;
caseInsensitive?: boolean;
embeddedElectricCharacters?: string[];
......@@ -35,8 +34,7 @@ export class BracketElectricCharacterSupport implements Modes.IRichEditElectricC
constructor(modeId: string, contribution: IBracketElectricCharacterContribution) {
this._modeId = modeId;
this.contribution = contribution;
this.brackets = new Brackets(contribution.brackets, contribution.regexBrackets,
contribution.docComment, contribution.caseInsensitive);
this.brackets = new Brackets(contribution.brackets, contribution.docComment, contribution.caseInsensitive);
}
public getElectricCharacters(): string[]{
......@@ -64,7 +62,6 @@ enum Lettercase { Unknown, Lowercase, Uppercase, Camelcase}
export class Brackets {
private brackets: Modes.IBracketPair[];
private regexBrackets: Modes.IRegexBracketPair[];
private docComment: IDocComment;
private caseInsensitive: boolean;
......@@ -77,10 +74,9 @@ export class Brackets {
* - stringIsBracket
*
*/
constructor(brackets: Modes.IBracketPair[], regexBrackets: Modes.IRegexBracketPair[] = [], docComment: IDocComment = null,
constructor(brackets: Modes.IBracketPair[], docComment: IDocComment = null,
caseInsensitive: boolean = false) {
this.brackets = brackets;
this.regexBrackets = regexBrackets ? regexBrackets : [];
this.docComment = docComment ? docComment : null;
this.caseInsensitive = caseInsensitive ? caseInsensitive : false;
}
......@@ -99,19 +95,6 @@ export class Brackets {
}
}
// Regexp brackets (always electric)
var regexBracketPair: Modes.IRegexBracketPair;
length = this.regexBrackets.length;
for (var i = 0; i < length; i++) {
regexBracketPair = this.regexBrackets[i];
if (regexBracketPair.openTrigger) {
result.push( this.caseInsensitive ? regexBracketPair.openTrigger.toLowerCase() : regexBracketPair.openTrigger);
}
if (regexBracketPair.closeTrigger) {
result.push( this.caseInsensitive ? regexBracketPair.closeTrigger.toLowerCase() : regexBracketPair.closeTrigger);
}
}
// Doc comments
if (this.docComment){
result.push(this.docComment.open.charAt(this.docComment.open.length - 1));
......@@ -140,7 +123,6 @@ export class Brackets {
}
return (this._onElectricCharacterDocComment(context, offset) ||
this._onElectricCharacterRegexBrackets(context, offset) ||
this._onElectricCharacterStandardBrackets(context, offset));
}
......@@ -195,47 +177,6 @@ export class Brackets {
return { matchBracketType: tokenType };
}
private _onElectricCharacterRegexBrackets(context: Modes.ILineContext, offset: number): Modes.IElectricAction {
// Handle regular expression brackets
var line = context.getLineContent();
for (var i = 0; i < this.regexBrackets.length; ++i) {
var regexBracket = this.regexBrackets[i];
// Check if an open bracket matches the line up to offset.
if (regexBracket.openTrigger && regexBracket.closeComplete &&
(line.charAt(offset) === regexBracket.openTrigger ||
(this.caseInsensitive && line.charAt(offset).toLowerCase() === regexBracket.openTrigger.toLowerCase()))) {
var matchLine = line.substr(0, offset+1);
var matches = matchLine.match(regexBracket.open);
if (matches) {
// Auto-complete with closing bracket.
var finalText = matches[0].replace(regexBracket.open, regexBracket.closeComplete);
if (regexBracket.matchCase) {
finalText = this._changeLettercase(finalText, this._detectLetercase(matches[0]));
}
return { appendText: finalText };
}
}
// Check if a close bracket matches the line up to offset.
if (regexBracket.closeTrigger &&
(line.charAt(offset) === regexBracket.closeTrigger ||
(this.caseInsensitive && line.charAt(offset).toLowerCase() === regexBracket.closeTrigger.toLowerCase()))) {
var matches = matchLine.match(regexBracket.close);
if (matches) {
// Auto-indent to the level of the opening bracket.
var properCaseMatch = matches[0];
if (this.caseInsensitive) {
properCaseMatch = properCaseMatch.toLowerCase();
}
return { matchBracketType: properCaseMatch.replace(regexBracket.close, regexBracket.tokenType)};
}
}
}
return null;
}
private _onElectricCharacterDocComment(context: Modes.ILineContext, offset: number): Modes.IElectricAction {
// We only auto-close, so do nothing if there is no closing part.
if (!this.docComment || !this.docComment.close) {
......
......@@ -47,33 +47,33 @@ export interface ILanguageBracket {
token: string; // token class
}
export interface ILanguageAutoComplete {
triggers: string; // characters that trigger auto completion rules
match: string|RegExp; // autocomplete if this matches
complete: string; // complete with this string
}
// export interface ILanguageAutoComplete {
// triggers: string; // characters that trigger auto completion rules
// match: string|RegExp; // autocomplete if this matches
// complete: string; // complete with this string
// }
export interface ILanguageAutoIndent {
match: string|RegExp; // auto indent if this matches on enter
matchAfter: string|RegExp; // and auto-outdent if this matches on the next line
}
// export interface ILanguageAutoIndent {
// match: string|RegExp; // auto indent if this matches on enter
// matchAfter: string|RegExp; // and auto-outdent if this matches on the next line
// }
/**
* Regular expression based brackets. These are always electric.
*/
export interface IRegexBracketPair {
openTrigger?: string; // The character that will trigger the evaluation of 'open'.
open: RegExp; // The definition of when an opening brace is detected. This regex is matched against the entire line upto, and including the last typed character (the trigger character).
closeComplete?: string; // How to complete a matching open brace. Matches from 'open' will be expanded, e.g. '</$1>'
matchCase?: boolean; // If set to true, the case of the string captured in 'open' will be detected an applied also to 'closeComplete'.
// This is useful for cases like BEGIN/END or begin/end where the opening and closing phrases are unrelated.
// For identical phrases, use the $1 replacement syntax above directly in closeComplete, as it will
// include the proper casing from the captured string in 'open'.
// Upper/Lower/Camel cases are detected. Camel case dection uses only the first two characters and assumes
// that 'closeComplete' contains wors separated by spaces (e.g. 'End Loop')
// /**
// * Regular expression based brackets. These are always electric.
// */
// export interface IRegexBracketPair {
// // openTrigger?: string; // The character that will trigger the evaluation of 'open'.
// open: RegExp; // The definition of when an opening brace is detected. This regex is matched against the entire line upto, and including the last typed character (the trigger character).
// closeComplete?: string; // How to complete a matching open brace. Matches from 'open' will be expanded, e.g. '</$1>'
// matchCase?: boolean; // If set to true, the case of the string captured in 'open' will be detected an applied also to 'closeComplete'.
// // This is useful for cases like BEGIN/END or begin/end where the opening and closing phrases are unrelated.
// // For identical phrases, use the $1 replacement syntax above directly in closeComplete, as it will
// // include the proper casing from the captured string in 'open'.
// // Upper/Lower/Camel cases are detected. Camel case dection uses only the first two characters and assumes
// // that 'closeComplete' contains wors separated by spaces (e.g. 'End Loop')
closeTrigger?: string; // The character that will trigger the evaluation of 'close'.
close?: RegExp; // The definition of when a closing brace is detected. This regex is matched against the entire line upto, and including the last typed character (the trigger character).
tokenType?: string; // The type of the token. Matches from 'open' or 'close' will be expanded, e.g. 'keyword.$1'.
// Only used to auto-(un)indent a closing bracket.
}
// // closeTrigger?: string; // The character that will trigger the evaluation of 'close'.
// close?: RegExp; // The definition of when a closing brace is detected. This regex is matched against the entire line upto, and including the last typed character (the trigger character).
// tokenType?: string; // The type of the token. Matches from 'open' or 'close' will be expanded, e.g. 'keyword.$1'.
// // Only used to auto-(un)indent a closing bracket.
// }
......@@ -28,58 +28,8 @@ suite('Editor Modes - Auto Indentation', () => {
assert.equal(brackets.stringIsBracket(')'), true);
});
test('Case insensitive regular expressions', () => {
var brackets = new autoIndentation.Brackets([],
[
{ tokenType: 'tag-$1',
openTrigger: '>',
open: /<(\w[\w\d]*)(\s+.*[^\/]>|\s*>)[^<]*$/i,
closeComplete: '</$1>',
closeTrigger: '>',
close: /<\/(\w[\w\d]*)\s*>$/i }
], null, true);
assert.equal(brackets.onElectricCharacter(modesUtil.createLineContextFromTokenText([
{ text: '<', type: 'delim' },
{ text: 'tag', type: 'tag', bracket: modes.Bracket.Open },
{ text: '>', type: 'delim' }
]), 4).appendText, '</tag>');
assert.equal(brackets.onElectricCharacter(modesUtil.createLineContextFromTokenText([
{ text: '</', type: 'delim' },
{ text: 'TAg', type: 'tag', bracket: modes.Bracket.Close},
{ text: '>', type: 'delim' },
]), 5).matchBracketType, 'tag-tag');
});
test('Case insensitive regular expressions and case matching auto completion', () => {
var brackets = new autoIndentation.Brackets([],
[
{ tokenType: 'sub',
openTrigger: 'b',
open: /^(|.*\s)sub/i,
closeComplete: ' end sub',
matchCase: true
}
], null, true);
assert.equal(brackets.onElectricCharacter(modesUtil.createLineContextFromTokenText([
{ text: 'sub', type: '' }
]), 2).appendText, ' end sub');
assert.equal(brackets.onElectricCharacter(modesUtil.createLineContextFromTokenText([
{ text: 'Sub', type: '' }
]), 2).appendText, ' End Sub');
assert.equal(brackets.onElectricCharacter(modesUtil.createLineContextFromTokenText([
{ text: 'SUB', type: '' }
]), 2).appendText, ' END SUB');
});
test('Doc comments', () => {
var brackets = new autoIndentation.Brackets([], [],
var brackets = new autoIndentation.Brackets([],
{ scope: 'doc', open: '/**', lineStart: ' * ', close: ' */' });
assert.equal(brackets.onElectricCharacter(modesUtil.createLineContextFromTokenText([
......
......@@ -136,12 +136,6 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
__electricCharacterSupport: {
brackets: [],
regexBrackets: [{
tokenType: htmlMode.htmlTokenTypes.getTag('$1'),
open: new RegExp(`<(?!(?:${htmlMode.EMPTY_ELEMENTS.join("|")}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
closeComplete: '</$1>',
close: /<\/(\w[\w\d]*)\s*>$/i
}],
caseInsensitive: true,
embeddedElectricCharacters: ['*', '}', ']', ')']
},
......
......@@ -352,12 +352,6 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode<W> i
__electricCharacterSupport: {
brackets: [],
regexBrackets: [{
tokenType: htmlTokenTypes.getTag('$1'),
open: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join("|")}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
closeComplete: '</$1>',
close: /<\/(\w[\w\d]*)\s*>$/i
}],
caseInsensitive: true,
embeddedElectricCharacters: ['*', '}', ']', ')']
},
......
......@@ -86,12 +86,6 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
__electricCharacterSupport: {
brackets: [],
regexBrackets: [{
tokenType: htmlMode.htmlTokenTypes.getTag('$1'),
open: new RegExp(`<(?!(?:${htmlMode.EMPTY_ELEMENTS.join("|")}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
closeComplete: '</$1>',
close: /<\/(\w[\w\d]*)\s*>$/i
}],
caseInsensitive: true,
embeddedElectricCharacters: ['*', '}', ']', ')']
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册