codemirror / codemirror5

In-browser code editor (version 5, legacy)
http://codemirror.net/5/
MIT License
26.78k stars 4.96k forks source link

Single spaces do not work on default Samsung Keyboard Android #4129

Open micwallace opened 8 years ago

micwallace commented 8 years ago

This issue what originally submitted to the simplemde repo by another user. The same issue is present in CodeMirror which I have confirmed using the examples on codemirror.net.

The users initial submission:

I only have Samsung devices to test, but I suspect it applies to all Androids, but I tested on a Galaxy S3, S4, and S5 and they all have the same issue. The issue is only with the default Samsung keyboard, when using a 3rd party keyboard it works fine (SwiftKey, etc).

When using the default Android/Samsung keyboard, if you hit the space bar once, nothing happens, but if you hit it twice, it gives you a single space. Basically, any time you want to enter a space, you must first hit space bar twice. After you've hit it twice, it seems to work normally.

original issue

I have done some basic debugging & inspected events triggered when this problem occurs. No keydown event seems to relate to this behaviour, however I have notice that 2 input events fire when the problem occurs when there is usually just one input event fired for each keydown event.

The problem also only seems to occur when the word being typed is in underline mode. ie. you can move the cursor to the end of a word which is already typed, and the space-bar will work on the first go. Only when typing a new word and then pressing space causes this issue.

micwallace commented 8 years ago

Observations:

I have been able to prevent this issue by using the below code, which checks for the presence of space or return character after the current cursor position. If the check fails then a space is appended to the end of the composition data.

https://github.com/codemirror/CodeMirror/blob/master/lib/codemirror.js#L1600

var cursorPos = cm.getCursor();
var lastChar = cm.getDoc().getRange({line: cursorPos.line, ch: cursorPos.ch-1}, cursorPos);
var addSpace = (cursorPos.ch==0 || lastChar==" ") && (e.data.length>1 && e.data.charAt(e.data.length-1)!=" ");

if (e.data != ours.startData && !/\u200b/.test(e.data))
      ours.data = e.data + (addSpace?" ":"");

I'm not sure if this is the best way to fix, but the events in question contain no unique data and therefore cannot be filtered without disabling auto-suggest functionality. Let me know if you find any other solutions.

UPDATE: Unfortunately the solution above causes more issues than it fixes.

micwallace commented 8 years ago

I was unable to come up with a working solution.......very frustrating.

Only workaround at the moment is to force textarea inputStyle.

dehypnosis commented 7 years ago

still no progress?

adrianheine commented 6 years ago

This is probably an issue that is difficult if not impossible to solve with the fundamental approach currently taken by CodeMirror.

We are working on a rewrite (CodeMirror 6) that will completely overhaul input handling and probably addresses this issue, and we are currently raising money for this work: See the announcement for more information about the rewrite and a demo.

Note that CodeMirror 6 is by no means stable or usable in production, yet. It is highly unlikely that we pick up this issue for CodeMirror 5, though.