Skip to content

Commit

Permalink
feat: support overwrite mode.
Browse files Browse the repository at this point in the history
Change-Id: I0eef412a1f7eb8876b06cfcc5bb8320919975eda
  • Loading branch information
rekols committed Nov 23, 2018
1 parent 39ccf5e commit bc57fd9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/dtextedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,9 @@ void DTextEdit::renderAllSelections()
setExtraSelections(selections);
}

void DTextEdit::keyPressEvent(QKeyEvent *keyEvent)
void DTextEdit::keyPressEvent(QKeyEvent *e)
{
const QString &key = Utils::getKeyshortcut(keyEvent);
const QString &key = Utils::getKeyshortcut(e);

if (m_readOnlyMode) {
if (key == "J") {
Expand Down Expand Up @@ -1426,12 +1426,12 @@ void DTextEdit::keyPressEvent(QKeyEvent *keyEvent)
copyLines();
} else if (key == Utils::getKeyshortcutFromKeymap(m_settings, "editor", "togglereadonlymode")) {
toggleReadOnlyMode();
} else if (key == "Shift+/" && keyEvent->modifiers() == Qt::ControlModifier) {
keyEvent->ignore();
} else if (key == "Shift+/" && e->modifiers() == Qt::ControlModifier) {
e->ignore();
} else {
// If press another key
// the main window does not receive
keyEvent->ignore();
e->ignore();
}
} else {
if (key == Utils::getKeyshortcutFromKeymap(m_settings, "editor", "indentline")) {
Expand Down Expand Up @@ -1528,11 +1528,17 @@ void DTextEdit::keyPressEvent(QKeyEvent *keyEvent)
QPlainTextEdit::redo();
} else if (key == Utils::getKeyshortcutFromKeymap(m_settings, "window", "escape")) {
escape();
} else if (e->key() == Qt::Key_Insert) {
if (e->modifiers() == Qt::NoModifier) {
setOverwriteMode(!overwriteMode());
update();
e->accept();
}
} else {
// Post event to window widget if key match window key list.
for (auto option : m_settings->settings->group("shortcuts.window")->options()) {
if (key == m_settings->settings->option(option->key())->value().toString()) {
keyEvent->ignore();
e->ignore();
return;
}
}
Expand All @@ -1541,12 +1547,12 @@ void DTextEdit::keyPressEvent(QKeyEvent *keyEvent)
QRegularExpression re("^Alt\\+\\d");
QRegularExpressionMatch match = re.match(key);
if (match.hasMatch()) {
keyEvent->ignore();
e->ignore();
return;
}

// Text editor handle key self.
QPlainTextEdit::keyPressEvent(keyEvent);
QPlainTextEdit::keyPressEvent(e);
}
}
}
Expand Down

0 comments on commit bc57fd9

Please sign in to comment.