diff --git a/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java b/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java
index 7afb9b622..ec0324877 100644
--- a/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java
+++ b/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java
@@ -382,7 +382,7 @@ public class ExEntryPanel extends JPanel implements VimCommandLine {
       catch (Throwable ex) {
         // Make sure the exception doesn't leak out of the handler, because it can break the text entry field and
         // require the editor to be closed/reopened. The worst that will happen is no incsearch highlights
-        logger.warn("Error while trying to show incsearch highlights", ex);
+        logger.error("Error while trying to show incsearch highlights", ex);
       }
     }
 
@@ -397,7 +397,7 @@ public class ExEntryPanel extends JPanel implements VimCommandLine {
         }
       }
       catch (Exception e) {
-        logger.warn("Cannot parse command for incsearch", e);
+        logger.error("Cannot parse command for incsearch", e);
       }
 
       return null;
diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt
index ebcaa8012..c64b1e5a2 100644
--- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt
+++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt
@@ -49,8 +49,16 @@ interface VimCommandLine {
    * This text represents the real content that is being processed or executed.
    */
   val actualText: String
-    get() = if (promptCharacterOffset == null) visibleText else {
-      visibleText.removeRange(promptCharacterOffset!!, promptCharacterOffset!! + 1)
+    get() {
+      val promptCharacterOffset1 = promptCharacterOffset
+      return if (promptCharacterOffset1 == null) visibleText else {
+        if (promptCharacterOffset1 >= visibleText.length) {
+          logger.error("promptCharacterOffset1 >= visibleText.length: $promptCharacterOffset1 >= ${visibleText.length}")
+          visibleText
+        } else {
+          visibleText.removeRange(promptCharacterOffset1, promptCharacterOffset1 + 1)
+        }
+      }
     }
 
   /**
@@ -98,9 +106,12 @@ interface VimCommandLine {
   fun clearPromptCharacter() {
     if (promptCharacterOffset == null) return
 
+    // Note: We have to set promptCharacterOffset to null first, because when we set the new text,
+    //   the listener will be called, which will try to get the actual text again. And, if this field isn't null,
+    //   it will get an incorrect result.
+    promptCharacterOffset = null
     setText(actualText)
     caret.offset = min(caret.offset, visibleText.length)
-    promptCharacterOffset = null
   }
 
   fun clearCurrentAction()