mirror of
https://github.com/flarum/framework.git
synced 2025-02-02 03:27:47 +08:00
Fix error thrown if textarea doesn't exist in TextEditor (#1852)
* Prevent textarea not existing from causing errors to be thrown * Replace [0] with .length
This commit is contained in:
parent
5a03cd865a
commit
d725012a84
|
@ -122,6 +122,8 @@ export default class TextEditor extends Component {
|
||||||
setSelectionRange(start, end) {
|
setSelectionRange(start, end) {
|
||||||
const $textarea = this.$('textarea');
|
const $textarea = this.$('textarea');
|
||||||
|
|
||||||
|
if (!$textarea.length) return;
|
||||||
|
|
||||||
$textarea[0].setSelectionRange(start, end);
|
$textarea[0].setSelectionRange(start, end);
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
}
|
}
|
||||||
|
@ -134,6 +136,8 @@ export default class TextEditor extends Component {
|
||||||
getSelectionRange() {
|
getSelectionRange() {
|
||||||
const $textarea = this.$('textarea');
|
const $textarea = this.$('textarea');
|
||||||
|
|
||||||
|
if (!$textarea.length) return [0, 0];
|
||||||
|
|
||||||
return [$textarea[0].selectionStart, $textarea[0].selectionEnd];
|
return [$textarea[0].selectionStart, $textarea[0].selectionEnd];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user