Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves bracket logic from text model into BracketPairsImpl (IBracketPairs) #136024

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/editor/common/controller/cursorTypeOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ export class TypeOperations {

if (electricAction.matchOpenBracket) {
let endColumn = (lineTokens.getLineContent() + ch).lastIndexOf(electricAction.matchOpenBracket) + 1;
let match = model.findMatchingBracketUp(electricAction.matchOpenBracket, {
let match = model.bracketPairs.findMatchingBracketUp(electricAction.matchOpenBracket, {
lineNumber: position.lineNumber,
column: endColumn
});
Expand Down
50 changes: 0 additions & 50 deletions src/vs/editor/common/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,6 @@ export class FindMatch {
}
}

/**
* @internal
*/
export interface IFoundBracket {
range: Range;
open: string[];
close: string[];
isOpen: boolean;
}

/**
* Describes the behavior of decorations when typing/editing near their edges.
* Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior`
Expand Down Expand Up @@ -968,46 +958,6 @@ export interface ITextModel {
*/
getWordUntilPosition(position: IPosition): IWordAtPosition;

/**
* Find the matching bracket of `request` up, counting brackets.
* @param request The bracket we're searching for
* @param position The position at which to start the search.
* @return The range of the matching bracket, or null if the bracket match was not found.
* @internal
*/
findMatchingBracketUp(bracket: string, position: IPosition): Range | null;

/**
* Find the first bracket in the model before `position`.
* @param position The position at which to start the search.
* @return The info for the first bracket before `position`, or null if there are no more brackets before `positions`.
* @internal
*/
findPrevBracket(position: IPosition): IFoundBracket | null;

/**
* Find the first bracket in the model after `position`.
* @param position The position at which to start the search.
* @return The info for the first bracket after `position`, or null if there are no more brackets after `positions`.
* @internal
*/
findNextBracket(position: IPosition): IFoundBracket | null;

/**
* Find the enclosing brackets that contain `position`.
* @param position The position at which to start the search.
* @internal
*/
findEnclosingBrackets(position: IPosition, maxDuration?: number): [Range, Range] | null;

/**
* Given a `position`, if the position is on top or near a bracket,
* find the matching bracket of that bracket and return the ranges of both brackets.
* @param position The position at which to look for a bracket.
* @internal
*/
matchBracket(position: IPosition): [Range, Range] | null;

/**
* @internal
*/
Expand Down
56 changes: 51 additions & 5 deletions src/vs/editor/common/model/bracketPairs/bracketPairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,70 @@
*--------------------------------------------------------------------------------------------*/

import { Event } from 'vs/base/common/event';
import { Range } from 'vs/editor/common/core/range';
import { IPosition } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';

export interface IBracketPairs {
/**
* Is fired when bracket pairs change, either due to a text or a settings change.
*/
onDidChange: Event<void>;

/**
* Gets all bracket pairs that intersect the given position.
* The result is sorted by the start position.
*/
getBracketPairsInRange(range: Range): BracketPairInfo[];
getBracketPairsInRange(range: IRange): BracketPairInfo[];

/**
* Gets all bracket pairs that intersect the given position.
* The result is sorted by the start position.
*/
getBracketPairsInRangeWithMinIndentation(range: Range): BracketPairWithMinIndentationInfo[];
getBracketPairsInRangeWithMinIndentation(range: IRange): BracketPairWithMinIndentationInfo[];

getBracketsInRange(range: Range): BracketInfo[];
getBracketsInRange(range: IRange): BracketInfo[];

onDidChange: Event<void>;
/**
* Find the matching bracket of `request` up, counting brackets.
* @param request The bracket we're searching for
* @param position The position at which to start the search.
* @return The range of the matching bracket, or null if the bracket match was not found.
*/
findMatchingBracketUp(bracket: string, position: IPosition): Range | null;

/**
* Find the first bracket in the model before `position`.
* @param position The position at which to start the search.
* @return The info for the first bracket before `position`, or null if there are no more brackets before `positions`.
*/
findPrevBracket(position: IPosition): IFoundBracket | null;

/**
* Find the first bracket in the model after `position`.
* @param position The position at which to start the search.
* @return The info for the first bracket after `position`, or null if there are no more brackets after `positions`.
*/
findNextBracket(position: IPosition): IFoundBracket | null;

/**
* Find the enclosing brackets that contain `position`.
* @param position The position at which to start the search.
*/
findEnclosingBrackets(position: IPosition, maxDuration?: number): [Range, Range] | null;

/**
* Given a `position`, if the position is on top or near a bracket,
* find the matching bracket of that bracket and return the ranges of both brackets.
* @param position The position at which to look for a bracket.
*/
matchBracket(position: IPosition): [Range, Range] | null;
}

export interface IFoundBracket {
range: Range;
open: string[];
close: string[];
isOpen: boolean;
}

export class BracketInfo {
Expand Down
Loading