From ab8c038ed7ae2f8fbdb899c88d195b69a806e705 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 23 Jan 2009 16:37:32 +0100
Subject: [PATCH]     Fixes:    fakwvim: fix recently broken selection in
 standalone application

---
 src/plugins/fakevim/fakevimhandler.cpp | 19 ++++++++++++++++---
 src/plugins/fakevim/fakevimplugin.cpp  |  3 ++-
 tests/manual/fakevim/main.cpp          |  4 ++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 142d2291e6d..def7aca21bf 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -158,6 +158,13 @@ QDebug &operator<<(QDebug &ts, const EditOperation &op)
     return ts;
 }
 
+QDebug &operator<<(QDebug &ts, const QList<QTextEdit::ExtraSelection> &sels)
+{
+    foreach (QTextEdit::ExtraSelection sel, sels) 
+        ts << "SEL: " << sel.cursor.anchor() << sel.cursor.position(); 
+    return ts;
+}
+        
 int lineCount(const QString &text)
 {
     //return text.count(QChar(ParagraphSeparator));
@@ -456,6 +463,7 @@ bool FakeVimHandler::Private::handleKey(int key, int unmodified, const QString &
 
 void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
 {
+    //qDebug() << "ANCHOR: " << m_anchor;
     if (m_submode == FilterSubMode) {
         int beginLine = lineForPosition(anchor());
         int endLine = lineForPosition(position());
@@ -526,10 +534,13 @@ void FakeVimHandler::Private::updateSelection()
         QTextEdit::ExtraSelection sel;
         sel.cursor = m_tc;
         sel.format = m_tc.blockCharFormat();
-        //sel.format.setFontWeight(QFont::Bold);
-        //sel.format.setFontUnderline(true);
+#if 0
+        sel.format.setFontWeight(QFont::Bold);
+        sel.format.setFontUnderline(true);
+#else
         sel.format.setForeground(Qt::white);
         sel.format.setBackground(Qt::black);
+#endif
         int cursorPos = m_tc.position();
         int anchorPos = m_marks['<'];
         //qDebug() << "POS: " << cursorPos << " ANCHOR: " << anchorPos;
@@ -566,6 +577,7 @@ void FakeVimHandler::Private::updateSelection()
             }
         }
     }
+    //qDebug() << "SELECTION: " << selections;
     emit q->selectionChanged(selections);
 }
 
@@ -834,7 +846,7 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
         m_mvcount.clear();
         m_submode = DeleteSubMode;
     } else if (key == 'd') {
-        setAnchor();
+        //setAnchor();
         leaveVisualMode();
         int beginLine = lineForPosition(m_marks['<']);
         int endLine = lineForPosition(m_marks['>']);
@@ -1819,6 +1831,7 @@ int FakeVimHandler::Private::lineForPosition(int pos) const
 
 void FakeVimHandler::Private::enterVisualMode(VisualMode visualMode)
 {
+    setAnchor();
     m_visualMode = visualMode;
     m_marks['<'] = m_tc.position();
     m_marks['>'] = m_tc.position();
diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp
index dcd3f662f0b..0b35c4fb815 100644
--- a/src/plugins/fakevim/fakevimplugin.cpp
+++ b/src/plugins/fakevim/fakevimplugin.cpp
@@ -258,8 +258,9 @@ void FakeVimPluginPrivate::removeHandler()
 
 void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
 {
+    Q_UNUSED(editor);
     //qDebug() << "OPENING: " << editor << editor->widget();
-    installHandler(editor);
+    //installHandler(editor);
 }
 
 void FakeVimPluginPrivate::editorAboutToClose(Core::IEditor *editor)
diff --git a/tests/manual/fakevim/main.cpp b/tests/manual/fakevim/main.cpp
index c67187a773b..9400fcf998f 100644
--- a/tests/manual/fakevim/main.cpp
+++ b/tests/manual/fakevim/main.cpp
@@ -24,9 +24,9 @@ public:
 public slots:
     void changeSelection(const QList<QTextEdit::ExtraSelection> &s)
     {
-        if (QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(sender()))
+        if (QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget))
             ed->setExtraSelections(s);
-        else if (QTextEdit *ed = qobject_cast<QTextEdit *>(sender()))
+        else if (QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget))
             ed->setExtraSelections(s);
     }
 
-- 
GitLab