plover icon indicating copy to clipboard operation
plover copied to clipboard

"老" is output as "j́"

Open mirka opened this issue 6 months ago • 6 comments

Describe the bug

When a translation contains the character , it's output as when I type it. This doesn't happen with any other characters (that I know of).

To Reproduce

Steps to reproduce the behavior:

  1. Add a translation that includes the character, for example "HRAO": "老".
  2. Stroke the chord.

Expected behavior

The character is output as is.

Screenshots

https://github.com/user-attachments/assets/e8beb0ea-cf96-4c94-964f-06025fa679fe

This is happening regardless of text editor or browser.

Operating system

  • OS: macOS Sequoia 15.5
  • Plover Version 4.0.1

Hardware

Starboard with Gemini PR

mirka avatar Jun 14 '25 20:06 mirka

I tested it on macOS Sequoia 15.5 with Plover v4.0.2 and I'm able to type 老 (actually typed it right now with Plover).

Maybe it's an encoding issue with your dictionary? It should be UTF-8 encoded. You can check it like this:

file -I inbox.json
inbox.json: application/json; charset=utf-8

mkrnr avatar Jun 14 '25 20:06 mkrnr

Thanks for testing! Yes, encoding was fine.

file -I japanese.json
japanese.json: application/json; charset=utf-8

I also tried it in a secure input field to make sure that other apps weren't intercepting/modifying the text, and it still reproduces. If it's just happening in my environment, I'm out of ideas 🥲

mirka avatar Jun 14 '25 21:06 mirka

Some interesting insights from ChatGPT:

A likely cause is that Plover is trying to “type” 老 using ordinary key-events, but the active macOS keyboard layout can’t produce that character. On the default ABC / U.S. layout Plover ends up sending the sequence Option-E (dead acute) + J, which macOS interprets as j́ (U+006A U+0301).

And that explains why it was working for me yesterday: I'm using an European keyboard layout (EurKEY) and with that I get 老. If I switch to the default ABC / U.S. layout, I can reproduce this issue and also get j́.

mkrnr avatar Jun 15 '25 05:06 mkrnr

Oh wow. You're right, I tried it on a French layout and it works. It doesn't work on either of the layouts that I use day-to-day (US and Japanese).

I wonder why it's just this character, because I have lots of other CJK characters in my definitions that work normally. Or emojis too, for that matter.

Do you know if this is something patchable at the Plover level?

mirka avatar Jun 16 '25 15:06 mirka

Some more insights:

Character Hex value macOS treats it as… Result on the U.S./ABC layout
0x8001 “pointer to sequence #1” Sequence #1 is defined — it’s Option + E (dead acute) then J. Plover replays those keys and you get j́.
0x8002 “pointer to sequence #2” Sequence #2 is not defined in this layout, so macOS falls back to “okay, just treat 0x8002 as a real Unicode code-point.” Plover inserts 耂 correctly.

So that's why it works for the French layout or mine: there, 0x8001 is not defined so it falls back to Unicode.

I'm afraid I won't be able to work on this anytime soon due to the rather complex implementation.

But I can offer a workaround that pastes the problematic string:

  1. Create an Apple Script ~/path/to/file/output-via-paste.scpt using the Script Editor with this content:
on run argv
	if (count argv) = 0 then return
	set pasteText to item 1 of argv
	
	set oldClip to the clipboard
	set the clipboard to pasteText
	tell application "System Events" to keystroke "v" using {command down}
	delay 0.1 -- brief pause so paste completes
	set the clipboard to oldClip
end run
  1. Install the plugin plover-run-shell via the Plugins Manager
  2. Define a dictionary entry "HRAO": "{PLOVER:SHELL:osascript ~/path/to/file/output-via-paste.scpt 老}"

mkrnr avatar Jun 16 '25 19:06 mkrnr

I guess it's the clipboard workaround for me then. I've just started building out my Japanese dictionary so I hope there aren't many characters like this 😅

Thank you for looking into it!

mirka avatar Jun 17 '25 22:06 mirka