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)
|
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();
|
m_findReplaceDialog->closeDialog();
|
||||||
event->accept();
|
event->accept();
|
||||||
return;
|
return;
|
||||||
|
@ -297,25 +297,27 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let Ctrl+[ behave exactly like ESC.
|
||||||
bool VMdEditOperations::handleKeyBracketLeft(QKeyEvent *p_event)
|
bool VMdEditOperations::handleKeyBracketLeft(QKeyEvent *p_event)
|
||||||
{
|
{
|
||||||
// 1. If it is not in Normal state, just go back to Normal state;
|
// 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;
|
// 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;
|
bool accept = false;
|
||||||
if (p_event->modifiers() == Qt::ControlModifier) {
|
if (p_event->modifiers() == Qt::ControlModifier) {
|
||||||
if (m_keyState != KeyState::Normal) {
|
if (m_keyState != KeyState::Normal) {
|
||||||
m_pendingTimer->stop();
|
m_pendingTimer->stop();
|
||||||
setKeyState(KeyState::Normal);
|
setKeyState(KeyState::Normal);
|
||||||
m_pendingKey.clear();
|
m_pendingKey.clear();
|
||||||
|
accept = true;
|
||||||
} else {
|
} else {
|
||||||
QTextCursor cursor = m_editor->textCursor();
|
QTextCursor cursor = m_editor->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
if (cursor.hasSelection()) {
|
||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
|
accept = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accept = true;
|
|
||||||
}
|
}
|
||||||
if (accept) {
|
if (accept) {
|
||||||
p_event->accept();
|
p_event->accept();
|
||||||
@ -593,11 +595,14 @@ bool VMdEditOperations::handleKeyW(QKeyEvent *p_event)
|
|||||||
if (p_event->modifiers() == Qt::ControlModifier) {
|
if (p_event->modifiers() == Qt::ControlModifier) {
|
||||||
// Ctrl+W, delete till the start of previous word.
|
// Ctrl+W, delete till the start of previous word.
|
||||||
QTextCursor cursor = m_editor->textCursor();
|
QTextCursor cursor = m_editor->textCursor();
|
||||||
bool ret = cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
|
if (cursor.hasSelection()) {
|
||||||
if (ret) {
|
|
||||||
cursor.removeSelectedText();
|
cursor.removeSelectedText();
|
||||||
|
} else {
|
||||||
|
bool ret = cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
|
||||||
|
if (ret) {
|
||||||
|
cursor.removeSelectedText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p_event->accept();
|
p_event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user