| 5486 | } |
| 5487 | |
| 5488 | bool UICodeEditor::checkAutoCloseXMLTag( const String& text ) { |
| 5489 | if ( !mAutoCloseXMLTags || text.empty() || text.size() > 1 || text[0] != '>' || |
| 5490 | mDoc->getSelection().hasSelection() ) |
| 5491 | return false; |
| 5492 | TextPosition start( mDoc->getSelection().start() ); |
| 5493 | if ( start.line() >= (Int64)mDoc->linesCount() ) |
| 5494 | return false; |
| 5495 | const auto& line = mDoc->line( start.line() ).getText(); |
| 5496 | if ( start.column() >= (Int64)line.size() || start.column() <= 1 || line.size() < 2 ) |
| 5497 | return false; |
| 5498 | if ( line[start.column() - 1] != '>' || ( line.size() > 2 && line[start.column() - 2] == '/' ) ) |
| 5499 | return false; |
| 5500 | const SyntaxDefinition& definition = |
| 5501 | mDoc->getHighlighter()->getSyntaxDefinitionFromTextPosition( start ); |
| 5502 | if ( !definition.getAutoCloseXMLTags() ) |
| 5503 | return false; |
| 5504 | SyntaxStyleType type = mDoc->getHighlighter()->getTokenTypeAt( start ); |
| 5505 | if ( type == SyntaxStyleTypes::String || type == SyntaxStyleTypes::Comment ) |
| 5506 | return false; |
| 5507 | size_t foundOpenPos = line.find_last_of( "<", start.column() - 1 ); |
| 5508 | if ( foundOpenPos == String::InvalidPos || start.column() - foundOpenPos < 1 ) |
| 5509 | return false; |
| 5510 | std::string tag( line.substr( foundOpenPos, start.column() - foundOpenPos ).toUtf8() ); |
| 5511 | LuaPattern pattern( "<([%w_%-]+).*>" ); |
| 5512 | auto match = pattern.gmatch( tag ); |
| 5513 | if ( match.matches() && !isAlreadyClosedTag( mDoc.get(), start ) ) { |
| 5514 | mDoc->textInput( String( "</" + match.group( 1 ) + ">" ) ); |
| 5515 | mDoc->setSelection( start ); |
| 5516 | return true; |
| 5517 | } |
| 5518 | return false; |
| 5519 | } |
| 5520 | |
| 5521 | Int64 UICodeEditor::getCurrentColumnCount() const { |
| 5522 | Int64 count = 0; |
nothing calls this directly
no test coverage detected