We’re starting to use CM6 in Pontoon, Mozilla’s localization system. In this context, we need to deal with some pretty deep bidirectionality, for example localized messages that as a whole are right-to-left, but may include HTML elements using a Latin left-to-right script, which may have attributes with localized right-to-left values, but then include left-to-right placeholders. All of this on a single line, of course.
I’ve been able to make this work for the presentation by using a parser that understands about elements, quoted attribute values and placeholders, and a small stack of decorator plugins so that I can get the right prioritised nesting of marks to result in the desired <span dir=...>
wrappers, but this doesn’t seem to work quite right for left/right arrow navigation, which is now appears broken near directionality boundaries where weakly directional characters are often assigned the wrong direction.
From inspecting the code, enabling perLineTextDirection
appears to mean that the overall direction is set by the direction of the <div class="cm-line">
, and then an inspection of the text characters results in a set of directional spans that determine the current mapping of left/right to forward/backward.
So there’s a mismatch here that I think needs solving, and I’m not sure exactly what would be the best way to do so. There are at least three options that I see as possible:
- Somehow allow for the
DocView.p.textDirectionAt(pos)
to look at the lowest-level<span>
forpos
and use its directionality rather than rely on the direction of the line + text bidi spans. - Rather than assigning
dir="ltr"
and similar mark decorators to spans, insert corresponding directional isolate characters in thetext
that the view is rendering, based on the syntax parse results. - Write a custom left/right arrow key handler that just looks at the DOM to pick which way is forward and back.
Any suggestions on which way we should go?