textadept icon indicating copy to clipboard operation
textadept copied to clipboard

Not print capital letters (Cyrillic alphabet)

Open bbslipers opened this issue 2 years ago • 4 comments
trafficstars

editor textadept-ncurses.exe it does not print capital letters (Cyrillic alphabet) if you enter them while holding Shift, but if you switch Caps Lock, then everything starts to output correctly.

bbslipers avatar Jul 27 '23 15:07 bbslipers

Probably the reason is the inappropriate behavior of Shift since some of the keyboard combinations do not work either.

bbslipers avatar Jul 27 '23 18:07 bbslipers

Yes, the manual's appendix mentions that not all key sequences are recognized properly, so shift+non-ascii characters seem to fall under this category, at least in the Windows terminal version. I don't have a Cyrillic keyboard, so I don't have a way to diagnose what's going wrong and fix it. Sorry :(

You could uncomment this line: https://github.com/orbitalquark/textadept/blob/19cfa3ce0c7d2f981d2b8cbbee4f8e603be9b5db/core/keys.lua#L186

When you type a shifted Cyrillic character, see what the statusbar outputs. If it's legible, then you could perhaps create a key binding for that sequence keys['...'] = function() buffer:insert_text(-1, '...') end to insert the correct character. It's certainly not ideal, but it might be better than nothing.

orbitalquark avatar Jul 28 '23 01:07 orbitalquark

profile\init.lua

events.connect(events.KEY, function(code, modifiers)
  if CURSES then ui.statusbar_text = string.format('"%s"', code) end
  if code == 1040 then
   buffer:insert_text(-1, 'А')
   return
  end
end)

Press Cyrillic character "A" (code = 1040) in editor xC0xC0 (the code was inserted twice)

Сapital letters Cyrillic alphabet: АБВГДЕ.... code = 1040 - 1071

bbslipers avatar Jul 28 '23 08:07 bbslipers

So far I have done so in no other way. Probably clumsy - I'm a beginner.

core\keys.lua

local bytemarkers = { {0x7FF,192}, {0xFFFF,224}, {0x1FFFFF,240} }
local function code2char(decimal)
    if decimal<128 then return string.char(decimal) end
    local charbytes = {}
    for bytes,vals in ipairs(bytemarkers) do
      if decimal<=vals[1] then
        for b=bytes+1,2,-1 do
          local mod = decimal%64
          decimal = (decimal-mod)/64
          charbytes[b] = string.char(128+mod)
        end
        charbytes[1] = string.char(vals[2]+decimal)
        break
      end
    end
    return table.concat(charbytes)
end

events.connect(events.KEY, function(code, modifiers)
        if CURSES and code >= 1040 and code < 1072 then
                buffer:insert_text(-1,code2char(code))
                buffer:char_right()
                return ''
        end
        local shift, ctrl, alt, cmd = modifiers & MOD_SHIFT > 0, modifiers & MOD_CTRL > 0, modifiers & MOD_ALT > 0, modifiers & MOD_META > 0
        if OSX and not CURSES then ctrl, cmd = cmd, ctrl end
        if code >= 32 and code < 256 then key = string.char(code) else key = M.KEYSYMS[code] end
        if not key then return end
        if QT and not shift and code < 256 then key = key:lower() end
        if shift and code >= 32 and code < 256 then shift = false end
        if (OSX and not CURSES) and alt and code < 256 then alt = false end
        return events.emit(events.KEYPRESS, string.format('%s%s%s%s%s', ctrl and CTRL or '', alt and ALT or '', cmd and OSX and CMD or '', shift and SHIFT or '', key))
end)

bbslipers avatar Jul 28 '23 18:07 bbslipers