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

Method checkAutoCloseXMLTag

src/eepp/ui/uicodeeditor.cpp:5488–5519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5486}
5487
5488bool 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
5521Int64 UICodeEditor::getCurrentColumnCount() const {
5522 Int64 count = 0;

Callers

nothing calls this directly

Calls 15

linesCountMethod · 0.80
columnMethod · 0.80
getHighlighterMethod · 0.80
getTokenTypeAtMethod · 0.80
find_last_ofMethod · 0.80
toUtf8Method · 0.80
substrMethod · 0.80
gmatchMethod · 0.80
textInputMethod · 0.80
groupMethod · 0.80
isAlreadyClosedTagFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected