Page MenuHomePhabricator

Cursor gets misaligned when trying to edit code with Unicode characters
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):
Try to edit the test case at https://www.wikifunctions.org/wiki/Z31731?uselang=en&action=edit, specifically, try changing the Bengali text there.

What happens?:
The cursor gets misaligned.

What should have happened instead?:
The cursor should have stayed aligned correctly.
Other information (browser name/version, screenshots, etc.):
Safari on macOS Tahoe 26.2

Event Timeline

I feel like this is more of an upstream Ace editor issue then a Wikilambda issue.

Yep, I just tested this on the editor embedded on their homepage.

I'll be working on T400015 / T289097 soon-ish. MediaWiki-extensions-CodeMirror shouldn't have this issue.

Either way CodeEditor is not Community-Tech, just FYI :)

@Redmin I see it happening in your example aswell. place the cursor at the end of local references = require('মডিউল:উইকিউপাত্ত তথ্যসূত্র বিন্যাসকরণ').format and its also doing strange erase

upstream issue I guess

This comment was removed by DSmit-WMF.

Ok I checked ace bug board and got this:

ACE has long-standing problems with Unicode and cursor positioning, especially for scripts that use combining characters (including Bengali and other Indic scripts).

Relevant issues
#5431 – Full Unicode support incomplete (open, P1)

  • Cursor moves too far from the text
  • Affects combining diacritical marks and variable-width Unicode
  • Marked as high priority, large effort

#4685 – Cursor at wrong pos with Devanagari (closed as no plans)

  • Same symptom with Devanagari (similar to Bengali)
  • Monospace fonts do not fix it
  • One workaround: call editor.resize() after showing the editor

#3800 – Variable-width Unicode characters

  • Core issue: ACE treats combining marks as full-width characters

Cause

ACE treats combining diacritical marks and multi-codepoint characters as full-width, so the cursor position is computed incorrectly. Bengali uses the same combining-character mechanism.

Possible workarounds

  1. editor.resize() – Call after the editor is visible; can help in some setups:
editor.session.setValue(contents);
editor.container.style.visibility = 'visible';
editor.resize();
  1. Community fix – A fix exists on a fork: ewnjtgouierg/ace, branch Selection_Fix (https://github.com/ewnjtgouierg/ace/tree/Selection_Fix). It is not merged upstream yet.

I tried the resize , it does not help.

Either way CodeEditor is not Community-Tech, just FYI :)

Whoops, my bad!

@Redmin I see it happening in your example aswell. place the cursor at the end of local references = require('মডিউল:উইকিউপাত্ত তথ্যসূত্র বিন্যাসকরণ').format and its also doing strange erase

That's weird, it seems to work normally for me on Safari and Chrome.

...
Replacing Ace is my best bet indeed for this.

If anyone else stumbles on this in the meantime: I use the search and replacement functionality of the editor to get around this.

CPT2610071315-572x290 (4).gif (572×290 px, 1 MB)

I can confirm this as fixed when using CodeMirror

Ah I thought you had already removed Ace from the repo.