Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7, 6.8, 6.9
-
None
Description
When a QTextDocument's cursor move style is Qt::LogicalMoveStyle there are cases when QTextCursor::movePosition actually moves in the opposite direction to the block's base text directionality as rendered by the document's layout.
I ran into this issue when implementing a custom QAbstractTextDocumentLayout subclass with a non-default heuristic for determining paragraph base directionality, but it is possible to force this even with a QPlainTextEdit with a little creativity:
int main(int argc, char** argv) { QApplication app(argc, argv); QPlainTextEdit textEdit; QTextDocument* document = textEdit.document(); document->setDefaultCursorMoveStyle(Qt::LogicalMoveStyle); QTextOption option; option.setTextDirection(Qt::LeftToRight); document->setDefaultTextOption(option); QTextBlockFormat format; format.setLayoutDirection(Qt::RightToLeft); QTextCursor cursor = textEdit.textCursor(); cursor.setBlockFormat(format); cursor.insertText("ABC בדיקה DEF"); textEdit.show(); return app.exec(); }
This displays Left to Right (the first logical directionality run, the "ABC", is to the left of the second one, which is the Hebrew bit):
However, if you place the text cursor between the "A" and the "B", and press the left arrow key, the cursor actually moves right, to be between "B" and "C".
The reason for this is a discrepancy between two different methods that are used to determine a text block's base direction:
- Rendering (of the text and cursor shape) is based on QTextEngine::isRightToLeft(), which only uses the block's QTextOption text direction attribute before falling back to looking for the first strongly directional character or the current IME input direction. The text option direction is set by the document's text layout class based on whatever the layout actually supports.
- QTextCusor::movePosition however relies on QTextBlock::layoutDirection which has different heuristics - it starts with the direction set in the block format, continues to the default text option's text direction, and then falls back to looking for the first strongly directed character. It aligns with how the internal class QTextDocumentLayout picks the block's direction, but this is not how other layout managers have to work...
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-130317 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
595574,3 | QTextCursor: Consider QTextBlock's layout text direction | dev | qt/qtbase | Status: NEW | 0 | 0 |