Fix reset syntax on saved or moved doc.

This commit is contained in:
Martín Lucas Golini
2024-05-01 17:20:58 -03:00
parent 209a786f2c
commit 2693160e94
3 changed files with 9 additions and 4 deletions

View File

@@ -435,6 +435,8 @@ class EE_API TextDocument {
void setNonWordChars( const String& nonWordChars );
const SyntaxDefinition& guessSyntax() const;
void resetSyntax();
bool getAutoDetectIndentType() const;

View File

@@ -375,6 +375,11 @@ bool TextDocument::hasSyntaxDefinition() const {
return !mSyntaxDefinition.getPatterns().empty();
}
const SyntaxDefinition& TextDocument::guessSyntax() const {
String header( getText( { { 0, 0 }, positionOffset( { 0, 0 }, 128 ) } ) );
return SyntaxDefinitionManager::instance()->find( mFilePath, header, mHAsCpp );
}
void TextDocument::resetSyntax() {
String header( getText( { { 0, 0 }, positionOffset( { 0, 0 }, 128 ) } ) );
std::string oldDef = mSyntaxDefinition.getLSPName();

View File

@@ -2592,8 +2592,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
refreshFolderView();
}
if ( !editor->getDocument().hasSyntaxDefinition() ) {
editor->getDocument().resetSyntax();
editor->setSyntaxDefinition( editor->getDocument().getSyntaxDefinition() );
editor->setSyntaxDefinition( editor->getDocument().guessSyntax() );
}
} );
@@ -2642,8 +2641,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
UICodeEditor* editor = event->getNode()->asType<UICodeEditor>();
editor->runOnMainThread( [this, editor] {
updateEditorTabTitle( editor );
editor->getDocument().resetSyntax();
editor->setSyntaxDefinition( editor->getDocument().getSyntaxDefinition() );
editor->setSyntaxDefinition( editor->getDocument().guessSyntax() );
} );
} );