mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fix select all flicker
This commit is contained in:
parent
aadf9e2f87
commit
fdeb092a8d
1 changed files with 9 additions and 8 deletions
|
@ -84,19 +84,20 @@ function clearChangeTimer() {
|
|||
|
||||
function onFocus(elem) {
|
||||
currentField = elem;
|
||||
setTimeout(unfocusHack, 1);
|
||||
// prevent webkit from highlighting the whole field
|
||||
$(elem).css("-webkit-user-select", "none");
|
||||
setTimeout(function () { unfocusHack() }, 1);
|
||||
py.run("focus:" + currentField.id.substring(1));
|
||||
}
|
||||
|
||||
// tabbing into a new field highlights everything, which we don't want
|
||||
// restore cursor
|
||||
function unfocusHack() {
|
||||
$(currentField).css("-webkit-user-select", "text");
|
||||
var r = document.createRange()
|
||||
r.selectNodeContents(currentField);
|
||||
r.collapse();
|
||||
var s = document.getSelection();
|
||||
if (s.rangeCount) {
|
||||
var r = s.getRangeAt(0);
|
||||
r.collapse();
|
||||
s.removeAllRanges();
|
||||
s.addRange(r);
|
||||
}
|
||||
s.addRange(r);
|
||||
};
|
||||
|
||||
function onBlur() {
|
||||
|
|
Loading…
Reference in a new issue