Commit a10aabc9 authored by Joerg Bornemann's avatar Joerg Bornemann Committed by Leandro T. C. Melo
Browse files

overwrite mode support for the text editor



Change-Id: Ibe0b8123429721511ebfde15a604229982fdc5d1
Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent 5715426f
......@@ -1534,6 +1534,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
}
bool ro = isReadOnly();
const bool inOverwriteMode = overwriteMode();
if (d->m_inBlockSelectionMode) {
if (e == QKeySequence::Cut) {
......@@ -1768,6 +1769,24 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
return;
}
break;
case Qt::Key_Insert:
if (ro) break;
if ((e->modifiers() & (Qt::ControlModifier | Qt::AltModifier)) == 0) {
if (inOverwriteMode) {
d->m_autoCompleter->setAutoParenthesesEnabled(d->autoParenthesisOverwriteBackup);
d->m_autoCompleter->setSurroundWithEnabled(d->surroundWithEnabledOverwriteBackup);
setOverwriteMode(false);
} else {
d->autoParenthesisOverwriteBackup = d->m_autoCompleter->isAutoParenthesesEnabled();
d->surroundWithEnabledOverwriteBackup = d->m_autoCompleter->isSurroundWithEnabled();
d->m_autoCompleter->setAutoParenthesesEnabled(false);
d->m_autoCompleter->setSurroundWithEnabled(false);
setOverwriteMode(true);
}
e->accept();
return;
}
break;
default:
break;
......@@ -1836,7 +1855,19 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
if (doEditBlock)
cursor.beginEditBlock();
cursor.insertText(text);
if (inOverwriteMode) {
if (!doEditBlock)
cursor.beginEditBlock();
QTextBlock block = cursor.block();
int eolPos = block.position() + block.length() - 1;
int selEndPos = qMin(cursor.position() + text.length(), eolPos);
cursor.setPosition(selEndPos, QTextCursor::KeepAnchor);
cursor.insertText(text);
if (!doEditBlock)
cursor.endEditBlock();
} else {
cursor.insertText(text);
}
if (!autoText.isEmpty()) {
int pos = cursor.position();
......@@ -1865,8 +1896,10 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
if (!ro && e->key() == Qt::Key_Delete && d->m_parenthesesMatchingEnabled)
d->m_parenthesesMatchingTimer->start(50);
if (!ro && d->m_contentsChanged && !e->text().isEmpty() && e->text().at(0).isPrint())
if (!ro && d->m_contentsChanged && !e->text().isEmpty()
&& e->text().at(0).isPrint() && !inOverwriteMode) {
d->m_codeAssistant->process();
}
}
void BaseTextEditorWidget::insertCodeSnippet(const QTextCursor &cursor_arg, const QString &snippet)
......@@ -6297,6 +6330,8 @@ void BaseTextEditorWidget::inSnippetMode(bool *active)
void BaseTextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
{
if (overwriteMode())
return;
d->m_codeAssistant->invoke(kind, provider);
}
......
......@@ -243,6 +243,8 @@ public:
uint m_highlightCurrentLine : 1;
uint m_requestMarkEnabled : 1;
uint m_lineSeparatorsAllowed : 1;
uint autoParenthesisOverwriteBackup : 1;
uint surroundWithEnabledOverwriteBackup : 1;
int m_visibleWrapColumn;
QTextCharFormat m_linkFormat;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment