summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Badea <catalin.badea392@gmail.com>2012-04-13 19:49:39 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-04-14 15:44:35 (GMT)
commitd4517116fc71d1b2d5967004757630293613e928 (patch)
treecfb8d66bb781548c5b60d037ef8372f2e82b921b /Swift/QtUI/QtChatWindow.cpp
parent2dcdee8e9f657c7f5c5d5c507373fd328beaa568 (diff)
downloadswift-contrib-d4517116fc71d1b2d5967004757630293613e928.zip
swift-contrib-d4517116fc71d1b2d5967004757630293613e928.tar.bz2
Improve tab completion
Remember last tab completion suggestion and use it for cycling through all completion candidates. Resolves: #1070 License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swift/QtUI/QtChatWindow.cpp')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index cf520ee..5223ddb 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -149,10 +149,12 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
inputClearing_ = false;
contactIsTyping_ = false;
+ tabCompletion_ = false;
connect(input_, SIGNAL(unhandledKeyPressEvent(QKeyEvent*)), this, SLOT(handleKeyPressEvent(QKeyEvent*)));
connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
connect(input_, SIGNAL(textChanged()), this, SLOT(handleInputChanged()));
+ connect(input_, SIGNAL(cursorPositionChanged()), this, SLOT(handleCursorPositionChanged()));
setFocusProxy(input_);
logRosterSplitter_->setFocusProxy(input_);
midBar->setFocusProxy(input_);
@@ -288,11 +290,15 @@ void QtChatWindow::tabComplete() {
if (!completer_) {
return;
}
-// QTextDocument* document = input_->document();
- QTextCursor cursor = input_->textCursor();
- cursor.select(QTextCursor::WordUnderCursor);
+
+ QTextCursor cursor;
+ if (tabCompleteCursor_.hasSelection()) {
+ cursor = tabCompleteCursor_;
+ } else {
+ cursor = input_->textCursor();
+ cursor.select(QTextCursor::WordUnderCursor);
+ }
QString root = cursor.selectedText();
- bool firstWord = cursor.selectionStart() == 0;
if (root.isEmpty()) {
return;
}
@@ -300,14 +306,17 @@ void QtChatWindow::tabComplete() {
if (root == suggestion) {
return;
}
+ tabCompletion_ = true;
cursor.beginEditBlock();
cursor.removeSelectedText();
+ int oldPosition = cursor.position();
+
cursor.insertText(suggestion);
- if (firstWord) {
- // cursor.insertText(":");
- }
- //cursor.insertText(" ");
+ tabCompleteCursor_ = cursor;
+ tabCompleteCursor_.setPosition(oldPosition, QTextCursor::KeepAnchor);
+
cursor.endEditBlock();
+ tabCompletion_ = false;
}
void QtChatWindow::setRosterModel(Roster* roster) {
@@ -699,6 +708,13 @@ void QtChatWindow::handleInputChanged() {
}
}
+void QtChatWindow::handleCursorPositionChanged() {
+ if (tabCompletion_) {
+ return;
+ }
+ tabCompleteCursor_.clearSelection();
+}
+
void QtChatWindow::show() {
if (parentWidget() == NULL) {
QWidget::show();