Skip to content

feat: add BiDi text direction support and message metadata footer - #1

Open
Ham3dParsa wants to merge 8 commits into
devfrom
bidi-metadata
Open

feat: add BiDi text direction support and message metadata footer#1
Ham3dParsa wants to merge 8 commits into
devfrom
bidi-metadata

Conversation

@Ham3dParsa

@Ham3dParsaHam3dParsa commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

Add bidirectional text (BiDi) support for Persian/Arabic mixed with English in OpenCode Desktop's Electron renderer.

Changes

BiDi Detection (preload/index.ts)

  • Hybrid algorithm (\da()): Uses first strong directional character as primary signal. If first strong is LTR but significant RTL content exists (>=40% of LTR count), falls back to \dir=\rtl\
  • Streaming support (\co()): MutationObserver on characterData changes re-applies direction on text updates
  • Prompt input (\inp()): \input\ event listener with 300ms debounce. Combined with \unicode-bidi:plaintext\ for stable text ordering
  • Code blocks: \direction:ltr; unicode-bidi:isolate\ — always LTR, isolated from surrounding text
  • Question Tool: \ ext-align:start\ override on [data-slot=\question-option], \unicode-bidi:plaintext\ on option labels/descriptions, Q selector for \da()\ coverage

CSS Injected

SelectorRule
[data-component=\markdown]>*\\unicode-bidi:plaintext\
[data-slot=\user-message-text]\\unicode-bidi:plaintext\
[data-component=\reasoning-part]>*\\unicode-bidi:plaintext\
[data-component=\tool-output]\\unicode-bidi:plaintext\
[data-slot=\question-text], [data-slot=\answer-text]\\unicode-bidi:plaintext\
[data-component=\markdown] code, [data-component=\markdown] pre\\direction:ltr; unicode-bidi:isolate\
[data-component=\prompt-input]\\unicode-bidi:plaintext\
[data-slot=\question-option]\\ ext-align:start\
[data-slot=\option-label], [data-slot=\option-description]\\unicode-bidi:plaintext\

Message Metadata Footer

  • Timestamp: smart format (Today/Yesterday/Date) with full date on hover
  • Token counts: ↑input ↓output with tooltip (Input, Output, Thinking, Speed, Total)
  • Rendered below copy-wrapper via MutationObserver
  • Streaming: waits for \data-time-completed\ attribute via \�ttributeFilter\ observer
  • Data attributes added to renderer bundle: \data-time-created, \data-time-completed, \data-tokens-input, \data-tokens-output, \data-tokens-reasoning, \data-model-id, \data-provider-id\

Testing

Test with mixed Persian/English content in:

  1. Chat messages (user + assistant)
  2. Code blocks and inline code
  3. Numbered lists with Persian text
  4. Tables with mixed content
  5. Prompt input (typing mixed text)
  6. Question Tool options

Sign up for freeto 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.

1 participant

@Ham3dParsa