MCPcopy Create free account
hub / github.com/SpartanJ/eepp / checkMatchingBrackets

Method checkMatchingBrackets

src/eepp/ui/uicodeeditor.cpp:3238–3279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3236}
3237
3238void UICodeEditor::checkMatchingBrackets() {
3239 if ( !mHighlightMatchingBracket )
3240 return;
3241 static const std::vector<String::StringBaseType> open{ '{', '(', '[' };
3242 static const std::vector<String::StringBaseType> close{ '}', ')', ']' };
3243 mMatchingBrackets = TextRange();
3244 TextPosition pos = mDoc->sanitizePosition( mDoc->getSelection().start() );
3245 auto searchChar = mDoc->getChar( pos );
3246 auto isOpenIt = std::find( open.begin(), open.end(), searchChar );
3247 auto isCloseIt = std::find( close.begin(), close.end(), searchChar );
3248 if ( ( isOpenIt == open.end() && isCloseIt == close.end() ) && pos.column() > 0 ) {
3249 searchChar = mDoc->getChar( TextPosition( pos.line(), pos.column() - 1 ) );
3250 isOpenIt = std::find( open.begin(), open.end(), searchChar );
3251 isCloseIt = std::find( close.begin(), close.end(), searchChar );
3252 if ( isOpenIt != open.end() ) {
3253 pos.setColumn( pos.column() - 1 );
3254 } else if ( isCloseIt != close.end() ) {
3255 pos.setColumn( pos.column() - 1 );
3256 }
3257 }
3258
3259 if ( ( isOpenIt == open.end() && isCloseIt == close.end() ) || mDoc->isHuge() )
3260 return;
3261
3262 if ( isOpenIt != open.end() ) {
3263 size_t index = std::distance( open.begin(), isOpenIt );
3264 String::StringBaseType openBracket = open[index];
3265 String::StringBaseType closeBracket = close[index];
3266 TextPosition closePosition = mDoc->getMatchingBracket(
3267 pos, openBracket, closeBracket, TextDocument::MatchDirection::Forward, true,
3268 Milliseconds( 100 ) );
3269 mMatchingBrackets = { pos, closePosition };
3270 } else if ( isCloseIt != close.end() ) {
3271 size_t index = std::distance( close.begin(), isCloseIt );
3272 String::StringBaseType openBracket = open[index];
3273 String::StringBaseType closeBracket = close[index];
3274 TextPosition closePosition = mDoc->getMatchingBracket(
3275 pos, openBracket, closeBracket, TextDocument::MatchDirection::Backward, true,
3276 Milliseconds( 100 ) );
3277 mMatchingBrackets = { pos, closePosition };
3278 }
3279}
3280
3281Int64 UICodeEditor::getColFromXOffset( VisibleIndex visibleIndex, const Float& x ) const {
3282 if ( x < 0 || !mFont || mDoc->isLoading() )

Callers

nothing calls this directly

Calls 14

findFunction · 0.85
TextPositionFunction · 0.85
distanceFunction · 0.85
MillisecondsFunction · 0.85
sanitizePositionMethod · 0.80
getCharMethod · 0.80
columnMethod · 0.80
setColumnMethod · 0.80
isHugeMethod · 0.80
getMatchingBracketMethod · 0.80
startMethod · 0.45
getSelectionMethod · 0.45

Tested by

no test coverage detected