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 // @ts-ignore
val = field.value; val = field.value;
let newCursorPos = endDistance; let newCursorPos = val.length - endDistance;
while(newCursorPos >= 0 && while(newCursorPos >= 0 &&
// We count the number of _actual_ characters (non-space characters) on the right of the new value // 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 // 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 --;
} }
newCursorPos++;
// @ts-ignore // @ts-ignore
self.SetCursorPosition(newCursorPos); self.SetCursorPosition(newCursorPos);
}; };
@ -147,4 +145,3 @@ export class TextField extends InputElement<string> {
} }
} }