Commit 6c6f78e8 authored by Simon Depiets's avatar Simon Depiets

Ensure the cursor is visible after a text operation

BUG: 404169
BUG: 403131
BUG: 405008
parent 638acfb3
......@@ -380,11 +380,9 @@ void Catalog::updateApprovedEmptyIndexCache()
while (pos.entry < limit) {
if (m_storage->isEmpty(pos))
d._emptyIndex << pos.entry;
if (!isApproved(pos))
{
if (!isApproved(pos)) {
d._nonApprovedIndex << pos.entry;
if (!m_storage->isEmpty(pos))
{
if (!m_storage->isEmpty(pos)) {
d._nonApprovedNonEmptyIndex << pos.entry;
}
}
......@@ -917,14 +915,11 @@ TargetState Catalog::setState(const DocPosition& pos, TargetState state)
m_storage->setApproved(pos, approved);
}
if (!approved)
{
if (!approved) {
insertInList(d._nonApprovedIndex, pos.entry);
if (!m_storage->isEmpty(pos))
insertInList(d._nonApprovedNonEmptyIndex, pos.entry);
}
else
{
} else {
d._nonApprovedIndex.removeAll(pos.entry);
d._nonApprovedNonEmptyIndex.removeAll(pos.entry);
}
......
......@@ -185,8 +185,7 @@ QString GettextStorage::sourceWithPlurals(const DocPosition& pos, bool truncateF
QString pluralString;
for (int i = 0; i < plurals.size(); i++) {
QString str = plurals.at(i);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......@@ -199,8 +198,7 @@ QString GettextStorage::sourceWithPlurals(const DocPosition& pos, bool truncateF
return pluralString;
} else {
QString str = m_entries.at(pos.entry).msgid(pos.form);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......@@ -215,8 +213,7 @@ QString GettextStorage::targetWithPlurals(const DocPosition& pos, bool truncateF
QString pluralString;
for (int i = 0; i < plurals.size(); i++) {
QString str = plurals.at(i);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......@@ -229,8 +226,7 @@ QString GettextStorage::targetWithPlurals(const DocPosition& pos, bool truncateF
return pluralString;
} else {
QString str = m_entries.at(pos.entry).msgstr(pos.form);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......
......@@ -282,8 +282,7 @@ QString TsStorage::target(const DocPosition& pos) const
QString TsStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
QString str = source(pos);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......@@ -293,8 +292,7 @@ QString TsStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFirstL
QString TsStorage::targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
QString str = target(pos);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......
......@@ -513,8 +513,7 @@ QString XliffStorage::target(const DocPosition& pos) const
QString XliffStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
QString str = source(pos);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......@@ -524,8 +523,7 @@ QString XliffStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFir
QString XliffStorage::targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
QString str = target(pos);
if (truncateFirstLine)
{
if (truncateFirstLine) {
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
......
......@@ -59,7 +59,7 @@ public:
* c'tor for glossary view
*/
explicit FlowLayout(User user = standard, QWidget *signalingWidget = nullptr,
const QVector<QAction*>& actions = QVector<QAction*>(), int margin = 0, int spacing = -1);
const QVector<QAction*>& actions = QVector<QAction*>(), int margin = 0, int spacing = -1);
~FlowLayout() override;
......
......@@ -286,7 +286,7 @@ void EditorView::unwrap(TranslationUnitTextEdit* editor)
void EditorView::insertTerm(const QString& term)
{
m_targetTextEdit->insertPlainText(term);
m_targetTextEdit->insertPlainTextWithCursorCheck(term);
m_targetTextEdit->setFocus();
}
......
......@@ -308,9 +308,7 @@ EditorTab* LokalizeMainWindow::fileOpen(QString filePath, int entry, bool setAsA
if (!state.isEmpty()) {
w->restoreState(QByteArray::fromBase64(state));
m_lastEditorState = state;
}
else
{
} else {
//Dummy restore to "initialize" widgets
w->restoreState(w->saveState());
}
......
/* ****************************************************************************
This file is part of Lokalize
Copyright (C) 2007-2014 by Nick Shaforostoff <shafff@ukr.net>
Copyright (C) 2007-2014 by Nick Shaforostoff <shafff@ukr.net>
2018-2019 by Simon Depiets <sdepiets@gmail.com>
This program is free software; you can redistribute it and/or
......
......@@ -685,7 +685,7 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
} else {
QString text = source->text();
text.remove(TAGRANGE_IMAGE_SYMBOL);
insertPlainText(text);
insertPlainTextWithCursorCheck(text);
}
}
......@@ -777,9 +777,9 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
else
KTextEdit::keyPressEvent(keyEvent);
} else if (keyEvent->key() == Qt::Key_Space && (keyEvent->modifiers()&Qt::AltModifier))
insertPlainText(QChar(0x00a0U));
insertPlainTextWithCursorCheck(QChar(0x00a0U));
else if (keyEvent->key() == Qt::Key_Minus && (keyEvent->modifiers()&Qt::AltModifier))
insertPlainText(QChar(0x0000AD));
insertPlainTextWithCursorCheck(QChar(0x0000AD));
//BEGIN clever editing
else if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
if (m_completionBox && m_completionBox->isVisible()) {
......@@ -823,7 +823,7 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
}
if (!str.isEmpty()) {
ins += '\n';
insertPlainText(ins);
insertPlainTextWithCursorCheck(ins);
} else
KTextEdit::keyPressEvent(keyEvent);
} else if (m_catalog->type() != Gettext)
......@@ -868,7 +868,7 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
}
KTextEdit::keyPressEvent(keyEvent);
} else if (keyEvent->key() == Qt::Key_Tab)
insertPlainText(QStringLiteral("\\t"));
insertPlainTextWithCursorCheck(QStringLiteral("\\t"));
else
KTextEdit::keyPressEvent(keyEvent);
//END clever editing
......@@ -876,12 +876,17 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
void TranslationUnitTextEdit::keyReleaseEvent(QKeyEvent * e) {
if ((e->key() == Qt::Key_Alt) && m_currentUnicodeNumber >= 32) {
insertPlainText(QChar(m_currentUnicodeNumber));
insertPlainTextWithCursorCheck(QChar(m_currentUnicodeNumber));
m_currentUnicodeNumber = 0;
} else
KTextEdit::keyReleaseEvent(e);
}
void TranslationUnitTextEdit::insertPlainTextWithCursorCheck(const QString & text) {
insertPlainText(text);
KTextEdit::ensureCursorVisible();
}
QString TranslationUnitTextEdit::toPlainText() {
QTextCursor cursor = textCursor();
cursor.select(QTextCursor::Document);
......@@ -1074,7 +1079,7 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
#ifdef Q_OS_MAC
if (event->type() == QEvent::InputMethod) {
QInputMethodEvent* e = static_cast<QInputMethodEvent*>(event);
insertPlainText(e->commitString());
insertPlainTextWithCursorCheck(e->commitString());
e->accept();
return true;
}
......@@ -1163,7 +1168,7 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
if (posInMsgStr != -1 && (posInMsgStr = target.indexOf(tag.cap(0), posInMsgStr)) == -1) {
if (immediate) {
insertPlainText(txt->text());
insertPlainTextWithCursorCheck(txt->text());
return;
}
menu.setActiveAction(txt);
......@@ -1176,7 +1181,7 @@ void insertContent(QTextCursor& cursor, const CatalogString& catStr, const Catal
//txt=menu.exec(_msgidEdit->mapToGlobal(QPoint(0,0)));
txt = menu.exec(mapToGlobal(cursorRect().bottomRight()));
if (txt)
insertPlainText(txt->text());
insertPlainTextWithCursorCheck(txt->text());
}
}
......
......@@ -64,6 +64,7 @@ public:
Q_UNUSED(block);
return true;
}
void insertPlainTextWithCursorCheck(const QString &text);
public slots:
void reflectApprovementState();
......
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