Open micwallace opened 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.
I was unable to come up with a working solution.......very frustrating.
Only workaround at the moment is to force textarea inputStyle.
still no progress?
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.
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:
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.