| 3236 | } |
| 3237 | |
| 3238 | void 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 | |
| 3281 | Int64 UICodeEditor::getColFromXOffset( VisibleIndex visibleIndex, const Float& x ) const { |
| 3282 | if ( x < 0 || !mFont || mDoc->isLoading() ) |
nothing calls this directly
no test coverage detected