Improve rename symbol.

This commit is contained in:
Martín Lucas Golini
2024-05-31 01:20:50 -03:00
parent fdb32a44e8
commit 80897f7c66
2 changed files with 7 additions and 6 deletions

View File

@@ -1199,14 +1199,15 @@ void LSPClientPlugin::renameSymbol( UICodeEditor* editor ) {
"New name (caution: not all references may be replaced)" ) );
msgBox->setTitle( editor->getUISceneNode()->i18n( "rename", "Rename" ) );
msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } );
TextPosition pos = editor->getDocument().getSelection().start();
msgBox->getTextInput()->setText(
editor->getDocument().getWordInPosition( editor->getDocument().getSelection().start() ) );
auto selection = editor->getDocument().getSelection();
TextPosition selStart = selection.start();
msgBox->getTextInput()->setText( editor->getDocument().getWordInPosition(
selection.hasSelection() ? selection.end() : selStart ) );
msgBox->getTextInput()->getDocument().selectAll();
msgBox->showWhenReady();
msgBox->addEventListener( Event::OnConfirm, [this, pos, editor, msgBox]( const Event* ) {
msgBox->addEventListener( Event::OnConfirm, [this, selStart, editor, msgBox]( const Event* ) {
String newName( msgBox->getTextInput()->getText() );
mClientManager.renameSymbol( editor->getDocumentRef()->getURI(), pos, newName );
mClientManager.renameSymbol( editor->getDocumentRef()->getURI(), selStart, newName );
msgBox->closeWindow();
} );
msgBox->addEventListener( Event::OnClose, [this]( const Event* ) {