mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Crash fix when formatting a document while searching for a string in the document.
This commit is contained in:
@@ -19,6 +19,9 @@ struct EE_API SyntaxToken {
|
||||
};
|
||||
|
||||
struct EE_API SyntaxTokenPosition {
|
||||
// TODO: type should be the hash of the name of the type. Using std::string takes at least
|
||||
// 40 bytes per token vs 4 bytes. It's much easier to debug a string than a hash and that's
|
||||
// the reason why we keep it for the moment.
|
||||
std::string type;
|
||||
Int64 pos{ 0 };
|
||||
size_t len{ 0 };
|
||||
|
||||
@@ -165,6 +165,11 @@ UICodeEditor::UICodeEditor( const bool& autoRegisterBaseCommands,
|
||||
UICodeEditor( "codeeditor", autoRegisterBaseCommands, autoRegisterBaseKeybindings ) {}
|
||||
|
||||
UICodeEditor::~UICodeEditor() {
|
||||
if ( getUISceneNode()->hasThreadPool() ) {
|
||||
Uint64 tag = reinterpret_cast<Uint64>( this );
|
||||
getUISceneNode()->getThreadPool()->removeWithTag( tag );
|
||||
}
|
||||
|
||||
if ( mCurrentMenu ) {
|
||||
mCurrentMenu->clearEventListener();
|
||||
mCurrentMenu = nullptr;
|
||||
@@ -1587,8 +1592,7 @@ void UICodeEditor::onDocumentLineCountChange( const size_t&, const size_t& ) {
|
||||
void UICodeEditor::onDocumentLineChanged( const Int64& lineNumber ) {
|
||||
mDoc->getHighlighter()->invalidate( lineNumber );
|
||||
|
||||
if ( !mHighlightWord.isEmpty() )
|
||||
updateHighlightWordCache();
|
||||
updateHighlightWordCache();
|
||||
}
|
||||
|
||||
void UICodeEditor::onDocumentUndoRedo( const TextDocument::UndoRedo& ) {
|
||||
@@ -2513,11 +2517,16 @@ const TextSearchParams& UICodeEditor::getHighlightWord() const {
|
||||
}
|
||||
|
||||
void UICodeEditor::updateHighlightWordCache() {
|
||||
if ( mHighlightWord.isEmpty() )
|
||||
return;
|
||||
|
||||
if ( getUISceneNode()->hasThreadPool() ) {
|
||||
Uint64 tag = reinterpret_cast<Uint64>( this );
|
||||
getUISceneNode()->getThreadPool()->removeWithTag( tag );
|
||||
getUISceneNode()->getThreadPool()->run(
|
||||
[this]() {
|
||||
if ( mDoc->isRunningTransaction() )
|
||||
return;
|
||||
mHighlightWordProcessing = true;
|
||||
mHighlightWordCache = mDoc->findAll(
|
||||
mHighlightWord.escapeSequences ? String::unescape( mHighlightWord.text )
|
||||
@@ -2527,6 +2536,8 @@ void UICodeEditor::updateHighlightWordCache() {
|
||||
},
|
||||
[this]( const auto& ) { mHighlightWordProcessing = false; }, tag );
|
||||
} else {
|
||||
if ( mDoc->isRunningTransaction() )
|
||||
return;
|
||||
mHighlightWordCache =
|
||||
mDoc->findAll( mHighlightWord.escapeSequences ? String::unescape( mHighlightWord.text )
|
||||
: mHighlightWord.text,
|
||||
|
||||
@@ -236,6 +236,9 @@ class App : public UICodeEditorSplitter::Client {
|
||||
t.setCommand( "open-command-palette", [&] { mUniversalLocator->showCommandPalette(); } );
|
||||
t.setCommand( "project-build-start", [&] {
|
||||
if ( mProjectBuildManager && mStatusBuildOutputController ) {
|
||||
if ( mProjectBuildManager->isBuilding() ) {
|
||||
mProjectBuildManager->cancelBuild();
|
||||
}
|
||||
mProjectBuildManager->buildCurrentConfig( mStatusBuildOutputController.get() );
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -369,6 +369,7 @@ void FormatterPlugin::formatDoc( UICodeEditor* editor ) {
|
||||
auto pos = doc->getSelection();
|
||||
auto scroll = editor->getScroll();
|
||||
doc->selectAll();
|
||||
doc->setRunningTransaction( true );
|
||||
doc->textInput( data );
|
||||
doc->setSelection( pos );
|
||||
editor->setScroll( scroll );
|
||||
@@ -377,6 +378,7 @@ void FormatterPlugin::formatDoc( UICodeEditor* editor ) {
|
||||
doc->save();
|
||||
mIsAutoFormatting[doc.get()] = false;
|
||||
}
|
||||
doc->setRunningTransaction( false );
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -402,9 +404,11 @@ void FormatterPlugin::runFormatter( UICodeEditor* editor, const Formatter& forma
|
||||
TextPosition pos = doc->getSelection().start();
|
||||
auto scroll = editor->getScroll();
|
||||
doc->selectAll();
|
||||
doc->setRunningTransaction( true );
|
||||
doc->textInput( res.result );
|
||||
doc->setSelection( pos );
|
||||
editor->setScroll( scroll );
|
||||
doc->setRunningTransaction( false );
|
||||
} );
|
||||
return;
|
||||
}
|
||||
@@ -441,9 +445,11 @@ void FormatterPlugin::runFormatter( UICodeEditor* editor, const Formatter& forma
|
||||
TextPosition pos = doc->getSelection().start();
|
||||
auto scroll = editor->getScroll();
|
||||
doc->selectAll();
|
||||
doc->setRunningTransaction( true );
|
||||
doc->textInput( data );
|
||||
doc->setSelection( pos );
|
||||
editor->setScroll( scroll );
|
||||
doc->setRunningTransaction( false );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user