Browse Source

vim-mode: bug fix in block cursor mode

Le Tan 8 years ago
parent
commit
7f230312df
2 changed files with 6 additions and 2 deletions
  1. 4 2
      src/utils/vvim.cpp
  2. 2 0
      src/vtextdocumentlayout.cpp

+ 4 - 2
src/utils/vvim.cpp

@@ -3987,8 +3987,6 @@ void VVim::processPasteAction(QList<Token> &p_tokens, bool p_pasteBefore)
 
             changed = true;
         }
-
-        setMode(VimMode::Normal);
     } else {
         // Normal mode.
         if (isBlock) {
@@ -4041,6 +4039,10 @@ void VVim::processPasteAction(QList<Token> &p_tokens, bool p_pasteBefore)
 
     cursor.endEditBlock();
 
+    if (!checkMode(VimMode::Normal)) {
+        setMode(VimMode::Normal);
+    }
+
     if (changed) {
         m_editor->setTextCursorW(cursor);
     }

+ 2 - 0
src/vtextdocumentlayout.cpp

@@ -314,6 +314,7 @@ QVector<QTextLayout::FormatRange> VTextDocumentLayout::formatRangeFromSelection(
             // a position to specify the line. that's more convenience in usage.
             QTextLayout::FormatRange o;
             QTextLine l = p_block.layout()->lineForTextPosition(range.cursor.position() - blpos);
+            Q_ASSERT(l.isValid());
             o.start = l.textStart();
             o.length = l.textLength();
             if (o.start + o.length == bllen - 1) {
@@ -1087,6 +1088,7 @@ int VTextDocumentLayout::getTextWidthWithinTextLine(const QTextLayout *p_layout,
                                                     int p_length)
 {
     QTextLine line = p_layout->lineForTextPosition(p_pos);
+    Q_ASSERT(line.isValid());
     Q_ASSERT(p_pos + p_length <= line.textStart() + line.textLength());
     return line.cursorToX(p_pos + p_length) - line.cursorToX(p_pos);
 }