OSDN Git Service

Completion: Make sure activation sequence has correct length
authorLeandro Melo <leandro.melo@nokia.com>
Fri, 20 May 2011 12:08:34 +0000 (14:08 +0200)
committerLeandro T. C. Melo <leandro.melo@nokia.com>
Fri, 20 May 2011 15:11:44 +0000 (17:11 +0200)
This is necessary for the very first characters typed on the editor
in the case the activation sequence length is greater than one.

Change-Id: I9ec611f816278795b7ac3f75913fccf5a52165bf
Reviewed-on: http://codereview.qt.nokia.com/47
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
src/plugins/texteditor/codeassist/codeassistant.cpp

index e59b6e4..a78b717 100644 (file)
@@ -126,6 +126,7 @@ private:
     bool m_receivedContentWhileWaiting;
     QTimer m_automaticProposalTimer;
     CompletionSettings m_settings;
+    static const QChar m_null;
 };
 
 } // TextEditor
@@ -133,6 +134,8 @@ private:
 // --------------------
 // CodeAssistantPrivate
 // --------------------
+const QChar CodeAssistantPrivate::m_null;
+
 CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
     : m_q(assistant)
     , m_textEditor(0)
@@ -373,7 +376,10 @@ CompletionAssistProvider *CodeAssistantPrivate::identifyActivationSequence()
         const int length = provider->activationCharSequenceLength();
         if (length == 0)
             continue;
-        const QString &sequence = m_textEditor->textAt(m_textEditor->position() - length, length);
+        QString sequence = m_textEditor->textAt(m_textEditor->position() - length, length);
+        const int lengthDiff = length - sequence.length();
+        for (int j = 0; j < lengthDiff; ++j)
+            sequence.prepend(m_null);
         if (provider->isActivationCharSequence(sequence))
             return provider;
     }