mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
refine editing shortcuts
1. Ctrl+[ behaves exactly like ESC; 2. Ctrl+W should delete the selected text if there has one. Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
336d9ad109
commit
46988f5bef
@ -874,7 +874,9 @@ void VMainWindow::resizeEvent(QResizeEvent *event)
|
||||
|
||||
void VMainWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape) {
|
||||
if (event->key() == Qt::Key_Escape
|
||||
|| (event->key() == Qt::Key_BracketLeft
|
||||
&& event->modifiers() == Qt::ControlModifier)) {
|
||||
m_findReplaceDialog->closeDialog();
|
||||
event->accept();
|
||||
return;
|
||||
|
@ -297,26 +297,28 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Let Ctrl+[ behave exactly like ESC.
|
||||
bool VMdEditOperations::handleKeyBracketLeft(QKeyEvent *p_event)
|
||||
{
|
||||
// 1. If it is not in Normal state, just go back to Normal state;
|
||||
// 2. If it is already Normal state, try to clear selection;
|
||||
// 3. Anyway, we accept this event.
|
||||
// 3. Otherwise, ignore this event and let parent handles it.
|
||||
bool accept = false;
|
||||
if (p_event->modifiers() == Qt::ControlModifier) {
|
||||
if (m_keyState != KeyState::Normal) {
|
||||
m_pendingTimer->stop();
|
||||
setKeyState(KeyState::Normal);
|
||||
m_pendingKey.clear();
|
||||
accept = true;
|
||||
} else {
|
||||
QTextCursor cursor = m_editor->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
cursor.clearSelection();
|
||||
m_editor->setTextCursor(cursor);
|
||||
}
|
||||
}
|
||||
accept = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (accept) {
|
||||
p_event->accept();
|
||||
}
|
||||
@ -593,11 +595,14 @@ bool VMdEditOperations::handleKeyW(QKeyEvent *p_event)
|
||||
if (p_event->modifiers() == Qt::ControlModifier) {
|
||||
// Ctrl+W, delete till the start of previous word.
|
||||
QTextCursor cursor = m_editor->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
cursor.removeSelectedText();
|
||||
} else {
|
||||
bool ret = cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
|
||||
if (ret) {
|
||||
cursor.removeSelectedText();
|
||||
}
|
||||
|
||||
}
|
||||
p_event->accept();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user