Small fixes in cursor position calculation

This commit is contained in:
Pieter Vander Vennet 2020-09-27 00:20:48 +02:00
parent 558a1848a0
commit 478b82b1e1

View file

@ -92,16 +92,14 @@ export class TextField extends InputElement<string> {
// @ts-ignore
val = field.value;
let newCursorPos = endDistance;
let newCursorPos = val.length - endDistance;
while(newCursorPos >= 0 &&
// We count the number of _actual_ characters (non-space characters) on the right of the new value
// This count should become bigger then the end distance
val.substr(newCursorPos).replace(/ /g, '').length <= endDistance
val.substr(newCursorPos).replace(/ /g, '').length < endDistance
){
newCursorPos --;
}
newCursorPos++;
// @ts-ignore
self.SetCursorPosition(newCursorPos);
};
@ -146,5 +144,4 @@ export class TextField extends InputElement<string> {
return this._isValid(t, undefined);
}
}
}