Skip to content

Commit

Permalink
Fixes for RTL (including a workaround for a Qt bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujan committed Dec 22, 2019
1 parent b2305e3 commit fde2324
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Latest version:

9 Dec 2019, V0.5.0
22 Dec 2019, V0.5.0

See "ChangeLog" for changes.
21 changes: 11 additions & 10 deletions feathernotes/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ QString TextEdit::remainingSpaces (const QString& spaceTab, const QTextCursor& c
qreal x = static_cast<qreal>(cursorRect (tmp).right());
tmp.setPosition (tmp.position() + 1);
x = static_cast<qreal>(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();
Expand Down Expand Up @@ -118,7 +118,7 @@ QTextCursor TextEdit::backTabCursor (const QTextCursor& cursor, bool twoSpace) c
qreal x = static_cast<qreal>(cursorRect (tmp).right());
tmp.setPosition (tmp.position() + 1);
x = static_cast<qreal>(cursorRect (tmp).right()) - x;
n += qMax (qRound (x / spaceL) - 1, 0);
n += qMax (qRound (qAbs (x) / spaceL) - 1, 0);
++i;
}
n += txt.count();
Expand All @@ -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<qreal>(cursorRect (tmp).right());
tmp.setPosition (txtStart - 1, QTextCursor::KeepAnchor);
x -= static_cast<qreal>(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);
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fde2324

Please sign in to comment.