WuTheFWasThat / vimflowy

An open source productivity tool drawing inspiration from workflowy and vim
https://www.wuthejeff.com/vimflowy
MIT License
1.61k stars 112 forks source link

Text other than english #147

Closed catch2patch closed 6 years ago

catch2patch commented 8 years ago

Hi! Thank all the contributors for the great project. It seems I can text english only in Vimflowy. Is it possible to switch keyboard language and write on the language other then english? PS > When I paste non-english text to Vimflowy it seems to be OK. But I cant input it from my keyboard.

WuTheFWasThat commented 8 years ago

hi!

yeah, it didn't occur to me to support non-english alphabets, at all. I don't know too much about other keyboards/languages, so it would be nice if somebody else could take care of this. also, how does vim work with these other alphabets anyways?

sorry this may not get resolved too soon :( i'm not sure if it can be done in a nice and general way (not saying it can't, i just don't know!)

za3k commented 8 years ago

I would expect this to work for left-to-right languages already. @WuTheFWasThat The only check I remember is for "is this one character long" (which I carefully checked whether it was a character vs a byte). This is basically something that needs to be supported by our input/output but I thought it should be already. @catch2patch Can you explain more specifically something you're trying to do that's failing?

wanpeng-first commented 8 years ago

Hi I really like your project and I have the same issue as @catch2patch . Most East Asian languages need an IME to input the non-English characters into computer. It looks like this (using Google Pinyin IME for Chinese): ime_example

As you can see when the user start typing, the keystrokes should go to the system IME first, then IME outputs the characters. The problem with vimflowy right now seems to be that it catches all the key strokes even before the IME. So it inserts some random characters when the user types.

vimflowyime

I don't have lots of knowledge on this, but seeing many other web apps have no problem with this, I suspect that there must be some system level API you can use to get the user's input--in English or not, instead of catching the raw keystrokes?

Hope it can help.

WuTheFWasThat commented 8 years ago

thanks for the info - I'm still having trouble finding out how to fix this though, at first glance. if anyone is curious, the only relevant code should be at https://github.com/WuTheFWasThat/vimflowy/blob/master/src/assets/js/keyEmitter.ts

r-laf commented 7 years ago

I guess https://w3c.github.io/input-events/ can be used to solve this problem. It says:

Inputtypes for beforeinput events for the start and end of IME compositions that allow isolation of the IME composition process.

This interface is relatively new, suppose only works with latest chrome or firefox.

WuTheFWasThat commented 7 years ago

http://stackoverflow.com/questions/27861122/how-do-international-keyboards-work-with-javascript-keyboard-events

Suggested solution: a hidden text box

liukun commented 7 years ago

Seems not easy to handle IME inputs by changing keyEmitter.ts only. There are not only input preview when using IME, but you can even move cursor during preview. For example,

draft_js___rich_text_editor_framework_for_react

So the most feasible way is using contenteditable DOM property during insert mode like Workflowy does. Then when user click Esc, switch back to normal mode and get rid of contenteditable. However, react's related module https://draftjs.org/ seems being migrating to new API. Maybe we should wait v0.11 before trying?

liukun commented 7 years ago

A similar editor is using two divs, only show the rendered one initially, then after user click, hide the rendered one and focus the origin one which let user editing by browser's input service.

<div>
    <div class="content-origin" contenteditable="true">**Bold**</div>
    <div class="content-rendered"><span class="hidden">**</span><span class="bold">Bold</span><span class="hidden">**</span></div>
</div>

Quite similar to Vimflowy's HTML plugin IMHO, just the contentEditable component should not contain children managed by React, so need put the text of whole line in it, not by tokenize each character.

WuTheFWasThat commented 7 years ago

ah - thanks for looking into this! the div should probably be hidden and cleared every character, actually. that way it's possible to implement things like mapping jk to escape without seeing the characters "jk"

yuanotes commented 6 years ago

I created a PR for this issue: https://github.com/WuTheFWasThat/vimflowy/pull/287

WuTheFWasThat commented 6 years ago

PR is merged. Please reopen if you have any issues; I have not tested myself!