Skip to content
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

Fix: setCursor doesn't work well with inputStyle: "contenteditable", #6168

Closed
wants to merge 4 commits into from

Conversation

A-312
Copy link

@A-312 A-312 commented Mar 8, 2020

Fix: #6167

This PR fix ContentEditableInput.showSelection(info), I removed takeFocus because it always false. It is a remanent code, it cannot work like that.

Also, I add a demo page to try the spellchecker (and also, because I discovered that we can active the spellchecker only with stackoverflow, not with the codemirror documentation....).

My last change is to add options.forceFocus because the behavior of selection in the ContenteditableInput editor with no focus is weird and different of the behavior that we get with TextareaInput.

Q/A

Q/A setSelection

To test my PR/fix you have to go on demo/abc.html and try to do :

  • editor.setSelection({line:0, ch:2}, {line:0, ch:5})
  • editor.setCursor({line:0, ch:2})

Try each time with focus (--> click in the editor) and without no focus (--> click out of the editor, in the page)

Q/A options.forceFocus

To test options.forceFocus:

  1. Select a word on demo/abc.html page, like this:
    image
  2. Try editor.setSelection({line:0, ch:2}, {line:0, ch:5}), nothing should be change.
  3. Try editor.setSelection({line:0, ch:2}, {line:0, ch:5}, {forceFocus:true}), selection should be visible, like this:
    image

We have a visual difference between contenteditable and textarea InputStyle:

  • TextareaInput: Selection is show with focus or not focus ;
  • ContenteditableInput: Selection is only show if the editor has focus.

The condition `op.focus == activeElt()` seems that it will be always `false` because `op.focus` is `boolean` and `activeElt()` returns an HTMLElement.

```
HTMLElement == true
false
HTMLElement == false
false
document.body == true
false
document.body == false
false
```

`activeElt()` always return an `HTMLElement`.
https://github.com/codemirror/CodeMirror/blob/28568ba037146b2d13857849650db94b8ec09385/src/util/dom.js#L67-L80
Give the editor focus after selection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setCursor doesn't work well with inputStyle: "contenteditable",
2 participants