Module: processTargets/modifiers/surroundingPair/findDelimiterPairContainingSelection
Functions
findDelimiterPairContainingSelection
▸ findDelimiterPairContainingSelection(initialIndex
, delimiterOccurrences
, acceptableDelimiters
, selectionOffsets
): SurroundingPairOffsets
| null
Looks for a surrounding pair that contains the selection, returning null if none is found.
Our approach is to first initialize two generators, one scanning rightwards and one scanning leftwards. The generator scanning rightwards starts at the first delimiter whose end offset is greater than or equal to the end offset of the selection. The generator scanning leftwards starts at the token just prior to the start token for the rightward scanner.
We start with the right generator, proceeding until we find any acceptable unmatched closing delimiter. We then advance the left generator, looking only for an unmatched opening delimiter that matches the closing delimiter we found in our rightward scan.
If the delimiter found by our leftward scan is before or equal to the start of the selection, we return the delimiter pair. If not, we loop back and scan left / right again, repeating the process until our leftward or rightward scan runs out of delimiters.
Parameters
Name | Type | Description |
---|---|---|
initialIndex | number | The index of the first delimiter to try within the delimiter occurrences list. Expected to be the index of the first delimiter whose end offset is greater than or equal to the end offset of the selection. |
delimiterOccurrences | PossibleDelimiterOccurrence [] | A list of delimiter occurrences. Expected to be sorted by offsets |
acceptableDelimiters | SimpleSurroundingPairName [] | A list of names of acceptable delimiters to look for |
selectionOffsets | Offsets | The offsets of the selection |
Returns
SurroundingPairOffsets
| null
The offsets of the surrounding pair containing the selection, or null if none is found
Defined in
processTargets/modifiers/surroundingPair/findDelimiterPairContainingSelection.ts:38