Kaynağa Gözat

ENH: ctkConsole: Support 2 different method to InsertCompletion

* (Default Completion) Replace the whole word under the cursor

* Insert the word and replace only from the cursor until the StartOfWord

Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
Mayeul Chassagnard 8 yıl önce
ebeveyn
işleme
be3776469e
2 değiştirilmiş dosya ile 19 ekleme ve 4 silme
  1. 9 1
      Libs/Widgets/ctkConsole.cpp
  2. 10 3
      Libs/Widgets/ctkConsole_p.h

+ 9 - 1
Libs/Widgets/ctkConsole.cpp

@@ -96,6 +96,7 @@ ctkConsolePrivate::ctkConsolePrivate(ctkConsole& object) :
   InteractivePosition(documentEnd()),
   MessageOutputSize(0),
   MultilineStatement(false), Ps1("$ "), Ps2("> "),
+  insertCompletionMethod(true),
   EditorHints(ctkConsole::AutomaticIndentation | ctkConsole::RemoveTrailingSpaces),
   ScrollbarAtBottom(false),
   CompleterShortcuts(QList<QKeySequence>() << Qt::Key_Tab),
@@ -984,7 +985,14 @@ void ctkConsolePrivate::insertCompletion(const QString& completion)
       }
     tc.clearSelection();
     tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
-    tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+    if (insertCompletionMethod)
+      {
+      tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+      }
+    else
+      {
+      tc.setPosition(endOfCompletion.position(), QTextCursor::KeepAnchor);
+      }
     tc.insertText(completion);
     endOfCompletion.setPosition(tc.position());
     this->setTextCursor(tc);

+ 10 - 3
Libs/Widgets/ctkConsole_p.h

@@ -116,9 +116,11 @@ public:
 
 public Q_SLOTS:
 
-  /// Inserts the given completion string at the cursor.  This will replace
-  /// the current word that the cursor is touching with the given text.
-  /// Determines the word using QTextCursor::StartOfWord, EndOfWord.
+  /// Inserts the given completion string at the cursor.
+  /// 2 Different ways of completion are established by \sa ctkConsolePrivate::insertCompletionMethod:
+  ///  TRUE  - Replace the current word that the cursor is touching with the given text.
+  ///          Determines the word using QTextCursor::StartOfWord, EndOfWord.
+  ///  FALSE - Just insert the word replacing only the text from the current position until StartOfWord
   void insertCompletion(const QString& text);
 
   /// Print a message
@@ -200,6 +202,11 @@ public:
   /// Secondary prompt
   QString Ps2;
 
+  /// Method to insert the completion word:
+  ///   TRUE  - Replace the whole word under the cursor
+  ///   FALSE - Insert the word and replace only from the cursor until the StartOfWord
+  bool insertCompletionMethod;
+
   ctkConsole::EditorHints EditorHints;
 
   bool ScrollbarAtBottom;