User:Uri/Bidi editing: Difference between revisions

Line 29: Line 29:
At this point, I would like to recommend reading [http://www-306.ibm.com/software/globalization/topics/bidiui/index.jsp Guidelines of a Logical User Interface (UI) for Editing Bidirectional Text] by Matitiahu Allouche of IBM. This document presents a method for dealing with the problems associated with BiDi editing. It contains some useful definitions, as well as a detailed description of a logical-to-visual mapping algorithm (in the "[http://www-306.ibm.com/software/globalization/topics/bidiui/conversion.jsp Conversion of cursor positions]" section). This document is the basis of the current Mozilla bidi editing implementation (which I'll describe below). I'd like to thank Simon Montagu for introducing me to this document.
At this point, I would like to recommend reading [http://www-306.ibm.com/software/globalization/topics/bidiui/index.jsp Guidelines of a Logical User Interface (UI) for Editing Bidirectional Text] by Matitiahu Allouche of IBM. This document presents a method for dealing with the problems associated with BiDi editing. It contains some useful definitions, as well as a detailed description of a logical-to-visual mapping algorithm (in the "[http://www-306.ibm.com/software/globalization/topics/bidiui/conversion.jsp Conversion of cursor positions]" section). This document is the basis of the current Mozilla bidi editing implementation (which I'll describe below). I'd like to thank Simon Montagu for introducing me to this document.


==The current state of affairs==
==The current Mozilla implementation==
''This section describes my understanding of the current system. It might contain inaccuracies. If you spot any, please let me know.''
''This section describes my understanding of the current system. It might contain inaccuracies. If you spot any, please let me know.''


Mozilla represents the caret location internally as a (collapsed) selection, which consistes of:
Mozilla represents the caret location internally as a (collapsed) selection, which consistes of:
* A logical position inside the content tree (i.e. a content node and an offset into that node).
* A logical position inside the content tree (i.e. a content node and an offset into that node).
* A "hint", which is a boolean value indicating how the caret arrived at the current location. This is used for determining where to visually display the caret in cases where a single logical position can map to two different visual locations.
* A "hint", which is a boolean value indicating how the caret arrived at the current location.
 
The "hint" mechanism was originally devised as way of indicating where to display the caret when it is at the end of a wrapping line.
When arriving from the left (in LTR text), using the right arrow key, the caret should be displayed at the end of the line (after the space at which the line wraps). Pressing the right arrow key again, the caret should be moved to the beginning of the following line.
Note that the caret remains in the same logical position - so this is a simple (non-bidi) case of where one logical position can be mapped to two visual positions.
When bidi support was added to Mozilla, the "hint" mechanism's role expanded to handle other cases where one logical position maps to two visual positions, as described in the previous section.
67

edits