本文整理汇总了TypeScript中vs/editor/common/controller/wordCharacterClassifier.getMapForWordSeparators函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getMapForWordSeparators函数的具体用法?TypeScript getMapForWordSeparators怎么用?TypeScript getMapForWordSeparators使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getMapForWordSeparators函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _isAutoClosingOpenCharType
private static _isAutoClosingOpenCharType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
if (!config.autoClosingBrackets || !config.autoClosingPairsOpen.hasOwnProperty(ch)) {
return false;
}
for (let i = 0, len = selections.length; i < len; i++) {
const selection = selections[i];
if (!selection.isEmpty()) {
return false;
}
const position = selection.getPosition();
const lineText = model.getLineContent(position.lineNumber);
// Do not auto-close ' or " after a word character
if ((ch === '\'' || ch === '"') && position.column > 1) {
const wordSeparators = getMapForWordSeparators(config.wordSeparators);
const characterBeforeCode = lineText.charCodeAt(position.column - 2);
const characterBeforeType = wordSeparators.get(characterBeforeCode);
if (characterBeforeType === WordCharacterClass.Regular) {
return false;
}
}
// Only consider auto closing the pair if a space follows or if another autoclosed pair follows
const characterAfter = lineText.charAt(position.column - 1);
if (characterAfter) {
let isBeforeCloseBrace = TypeOperations._isBeforeClosingBrace(config, ch, characterAfter);
if (!isBeforeCloseBrace && !/\s/.test(characterAfter)) {
return false;
}
}
if (!model.isCheapToTokenize(position.lineNumber)) {
// Do not force tokenization
return false;
}
model.forceTokenization(position.lineNumber);
const lineTokens = model.getLineTokens(position.lineNumber);
let shouldAutoClosePair = false;
try {
shouldAutoClosePair = LanguageConfigurationRegistry.shouldAutoClosePair(ch, lineTokens, position.column);
} catch (e) {
onUnexpectedError(e);
}
if (!shouldAutoClosePair) {
return false;
}
}
return true;
}
示例2: runEditorCommand
public runEditorCommand(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
const config = editor.getConfiguration();
const wordSeparators = getMapForWordSeparators(config.wordSeparators);
const model = editor.getModel();
const selections = editor.getSelections();
const commands = selections.map((sel) => {
const deleteRange = this._delete(wordSeparators, model, sel, this._whitespaceHeuristics, this._wordNavigationType);
return new ReplaceCommand(deleteRange, '');
});
editor.pushUndoStop();
editor.executeCommands(this.id, commands);
editor.pushUndoStop();
}
示例3: parseSearchRequest
public parseSearchRequest(): SearchData {
if (this.searchString === '') {
return null;
}
// Try to create a RegExp out of the params
let multiline: boolean;
if (this.isRegex) {
multiline = SearchParams._isMultilineRegexSource(this.searchString);
} else {
multiline = (this.searchString.indexOf('\n') >= 0);
}
let regex: RegExp = null;
try {
regex = strings.createRegExp(this.searchString, this.isRegex, {
matchCase: this.matchCase,
wholeWord: false,
multiline: multiline,
global: true
});
} catch (err) {
return null;
}
if (!regex) {
return null;
}
let canUseSimpleSearch = (!this.isRegex && !multiline);
if (canUseSimpleSearch && this.searchString.toLowerCase() !== this.searchString.toUpperCase()) {
// casing might make a difference
canUseSimpleSearch = this.matchCase;
}
return new SearchData(regex, this.wordSeparators ? getMapForWordSeparators(this.wordSeparators) : null, canUseSimpleSearch ? this.searchString : null);
}
示例4: suite
suite('TextModelSearch', () => {
const usualWordSeparators = getMapForWordSeparators(USUAL_WORD_SEPARATORS);
function assertFindMatch(actual: FindMatch, expectedRange: Range, expectedMatches: string[] = null): void {
assert.deepEqual(actual, new FindMatch(expectedRange, expectedMatches));
}
function _assertFindMatches(model: TextModel, searchParams: SearchParams, expectedMatches: FindMatch[]): void {
let actual = TextModelSearch.findMatches(model, searchParams, model.getFullModelRange(), false, 1000);
assert.deepEqual(actual, expectedMatches, 'findMatches OK');
// test `findNextMatch`
let startPos = new Position(1, 1);
let match = TextModelSearch.findNextMatch(model, searchParams, startPos, false);
assert.deepEqual(match, expectedMatches[0], `findNextMatch ${startPos}`);
for (let i = 0; i < expectedMatches.length; i++) {
startPos = expectedMatches[i].range.getStartPosition();
match = TextModelSearch.findNextMatch(model, searchParams, startPos, false);
assert.deepEqual(match, expectedMatches[i], `findNextMatch ${startPos}`);
}
// test `findPrevMatch`
startPos = new Position(model.getLineCount(), model.getLineMaxColumn(model.getLineCount()));
match = TextModelSearch.findPreviousMatch(model, searchParams, startPos, false);
assert.deepEqual(match, expectedMatches[expectedMatches.length - 1], `findPrevMatch ${startPos}`);
for (let i = 0; i < expectedMatches.length; i++) {
startPos = expectedMatches[i].range.getEndPosition();
match = TextModelSearch.findPreviousMatch(model, searchParams, startPos, false);
assert.deepEqual(match, expectedMatches[i], `findPrevMatch ${startPos}`);
}
}
function assertFindMatches(text: string, searchString: string, isRegex: boolean, matchCase: boolean, wordSeparators: string, _expected: [number, number, number, number][]): void {
let expectedRanges = _expected.map(entry => new Range(entry[0], entry[1], entry[2], entry[3]));
let expectedMatches = expectedRanges.map(entry => new FindMatch(entry, null));
let searchParams = new SearchParams(searchString, isRegex, matchCase, wordSeparators);
let model = TextModel.createFromString(text);
_assertFindMatches(model, searchParams, expectedMatches);
model.dispose();
let model2 = TextModel.createFromString(text);
model2.setEOL(EndOfLineSequence.CRLF);
_assertFindMatches(model2, searchParams, expectedMatches);
model2.dispose();
}
let regularText = [
'This is some foo - bar text which contains foo and bar - as in Barcelona.',
'Now it begins a word fooBar and now it is caps Foo-isn\'t this great?',
'And here\'s a dull line with nothing interesting in it',
'It is also interesting if it\'s part of a word like amazingFooBar',
'Again nothing interesting here'
];
test('Simple find', () => {
assertFindMatches(
regularText.join('\n'),
'foo', false, false, null,
[
[1, 14, 1, 17],
[1, 44, 1, 47],
[2, 22, 2, 25],
[2, 48, 2, 51],
[4, 59, 4, 62]
]
);
});
test('Case sensitive find', () => {
assertFindMatches(
regularText.join('\n'),
'foo', false, true, null,
[
[1, 14, 1, 17],
[1, 44, 1, 47],
[2, 22, 2, 25]
]
);
});
test('Whole words find', () => {
assertFindMatches(
regularText.join('\n'),
'foo', false, false, USUAL_WORD_SEPARATORS,
[
[1, 14, 1, 17],
[1, 44, 1, 47],
[2, 48, 2, 51]
]
);
});
test('/^/ find', () => {
assertFindMatches(
regularText.join('\n'),
'^', true, false, null,
[
//.........这里部分代码省略.........
示例5: word
public static word(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, position: Position): SingleCursorState {
const wordSeparators = getMapForWordSeparators(config.wordSeparators);
let prevWord = WordOperations._findPreviousWordOnLine(wordSeparators, model, position);
let nextWord = WordOperations._findNextWordOnLine(wordSeparators, model, position);
if (!inSelectionMode) {
// Entering word selection for the first time
const isTouchingPrevWord = (prevWord && prevWord.wordType === WordType.Regular && prevWord.start <= position.column - 1 && position.column - 1 <= prevWord.end);
const isTouchingNextWord = (nextWord && nextWord.wordType === WordType.Regular && nextWord.start <= position.column - 1 && position.column - 1 <= nextWord.end);
let startColumn: number;
let endColumn: number;
if (isTouchingPrevWord) {
startColumn = prevWord.start + 1;
endColumn = prevWord.end + 1;
} else if (isTouchingNextWord) {
startColumn = nextWord.start + 1;
endColumn = nextWord.end + 1;
} else {
if (prevWord) {
startColumn = prevWord.end + 1;
} else {
startColumn = 1;
}
if (nextWord) {
endColumn = nextWord.start + 1;
} else {
endColumn = model.getLineMaxColumn(position.lineNumber);
}
}
return new SingleCursorState(
new Range(position.lineNumber, startColumn, position.lineNumber, endColumn), 0,
new Position(position.lineNumber, endColumn), 0
);
}
const isInsidePrevWord = (prevWord && prevWord.wordType === WordType.Regular && prevWord.start < position.column - 1 && position.column - 1 < prevWord.end);
const isInsideNextWord = (nextWord && nextWord.wordType === WordType.Regular && nextWord.start < position.column - 1 && position.column - 1 < nextWord.end);
let startColumn: number;
let endColumn: number;
if (isInsidePrevWord) {
startColumn = prevWord.start + 1;
endColumn = prevWord.end + 1;
} else if (isInsideNextWord) {
startColumn = nextWord.start + 1;
endColumn = nextWord.end + 1;
} else {
startColumn = position.column;
endColumn = position.column;
}
let lineNumber = position.lineNumber;
let column: number;
if (cursor.selectionStart.containsPosition(position)) {
column = cursor.selectionStart.endColumn;
} else if (position.isBeforeOrEqual(cursor.selectionStart.getStartPosition())) {
column = startColumn;
let possiblePosition = new Position(lineNumber, column);
if (cursor.selectionStart.containsPosition(possiblePosition)) {
column = cursor.selectionStart.endColumn;
}
} else {
column = endColumn;
let possiblePosition = new Position(lineNumber, column);
if (cursor.selectionStart.containsPosition(possiblePosition)) {
column = cursor.selectionStart.startColumn;
}
}
return cursor.move(true, lineNumber, column, 0);
}
示例6: compositionEndWithInterceptors
public static compositionEndWithInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[]): EditOperationResult {
if (config.autoClosingQuotes === 'never') {
return null;
}
let commands: ICommand[] = [];
for (let i = 0; i < selections.length; i++) {
if (!selections[i].isEmpty()) {
continue;
}
const position = selections[i].getPosition();
const lineText = model.getLineContent(position.lineNumber);
const ch = lineText.charAt(position.column - 2);
if (config.autoClosingPairsClose.hasOwnProperty(ch)) { // first of all, it's a closing tag
if (ch === config.autoClosingPairsClose[ch] /** isEqualPair */) {
const lineTextBeforeCursor = lineText.substr(0, position.column - 2);
const chCntBefore = this._countNeedlesInHaystack(lineTextBeforeCursor, ch);
if (chCntBefore % 2 === 1) {
continue; // it pairs with the opening tag.
}
}
}
// As we are not typing in a new character, so we don't need to run `_runAutoClosingCloseCharType`
// Next step, let's try to check if it's an open char.
if (config.autoClosingPairsOpen.hasOwnProperty(ch)) {
if (isQuote(ch) && position.column > 2) {
const wordSeparators = getMapForWordSeparators(config.wordSeparators);
const characterBeforeCode = lineText.charCodeAt(position.column - 3);
const characterBeforeType = wordSeparators.get(characterBeforeCode);
if (characterBeforeType === WordCharacterClass.Regular) {
continue;
}
}
const characterAfter = lineText.charAt(position.column - 1);
if (characterAfter) {
let isBeforeCloseBrace = TypeOperations._isBeforeClosingBrace(config, ch, characterAfter);
let shouldAutoCloseBefore = isQuote(ch) ? config.shouldAutoCloseBefore.quote : config.shouldAutoCloseBefore.bracket;
if (isBeforeCloseBrace) {
// In normal auto closing logic, we will auto close if the cursor is even before a closing brace intentionally.
// However for composition mode, we do nothing here as users might clear all the characters for composition and we don't want to do a unnecessary auto close.
// Related: microsoft/vscode#57250.
continue;
}
if (!shouldAutoCloseBefore(characterAfter)) {
continue;
}
}
if (!model.isCheapToTokenize(position.lineNumber)) {
// Do not force tokenization
continue;
}
model.forceTokenization(position.lineNumber);
const lineTokens = model.getLineTokens(position.lineNumber);
let shouldAutoClosePair = false;
try {
shouldAutoClosePair = LanguageConfigurationRegistry.shouldAutoClosePair(ch, lineTokens, position.column - 1);
} catch (e) {
onUnexpectedError(e);
}
if (shouldAutoClosePair) {
const closeCharacter = config.autoClosingPairsOpen[ch];
commands[i] = new ReplaceCommandWithOffsetCursorState(selections[i], closeCharacter, 0, -closeCharacter.length);
}
}
}
return new EditOperationResult(EditOperationType.Typing, commands, {
shouldPushStackElementBefore: true,
shouldPushStackElementAfter: false
});
}