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

Bidirectional text improvements #7557

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

Jermolene
Copy link
Member

This PR is a recreation of #4541 which was merged and then later reverted when it was discovered that it caused a serious performance regression.


TiddlyWiki's language plugin mechanism includes a primitive mechanism for setting the HTML 5 "dir" attribute on the document body to "RTL", thus switching the direction of the user interface. This mechanism is used by languages such as Farsi and Hebrew.

Some of the issues with the current approach is that it is hard to work with tiddlers that have a different directionality to the main interface. For example, the document direction is "LTR" when using the default "en-GB" language plugin, but pasting (say) Farsi into the title, tags, or text fields of a tiddler doesn't switch direction to "RTL".

Prompted by discussions with @kookma, this experimental PR explores two separate mechanisms that help when working with text of a different directionality than the main interface.

The first is a new \dir rtl pragma that can be used at the top of a tiddler to specify that it should be rendered as RTL. This setting is respected if the tiddler content is transcluded elsewhere.

(A shortcoming at present is that the \dir pragma must be used after any \define pragmas if those macro definitions are to be imported elsewhere with the `\import' pragma).

The second change in this PR is support for a new $:/config/DefaultTextDirection hidden setting. It can be set to "rtl", "ltr" or "auto". It sets the "dir" attribute on several different parts of the view template and edit template.

The interesting thing is the setting "auto", part of the HTML 5 spec. It applies a simple heuristic to detect the appropriate direction for a fragment of text. The default value of $:/config/DefaultTextDirection is "auto". With this setting in place it becomes possible to paste fragments of RTL text into titles, tags, or text fields, and have things work as expected.

(A shortcoming that won't be going away is that the CodeMirror engine doesn't support "auto", just the explicit "RTL" and "LTR" settings. So I think we'll have to handle that entirely differently.

The change that I haven't explored here is adding a "_direction" field on individual tiddlers. That would work much better with the CodeMirror editor, but the disadvantage is that transclusion wouldn't respect the setting.

@vercel
Copy link

vercel bot commented Jun 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview Jun 21, 2023 4:20pm

@kookma
Copy link
Contributor

kookma commented Jan 12, 2025

Is there any way to update this branch with the latest version of TiddlyWiki?

@kookma
Copy link
Contributor

kookma commented Jan 23, 2025

@Jermolene
Is there any way to update this branch with the latest version of TiddlyWiki? I use the rtl features implemented in this branch. The latest version I have working with this branch is TW 5.3.0

Copy link

netlify bot commented Jan 24, 2025

Deploy Preview for tiddlywiki-previews ready!

Name Link
🔨 Latest commit a62e39a
🔍 Latest deploy log https://app.netlify.com/sites/tiddlywiki-previews/deploys/6797ba5bd80c8800080aaafa
😎 Deploy Preview https://deploy-preview-7557--tiddlywiki-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Jermolene
Copy link
Member Author

Hi @kookma I've updated this branch. Let me know if you run into anything.

@pmario
Copy link
Member

pmario commented Jan 24, 2025

@Jermolene -- I did just have a look at the code here and I could not find any difference to the original "reverted" PR. So does this one still have the performance penalty?

@Jermolene
Copy link
Member Author

@Jermolene -- I did just have a look at the code here and I could not find any difference to the original "reverted" PR. So does this one still have the performance penalty?

As I said in that original comment "Sadly, this PR will have to be reverted. I'll also create a new PR with the changes so that we can continue investigations". So at this point this is a duplicate of the original PR so that we can continue to experiment; we can't use #4541 because that has already been merged.

@kookma
Copy link
Contributor

kookma commented Jan 24, 2025

Hi @kookma I've updated this branch. Let me know if you run into anything.

Thank you, Jeremy! This works like TW-5.3.0pre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants