Fix invalid memory access when Event::OnDocumentChange is processed in LSPClientPlugin.

Some refactor of Keyboards Shortcuts.
This commit is contained in:
Martín Lucas Golini
2024-09-25 20:56:05 -03:00
parent f433141837
commit 92291448c0
5 changed files with 39 additions and 12 deletions

View File

@@ -1479,20 +1479,19 @@ void LSPClientPlugin::onRegister( UICodeEditor* editor ) {
} ) );
listeners.push_back(
editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) {
editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* event ) {
const DocChangedEvent* docChangedEvent = static_cast<const DocChangedEvent*>( event );
TextDocument* oldDoc = mEditorDocs[editor];
TextDocument* newDoc = editor->getDocumentRef().get();
URI docURI;
{
Lock l( mDocMutex );
docURI = oldDoc->getURI();
mDocs.erase( oldDoc );
mEditorDocs[editor] = newDoc;
}
{
Lock l( mDocCurrentSymbolsMutex );
mDocCurrentSymbols.erase( docURI );
mDocCurrentSymbols.erase( docChangedEvent->getOldDocURI() );
}
updateCurrentSymbol( editor->getDocument() );