diff --git a/ChangeLog b/ChangeLog index 3b61a3ed..71d5b1ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,7 @@ V0.5.0 * On triple clicking, select the current block without selecting its newline and start and end whitespaces. * Smooth wheel scrolling (touchpad scrolling is already smooth). * Fixed a problem in backward search and replacement. + * Fixes for RTL, including a workaround for a Qt bug. V0.4.6 --------- diff --git a/NEWS b/NEWS index a3491fac..a228c8b2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ Latest version: - 9 Dec 2019, V0.5.0 + 22 Dec 2019, V0.5.0 See "ChangeLog" for changes. diff --git a/feathernotes/textedit.cpp b/feathernotes/textedit.cpp index 3fb00413..d5389f15 100644 --- a/feathernotes/textedit.cpp +++ b/feathernotes/textedit.cpp @@ -77,7 +77,7 @@ QString TextEdit::remainingSpaces (const QString& spaceTab, const QTextCursor& c qreal x = static_cast(cursorRect (tmp).right()); tmp.setPosition (tmp.position() + 1); x = static_cast(cursorRect (tmp).right()) - x; - n += qMax (qRound (x / spaceL) - 1, 0); + n += qMax (qRound (qAbs (x) / spaceL) - 1, 0); // x is negative for RTL ++i; } n += txt.count(); @@ -118,7 +118,7 @@ QTextCursor TextEdit::backTabCursor (const QTextCursor& cursor, bool twoSpace) c qreal x = static_cast(cursorRect (tmp).right()); tmp.setPosition (tmp.position() + 1); x = static_cast(cursorRect (tmp).right()) - x; - n += qMax (qRound (x / spaceL) - 1, 0); + n += qMax (qRound (qAbs (x) / spaceL) - 1, 0); ++i; } n += txt.count(); @@ -128,15 +128,14 @@ QTextCursor TextEdit::backTabCursor (const QTextCursor& cursor, bool twoSpace) c if (twoSpace) n = qMin (n, 2); tmp.setPosition (txtStart); - QChar ch = blockText.at (indx - 1); - if (ch == QChar (QChar::Space)) + if (blockText.at (indx - 1) == QChar (QChar::Space)) tmp.setPosition (txtStart - n, QTextCursor::KeepAnchor); else // the previous character is a tab { qreal x = static_cast(cursorRect (tmp).right()); tmp.setPosition (txtStart - 1, QTextCursor::KeepAnchor); x -= static_cast(cursorRect (tmp).right()); - n -= qRound (x / spaceL); + n -= qRound (qAbs (x) / spaceL); if (n < 0) n = 0; // impossible without "twoSpace" tmp.setPosition (tmp.position() - n, QTextCursor::KeepAnchor); } @@ -758,18 +757,20 @@ void TextEdit::mousePressEvent (QMouseEvent *e) txtCur.movePosition (QTextCursor::StartOfBlock); int i = 0; while (i < l && blockText.at (i).isSpace()) - { - txtCur.movePosition (QTextCursor::NextCharacter); ++i; - } + /* WARNING: QTextCursor::movePosition() can be a mess with RTL + but QTextCursor::setPosition() works fine. */ if (i < l) { + txtCur.setPosition (txtCur.position() + i); int j = l; while (j > i && blockText.at (j - 1).isSpace()) --j; - txtCur.movePosition (QTextCursor::NextCharacter, QTextCursor::KeepAnchor, j - i); - setTextCursor (txtCur); + txtCur.setPosition (txtCur.position() + j - i, QTextCursor::KeepAnchor); } + else + txtCur.setPosition (txtCur.position() + i, QTextCursor::KeepAnchor); + setTextCursor (txtCur); return; } tripleClickTimer_.invalidate();