Don't remove keybindings of formatter and linter plugins if any document is still open.

Converting from UTF8 now checks for BOM UTF8 strings.
This commit is contained in:
Martín Lucas Golini
2023-09-15 23:47:47 -03:00
parent 044e289ba8
commit 2e80cdb77e
6 changed files with 60 additions and 23 deletions

View File

@@ -81,6 +81,12 @@ void FormatterPlugin::onRegister( UICodeEditor* editor ) {
tryRequestCapabilities( editor->getDocumentRef() );
} ) );
listeners.push_back(
editor->addEventListener( Event::OnDocumentChanged, [&, editor]( const Event* ) {
TextDocument* newDoc = editor->getDocumentRef().get();
mEditorDocs[editor] = newDoc;
} ) );
listeners.push_back( editor->addEventListener( Event::OnDocumentSave, [this](
const Event* event ) {
if ( mAutoFormatOnSave && event->getNode()->isType( UI_TYPE_CODEEDITOR ) ) {
@@ -92,15 +98,10 @@ void FormatterPlugin::onRegister( UICodeEditor* editor ) {
} ) );
mEditors.insert( { editor, listeners } );
mEditorDocs[editor] = editor->getDocumentRef().get();
}
void FormatterPlugin::onUnregister( UICodeEditor* editor ) {
for ( auto& kb : mKeyBindings ) {
editor->getKeyBindings().removeCommandKeybind( kb.first );
if ( editor->hasDocument() )
editor->getDocument().removeCommand( kb.first );
}
auto afIt = mIsAutoFormatting.find( &editor->getDocument() );
if ( afIt != mIsAutoFormatting.end() )
mIsAutoFormatting.erase( afIt );
@@ -112,6 +113,18 @@ void FormatterPlugin::onUnregister( UICodeEditor* editor ) {
if ( mShuttingDown )
return;
mEditors.erase( editor );
mEditorDocs.erase( editor );
TextDocument* doc = &editor->getDocument();
for ( auto editorIt : mEditorDocs )
if ( editorIt.second == doc )
return;
for ( auto& kb : mKeyBindings ) {
editor->getKeyBindings().removeCommandKeybind( kb.first );
if ( editor->hasDocument() )
editor->getDocument().removeCommand( kb.first );
}
}
bool FormatterPlugin::getAutoFormatOnSave() const {