MdEditOperations: Ctrl+U to delete till the space of block

This commit is contained in:
Le Tan 2018-07-27 21:05:07 +08:00
parent 2e7b2e1e5d
commit 9b49de3ab5
3 changed files with 10 additions and 2 deletions

View File

@ -25,6 +25,7 @@ public:
// Need to call setTextCursor() to make it take effect.
static void moveCursorFirstNonSpaceCharacter(QTextCursor &p_cursor,
QTextCursor::MoveMode p_mode);
// Indent current block as next/previous block.
// Return true if some changes have been made.
// @p_cursor will be placed at the position after inserting leading spaces.

View File

@ -1383,7 +1383,7 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
case Qt::Key_AsciiCircum:
{
if (modifiers == Qt::ShiftModifier) {
// ~, go to first non-space character of current line (block).
// ^, go to first non-space character of current line (block).
tryGetRepeatToken(m_keys, m_tokens);
if (!m_keys.isEmpty()) {
// Not a valid sequence.

View File

@ -565,8 +565,15 @@ bool VMdEditOperations::handleKeyU(QKeyEvent *p_event)
if (cursor.atBlockStart()) {
ret = cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
} else {
ret = cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
int indent = VEditUtils::fetchIndentation(cursor.block());
int pib = cursor.positionInBlock();
if (pib <= indent) {
ret = cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
} else {
ret = cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, pib - indent);
}
}
if (ret) {
cursor.removeSelectedText();
}