b94dba3d9b
Fix bluring keyboard on Android Fix reading messages when page was blured Fix instant reading messages if there only one page of them Split dom functions
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
/*
|
|
* https://github.com/morethanwords/tweb
|
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
*
|
|
* Originally from:
|
|
* https://github.com/zhukov/webogram
|
|
* Copyright (C) 2014 Igor Zhukov <igor.beatle@gmail.com>
|
|
* https://github.com/zhukov/webogram/blob/master/LICENSE
|
|
*/
|
|
|
|
import { isTouchSupported } from "../touchSupport";
|
|
|
|
export default function placeCaretAtEnd(el: HTMLElement) {
|
|
if(isTouchSupported) {
|
|
return;
|
|
}
|
|
|
|
el.focus();
|
|
if(typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
|
|
var range = document.createRange();
|
|
range.selectNodeContents(el);
|
|
range.collapse(false);
|
|
var sel = window.getSelection();
|
|
sel.removeAllRanges();
|
|
sel.addRange(range);
|
|
// @ts-ignore
|
|
} else if(typeof document.body.createTextRange !== "undefined") {
|
|
// @ts-ignore
|
|
var textRange = document.body.createTextRange();
|
|
textRange.moveToElementText(el);
|
|
textRange.collapse(false);
|
|
textRange.select();
|
|
}
|
|
}
|