Browse Source

let Shift+Enter to insert two spaces and a new line

Le Tan 8 years ago
parent
commit
de4e5fef8e
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/vmdeditoperations.cpp

+ 12 - 0
src/vmdeditoperations.cpp

@@ -741,6 +741,17 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
     if (p_event->modifiers() & Qt::ControlModifier) {
         m_autoIndentPos = -1;
         return false;
+    } else if (p_event->modifiers() & Qt::ShiftModifier) {
+        // Insert two spaces and a new line.
+        m_autoIndentPos = -1;
+
+        QTextCursor cursor = m_editor->textCursor();
+        cursor.beginEditBlock();
+        cursor.removeSelectedText();
+        cursor.insertText("  ");
+        cursor.endEditBlock();
+
+        // Let remaining logics handle inserting the new block.
     }
 
     // See if we need to cancel auto indent.
@@ -783,6 +794,7 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
             m_autoIndentPos = m_editor->textCursor().position();
         }
     }
+
     return handled;
 }