mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Refine Ctrl+B and Ctrl+I
If there are ** or * after current cursor, just skip them or it when hitting Ctrl+B or Ctrl+I. Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
3ce9f02007
commit
9d975c4bdb
@ -382,9 +382,22 @@ bool VMdEditOperations::handleKeyB(QKeyEvent *p_event)
|
|||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
} else {
|
} else {
|
||||||
// Insert **** and place cursor in the middle.
|
// Insert **** and place cursor in the middle.
|
||||||
|
// Or if there are two * after current cursor, just skip them.
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
cursor.insertText("****");
|
int pos = cursor.positionInBlock();
|
||||||
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 2);
|
bool hasStars = false;
|
||||||
|
QString text = cursor.block().text();
|
||||||
|
if (pos <= text.size() - 2) {
|
||||||
|
if (text[pos] == '*' && text[pos + 1] == '*') {
|
||||||
|
hasStars = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasStars) {
|
||||||
|
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 2);
|
||||||
|
} else {
|
||||||
|
cursor.insertText("****");
|
||||||
|
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 2);
|
||||||
|
}
|
||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
@ -441,9 +454,22 @@ bool VMdEditOperations::handleKeyI(QKeyEvent *p_event)
|
|||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
} else {
|
} else {
|
||||||
// Insert ** and place cursor in the middle.
|
// Insert ** and place cursor in the middle.
|
||||||
|
// Or if there are one * after current cursor, just skip it.
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
cursor.insertText("**");
|
int pos = cursor.positionInBlock();
|
||||||
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
|
bool hasStar = false;
|
||||||
|
QString text = cursor.block().text();
|
||||||
|
if (pos <= text.size() - 1) {
|
||||||
|
if (text[pos] == '*') {
|
||||||
|
hasStar = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasStar) {
|
||||||
|
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1);
|
||||||
|
} else {
|
||||||
|
cursor.insertText("**");
|
||||||
|
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
|
||||||
|
}
|
||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user