getSelection() only works after setSelection()
See original GitHub issueWhen I try to use the API function getSelection(), it gives an error:
TypeError: quill.getSelection(...) is null
However, if I first set the selection (shows for the user)
quill.setSelection(3,5);
alert(quill.getSelection().end);
It gives no error, and displays a popup saying ‘5’
Issue Analytics
- State:
- Created 8 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Window.getSelection changes after being set to another ...
I seem to have a problem that my window.getselection object changes after I set it to another object. Here is an example: document....
Read more >Window.getSelection() - Web APIs | MDN
getSelection() method returns a Selection object representing the range of text selected by the user or the current position of the caret.
Read more >Selection and Range - The Modern JavaScript Tutorial
The document selection is represented by Selection object, that can be obtained as window.getSelection() or document.getSelection() . A ...
Read more >SelectionState - Draft.js
getSelection() , which provides the SelectionState currently being rendered in the editor. Keys and Offsets#. A selection range has two points: ...
Read more >Row Selection - JavaScript Data Grid
Getting the underlying node (rather than the data) is useful when working with ... and call the setSelected() method if it matches the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It turned out that the issue was that the editor was losing focus when clicking on a custom button. This can be resolved by adding a custom format tied to a button or by calling
quill.focus
beforequill.getSelection
. A demo can be seen hereI want to set cursor to specific position but not working in my code here is the sample code I wrote any body know please update
import React, {Component} from ‘react’; import ReactQuill from ‘react-quill’ import “react-quill/dist/quill.snow.css”; import ‘./App.css’;
class App extends Component{ constructor(props) { super(props); this.state = { editorHtml: “testing” }; this.handleChange = this.handleChange.bind(this); this.handleChangeSelection = this.handleChangeSelection.bind(this);
}
handleChange(content, delta, source, editor) { console.log(content); console.log(delta); console.log(source); console.log(editor.getSelection()); //console.log(“IBM”+editor.getHTML()); // HTML/rich text //alert(event); //this.setState({ editorHtml: editor.getHt }); }
handleChangeSelection(e) { console.log(e); }
moveCursor = () => { this.reactQuillRef.focus();
}
render(){ return ( <div className="App">
} }
export default App;