Skip to content

Commit

Permalink
support input surrogate paird codepoint
Browse files Browse the repository at this point in the history
support surrogate pair input
  • Loading branch information
YO4 committed Dec 8, 2021
1 parent 00021fa commit 0b4aced
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/reline/windows.rb
Expand Up @@ -213,8 +213,29 @@ def self.msys_tty?(io=@@hConsoleInputHandle)
[ { control_keys: :SHIFT, virtual_key_code: VK_TAB }, [27, 91, 90] ],
]

@@hsg = nil

def self.process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)

# high-surrogate
if char_code & 0xDC00 == 0xD800
@@hsg = char_code
return
end
# low-surrogate
if char_code & 0xDC00 == 0xDC00
if @@hsg
char_code = 0x10000 + (@@hsg - 0xD800) * 0x400 + char_code - 0xDC00
@@hsg = nil
else
# no high-surrogate. ignored.
return
end
else
# ignore high-surrogate without low-surrogate if there
@@hsg = nil
end

key = KeyEventRecord.new(virtual_key_code, char_code, control_key_state)

match = KEY_MAP.find { |args,| key.matches?(**args) }
Expand Down

0 comments on commit 0b4aced

Please sign in to comment.