New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autocapitalization and autocorrect not supported on iOS #7009
Comments
This is related to directus/directus#16690. Looking elsewhere for clues, I see a few various issues related to autocapitalization and autocorrect: |
This suggestion #3403 (comment) tipped me to what I think is the answer:
Note that we are manually setting the attribute. And, I suspect it's because of this bug: #3403 (comment) It looks like there was a commit to set the value to an empty string? 97f6acc And here is another related ticket #4865 It looks like Apple's docs say the values should be
The resolution to this ticket, then, is to use the value |
Here's a diff I tested:
However, this only takes effect on The way I tested this was to apply this change to master branch, then:
index.html <!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>CodeMirror5 - contenteditable</title>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>
</head>
<body>
<h1>CodeMirror5 - contenteditable</h1>
<input type="text" id="myCode"></input>
<script type="text/javascript">
window.onload = function() {
var myTextarea = document.getElementById("myCode");
editor = CodeMirror.fromTextArea(myTextarea, {
lineNumbers: true,
autocorrect: true,
autocapitalize: true,
spellcheck: true,
inputStyle: 'contenteditable'
});
};
</script>
</body>
</html> or with textarea like index.html <!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>CodeMirror5 - textarea</title>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>
</head>
<body>
<h1>CodeMirror5 - textarea</h1>
<input type="text" id="myCode"></input>
<script type="text/javascript">
window.onload = function() {
var myTextarea = document.getElementById("myCode");
editor = CodeMirror.fromTextArea(myTextarea, {
lineNumbers: true,
autocorrect: true,
autocapitalize: true,
spellcheck: true,
inputStyle: 'contenteditable'
});
};
</script>
</body>
</html> So... back to the drawing board. I'm curious why CodeMirror only applies autocorrect and autocapitalize to |
I see this comment that affirms only |
Based on my testing, what iOS is needing is a If it is true, then in order to support these functions on iOS you need to manually set them like so: <!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>CodeMirror5 - textarea</title>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>
</head>
<body>
<h1>CodeMirror5 - textarea</h1>
<textarea id="myCode"></textarea>
<script type="text/javascript">
window.onload = function() {
var myTextarea = document.getElementById("myCode");
editor = CodeMirror.fromTextArea(myTextarea, {
lineNumbers: true,
spellcheck: true,
inputStyle: 'textarea'
});
var input = editor.getInputField();
input.setAttribute('autocorrect', 'on');
input.setAttribute('autocapitalize', 'on');
};
</script>
</body>
</html> |
They changed the default from on to off? From the code, it looks like the editor is just not adding the autocorrect=off attribute when you enable autocorrect. Can you confirm that an editable field without the attribute no longer does autocorrection? |
Videos are at 4x speed. Here is a video of what a plain textarea field looks like on iOS with these two attributes in various states using this codepen https://codepen.io/josephdpurcell/pen/xxzBgjz. Expand to view videoFullSizeRender.MOVHere is the same but for contenteditable using this codepen https://codepen.io/josephdpurcell/pen/NWzJdEr. Expand to view videoFullSizeRender.MOV |
@marijnh I created two new codepens titled FAIL 6 and FAIL 7:
They show the behavior of CodeMirror5 having given no options for autocapitalize and autocorrect. FAIL 6 is a textarea and worked for autopunctuation, but not for autocorrect nor autocapitalize. FAIL 7 is a contenteditable and did not work for any of those features: autopunctuation, autocorrect, nor autocapitalize. I hope that answers your question? A contenteditable field with no options supplied does not work for autocorrection. And, if you were meaning what a "plain" contenteditable behavior is see my previous comment where I did some testing. |
I just updated the description. PASS 1 is now FAIL 8 -- it does not autocapitalize on new lines. PASS 2 is now FAIL 9 -- it does not support autocorrect and it does not autocapitalize on new lines. |
Not enabling autocorrect and autocapitalize is the intended behavior when no options are given. I'm sorry, but I don't see through the flurry or messages and videos (for something that could have been a table? and seems to show the browser behaving as expected?) in this issue. Can you try to provide a single, focused example of something that is not working as you'd expect it to? |
@marijnh Sorry for the confusion, I was attempting to address your question:
But in the process of answering it I discovered that there is no scenario in which autocorrect, autocapitalization, and autopunctuation all function on iOS with CodeMirror5. From the description on this ticket, this is the code that does not work:
Here is the code pen: https://codepen.io/josephdpurcell/pen/xxzMLQw Here is a recording showing how it does not work: IMG_8963.MOVEdit 12/8 930a ET: Put code in code block. |
To see how autocorrect, autopunctuation, and autocapitalization are intended to work on iOS you can use the plain textarea input on this code pen: https://codepen.io/josephdpurcell/pen/xxzBgjz Here is a recording: IMG_8964.MOV |
Okay, I see what you mean now. Those options are only used for contenteditable input style, not textareas. It seems likely that the autocorrect suggestions will be invisible or misplaced in that configuration anyway. Why are you forcing inputStyle to textarea on mobile? |
Ultimately, I'm trying to achieve autocorrect, autocapitalization, and autopunctuation on the Markdown field for Directus, here is an explanation. My assumption was that I had to set the inputStyle. I'll attempt some more testing without that setting. I tried these settings on contenteditable too, see https://codepen.io/josephdpurcell/pen/KKeEwWo. It did not work. |
The editable element in that example has |
Yes, based on my testing those attributes should result in an input that supports autocorrect, autocapitalization, and autopunctuation. However, it does not. Here is a recording of https://codepen.io/josephdpurcell/pen/KKeEwWo (FAIL 4): IMG_8967.MOVI'm happy to try something different. |
I tried the scenario where I do not included the |
I noticed in my contenteditable tests that I use an |
@marijnh Regarding "something that could have been a table", I updated the description to use a table. I took about 30 mins, it was a little tedious. But, I hope it's more readable and helpful. CASE 8 is what most closely matched the desired behavior, but it uses a setTimeout hack. |
There's an iOS Safari bug (at least six years old at this point, they don't seem to care a lot about this stuff) where putting the cursor somewhere via a script does not update the autocapitalization state of the virtual keyboard. That may be what's breaking autocapitalize. This version is not under active development, so it's unlikely that anything big will be overhauled to make this work. I've merged #7010, but you already mention in the comments that that doesn't actually make a difference. |
Regarding:
I did some searching too and ran across this issue: https://dev.ckeditor.com/ticket/12142 for CKEditor. It says:
And I also found ckeditor/ckeditor4#4180 for CKEditor4 which says:
Followed by a comment saying that workaround stopped working in iOS 14.3. And I see ckeditor/ckeditor5#1111 for CKEditor5. I'm not sure what to conclude here. I am only vaguely aware of just how complex it is to write a WYSIWYG/editor, I suspect there isn't an easy fix. It is interesting that CodeMirror6 does not experience this issue (though it does seem to show both CM6 autocorrect and iOS autocorrect UIs which is odd). Going back to my own personal motivation on this ticket, I am researching what I think is a best-fit Markdown editor over here: directus/directus#16762 (comment). What I have found is that there are Markdown-specific editors that do support autocorrect, autopunctuation, and autocapitalization in the way I'm desiring. GitHub and StackExchange sites seem to also support these features well. I suspect that the more robust WYSIWYG-style editors like CKEditor and CodeMirror run into these OS-intereference issues? It's an interesting thing to observe. CodeMirror is truly impressive, and thank you for commenting to help validate that this is an issue. |
NOTE: CodeMirror6 does not experience this issue, see codemirror/dev#1020 (comment).
Using Safari on iOS 15.6.1 I am unable to get autocapitalization and autocorrect to work using the configuration specified in the manual here https://codemirror.net/5/doc/manual.html#config, with CodeMirror 5.65.10 seen here https://cdnjs.com/libraries/codemirror/5.65.10 (also tested
master
branch).The basic code is:
For reference here are code pens showing behavior of plain textarea and contenteditable:
A PASS is given if the following are true:
[a-zA-Z0-9]
turns into a period followed by 1 space.Here are code pens I've created to test different scenarios, I've put them in a collection https://codepen.io/collection/NqEdwO. And note testing results below.
Legend for cases:
textarea
: The HTML element is atextarea
.contenteditable
: The HTML element is acontenteditable
.inputStyle
: The input style was forced totextarea
orcontenteditable
, based on which HTML element was used.options
: Theautocorrect: true
andautocapitalization: true
arguments were passed as options to CodeMirror.setOption
: Theautocorrect
andautocapitalization
arguments were passed usingsetoption
.setAttribute
: The JavaScriptsetAttribute
function was used to "manually" set theautocorrect
andautocapitalize
options, either usinggetInputField
orquerySelectorAll
to get the elements.setTimeout + X
: TheX
was wrapped in a setTimeout.default
: No options were given; the CodeMirror defaults will be used.getInputField
querySelectorAll
getInputField
div
, options1 Only the first letter of the first word typed was capitalized, but never again.
2 Autocapitalization did not happen on new lines unless capitalization was already on, eg type "W-space-return-w" and you will get an upperacse
W
on the first line and a lowercasew
on the second line but if you type "W-space-space-return-w" you get an uppercaseW
with a period on the first line and an uppercaseW
on the second line.3 Same as note 2, autocapitalization is a little finicky.
4 Autocapitalization did not happen on new lines, nor after punctuation.
5 Autocapitalization did not happen on new lines, nor after punctuation.
6 Autocapitalization did not happen on new lines, nor after punctuation.
Note that CASE 12 is the only case that does not use the
CodeMirror.fromTextArea
pattern.Recording of testing CASE 1-3 and CASE 8 at 2x speed (note the video has it mis-labeled):
Expand to view video
FullSizeRender.MOV
Recording does not include cases 4, 5, 6, 7, nor 9.
Edit 12/7 3p ET: Clarified that autopunctuation does work.
Edit 12/7 6p ET: Added case 4, 5, and pass 2.
Edit 12/8 6a ET: Added case 6, 7, demos, and summary. Reflect discovery that all scenarios fail.
Edit 12/8 945a ET: Added case 10, 11, 12.
Edit 12/8 115p ET: Noted that CodeMirror6 does not have this issue.
Edit 12/8 315p ET: Modified to use a table for readability, and used the word CASE instead of pass/fail in the label.
The text was updated successfully, but these errors were encountered: