Ver código fonte

ENH: ctkConsole: Restore positions after building the completion model

Since some implementation of updateCompletionModel (e.g python)
can display messages while building the completion model, it is
important to save and restore the positions.
Jean-Christophe Fillion-Robin 8 anos atrás
pai
commit
fb314c770f
1 arquivos alterados com 13 adições e 0 exclusões
  1. 13 0
      Libs/Widgets/ctkConsole.cpp

+ 13 - 0
Libs/Widgets/ctkConsole.cpp

@@ -544,9 +544,22 @@ void ctkConsolePrivate::updateCompleter()
     text_cursor.setPosition(this->InteractivePosition, QTextCursor::KeepAnchor);
     text_cursor.setPosition(this->InteractivePosition, QTextCursor::KeepAnchor);
     QString commandText = text_cursor.selectedText();
     QString commandText = text_cursor.selectedText();
 
 
+    // Save current positions: Since some implementation of
+    // updateCompletionModel (e.g python) can display messages
+    // while building the completion model, it is important to save
+    // and restore the positions.
+    int savedInteractivePosition = this->InteractivePosition;
+    int savedCursorPosition = this->textCursor().position();
+
     // Call the completer to update the completion model
     // Call the completer to update the completion model
     this->Completer->updateCompletionModel(commandText);
     this->Completer->updateCompletionModel(commandText);
 
 
+    // Restore positions
+    this->InteractivePosition = savedInteractivePosition;
+    QTextCursor textCursor = this->textCursor();
+    textCursor.setPosition(savedCursorPosition);
+    this->setTextCursor(textCursor);
+
     // Place and show the completer if there are available completions
     // Place and show the completer if there are available completions
     if (this->Completer->completionCount())
     if (this->Completer->completionCount())
       {
       {