Fixed caret not moving properly in zen mode

This commit is contained in:
Jack92829 2021-01-12 15:29:40 +11:00
parent f2f0141bf7
commit e22ee7d1a0

View file

@ -1498,6 +1498,12 @@ function updateCaretPosition() {
currentLetterIndex = 0;
}
try {
//insert temporary character so the caret will work in zen mode
let activeWordEmpty = $("#words .active").children().length == 0;
if (activeWordEmpty) {
$("#words .active").append('<letter style="opacity: 0;">_</letter>');
}
let currentWordNodeList = document
.querySelector("#words .active")
.querySelectorAll("letter");
@ -1506,7 +1512,7 @@ function updateCaretPosition() {
currentLetter = currentWordNodeList[currentWordNodeList.length - 1];
}
if ($(currentLetter).length == 0) return;
if (config.mode != "zen" && $(currentLetter).length == 0) return;
const isLanguageLeftToRight = Misc.getCurrentLanguage().leftToRight;
let currentLetterPosLeft = isLanguageLeftToRight
? currentLetter.offsetLeft
@ -1561,6 +1567,9 @@ function updateCaretPosition() {
});
}
}
if (activeWordEmpty) {
$("#words .active").children().remove();
}
} catch (e) {
console.log("could not move caret: " + e.message);
}