Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force left-to-right for lines with bidirectional text? #20

Closed
cspeterson opened this issue Apr 22, 2020 · 3 comments
Closed

Force left-to-right for lines with bidirectional text? #20

cspeterson opened this issue Apr 22, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@cspeterson
Copy link
Owner

As per issue #17 and PR #18

Database entries (there are two examples in the emoticons file as of this reply) which include bidirectional unicode text (Arabic, Persian, or Hebrew) are rendered in their entirety by Rofi from right-to-left.

I experimented a bit and including e.g. \u200e the left-to-right "implicit directional mark" at the head of the lines including bidi text does indeed make Rofi render them ltr, BUT then barring any code changes the result in either the clipboard or by type includes these control characters. Depending on where you paste this, it could show the character and make things ugly.

So we have a solution of sorts. We could..

  • Prepend directional marks on bidi lines in the database, and strip them on the output
    • This means the addition of a new field to the db format, but just a single extra string substitution at runtime, which isn't a lot of overhead.
  • Prepend directional marks on all lines in-line as they are piped out to rofi, and then strip them on output
    • This means a text prepend operation of every line that goes out to rofi, which feels gross, but at least wouldn't alter the DB format.
  • Do nothing
    • This means some lines will continue to be reversed in the menu

I'm leaning towards "Do nothing" but will continue to consider the other options

@cspeterson cspeterson added the bug Something isn't working label Apr 22, 2020
@iFreilicht
Copy link

What about prepending directional marks on the bidi lines, and just substituting "\u200e" with "" on output? Should be solved by a simple substitution like ${string//\u200e/}, no?

There's no need to add a new field in this case, so this seems like a very simple yet effective solution.

@cspeterson
Copy link
Owner Author

Okay so e34c93c should take care of this

I ran the emoticon db through the following script

#!/usr/bin/env python3

from unicodedata import bidirectional
import sys

lines = sys.stdin.readlines()

for line in lines:
    line = line.strip()
    moji, annotations = line.split("\t", 1)
    if True in [bidirectional(b) in ['AL', 'R'] for b in moji]:
        print('\u200e' + moji, annotations, sep="\t")
    else:
        print(line)

.. in order to prepend a unicode directional control character for any line with mixed bidi text.

And splatmoji strips it out after selection:

selection=${selection#$'\u200e'}

csp

@iFreilicht
Copy link

Perfect :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants