From 0790ee8159c0dc7c47ef054ad760db66b2dfb46c Mon Sep 17 00:00:00 2001
From: Lukas Holecek <hluk@email.cz>
Date: Sat, 15 Nov 2014 09:19:04 +0100
Subject: [PATCH] FakeVim: Remove superfluous cursor shape changes

Change-Id: I6996d82a0a3b0e0a7bb5ddc9732297bebd368a2d
Reviewed-by: hjk <hjk121@nokiamail.com>
---
 src/plugins/fakevim/fakevimhandler.cpp | 42 +++++++++++---------------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 0f051a7925..9ee836bc22 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -2323,23 +2323,22 @@ void FakeVimHandler::Private::focus()
     enterFakeVim();
 
     stopIncrementalFind();
-    if (!isInsertMode()) {
-        if (g.subsubmode == SearchSubSubMode || g.submode != NoSubMode || g.mode == ExMode) {
-            if (g.subsubmode == SearchSubSubMode) {
-                setPosition(m_searchStartPosition);
-                scrollToLine(m_searchFromScreenLine);
-            } else {
-                leaveVisualMode();
-                setPosition(qMin(position(), anchor()));
-            }
-            setTargetColumn();
-            setAnchor();
-            commitCursor();
+    if (isCommandLineMode()) {
+        if (g.subsubmode == SearchSubSubMode) {
+            setPosition(m_searchStartPosition);
+            scrollToLine(m_searchFromScreenLine);
+        } else {
+            leaveVisualMode();
+            setPosition(qMin(position(), anchor()));
         }
-
         leaveCurrentMode();
+        setTargetColumn();
+        setAnchor();
+        commitCursor();
+    } else {
+        clearCurrentMode();
+        updateCursorShape();
     }
-    updateCursorShape();
     updateHighlights();
 
     leaveFakeVim(false);
@@ -2379,7 +2378,6 @@ void FakeVimHandler::Private::leaveFakeVim(bool needUpdate)
             updateScrollOffset();
 
             commitCursor();
-            updateCursorShape();
         }
 
         updateMiniBuffer();
@@ -3084,6 +3082,8 @@ void FakeVimHandler::Private::commitCursor()
         tc.clearSelection();
     }
 
+    updateCursorShape();
+
     if (isVisualBlockMode()) {
         emit q->requestSetBlockSelection(tc);
     } else  {
@@ -4521,9 +4521,9 @@ bool FakeVimHandler::Private::handleWindowSubMode(const Input &input)
         return true;
 
     leaveVisualMode();
+    leaveCurrentMode();
     emit q->windowCommandRequested(input.toString(), count());
 
-    g.submode = NoSubMode;
     return true;
 }
 
@@ -6383,7 +6383,7 @@ int FakeVimHandler::Private::charClass(QChar c, bool simple) const
 void FakeVimHandler::Private::miniBufferTextEdited(const QString &text, int cursorPos,
     int anchorPos)
 {
-    if (g.subsubmode != SearchSubSubMode && g.mode != ExMode) {
+    if (!isCommandLineMode()) {
         editor()->setFocus();
     } else if (text.isEmpty()) {
         // editing cancelled
@@ -6392,7 +6392,6 @@ void FakeVimHandler::Private::miniBufferTextEdited(const QString &text, int curs
         leaveFakeVim();
 
         editor()->setFocus();
-        updateCursorShape();
     } else {
         CommandBuffer &cmdBuf = (g.mode == ExMode) ? g.commandBuffer : g.searchBuffer;
         int pos = qMax(1, cursorPos);
@@ -7243,8 +7242,6 @@ bool FakeVimHandler::Private::passEventToEditor(QEvent &event, QTextCursor &tc)
     if (!m_textedit && !m_plaintextedit)
         return false;
 
-    updateCursorShape();
-
     if (accepted)
         tc = EDITOR(textCursor());
 
@@ -7676,10 +7673,7 @@ void FakeVimHandler::Private::redo()
 
 void FakeVimHandler::Private::updateCursorShape()
 {
-    bool thinCursor = g.mode == ExMode
-            || g.subsubmode == SearchSubSubMode
-            || g.mode == InsertMode
-            || (isVisualMode() && !isVisualCharMode());
+    bool thinCursor = g.mode == InsertMode || isVisualLineMode() || isVisualBlockMode();
     EDITOR(setOverwriteMode(!thinCursor));
 }
 
-- 
GitLab