Kaynağa Gözat

ENH: ctkConsole: Improve updateCommandBuffer to limit content of text

Jean-Christophe Fillion-Robin 8 yıl önce
ebeveyn
işleme
97ec773fe5
2 değiştirilmiş dosya ile 8 ekleme ve 5 silme
  1. 4 3
      Libs/Widgets/ctkConsole.cpp
  2. 4 2
      Libs/Widgets/ctkConsole_p.h

+ 4 - 3
Libs/Widgets/ctkConsole.cpp

@@ -581,9 +581,10 @@ void ctkConsolePrivate::updateCompleter()
 }
 
 //-----------------------------------------------------------------------------
-void ctkConsolePrivate::updateCommandBuffer()
+void ctkConsolePrivate::updateCommandBuffer(int commandLength)
 {
-  this->commandBuffer() = this->toPlainText().mid(this->InteractivePosition);
+  this->commandBuffer() =
+      this->toPlainText().mid(this->InteractivePosition, commandLength);
 }
 
 //-----------------------------------------------------------------------------
@@ -778,7 +779,7 @@ void ctkConsolePrivate::insertCompletion(const QString& completion)
   int cursorOffset = this->Completer->cursorOffset(shellLine);
   tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, cursorOffset);
   this->setTextCursor(tc);
-  this->updateCommandBuffer();
+  this->updateCommandBuffer(completion.length());
 }
 
 //-----------------------------------------------------------------------------

+ 4 - 2
Libs/Widgets/ctkConsole_p.h

@@ -72,8 +72,10 @@ public:
 
   void updateCompleter();
   
-  /// Update the contents of the command buffer from the contents of the widget
-  void updateCommandBuffer();
+  /// Update the contents of the command buffer from the contents of the widget.
+  /// If \a commandLength is specified, buffer is updated limiting the content
+  /// of the widget.
+  void updateCommandBuffer(int commandLength = -1);
   
   /// Replace the contents of the command buffer, updating the display
   void replaceCommandBuffer(const QString& text);