codeShouldAutoPairSymmetricDelimiterInDocument function
bool
codeShouldAutoPairSymmetricDelimiterInDocument(
- TextDocument document,
- int offset, {
- bool hasSelection = false,
Implementation
bool codeShouldAutoPairSymmetricDelimiterInDocument(
TextDocument document,
int offset, {
bool hasSelection = false,
}) {
if (hasSelection) {
return true;
}
final before = offset > 0 ? document.graphemeAt(offset - 1) ?? '' : '';
final after = offset < document.length
? document.graphemeAt(offset) ?? ''
: '';
final beforeBlocksPair =
before.isNotEmpty && RegExp(r'[\w\\]').hasMatch(before);
if (beforeBlocksPair) {
return false;
}
return after.isEmpty || RegExp(r'[\s\]\)\}\>,.;:]').hasMatch(after);
}