From 478b82b1e18e4082dc081cbeacce4fdf86e56c41 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 27 Sep 2020 00:20:48 +0200 Subject: [PATCH] Small fixes in cursor position calculation --- UI/Input/TextField.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/UI/Input/TextField.ts b/UI/Input/TextField.ts index 0ae1e28..2c838bf 100644 --- a/UI/Input/TextField.ts +++ b/UI/Input/TextField.ts @@ -92,16 +92,14 @@ export class TextField extends InputElement { // @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 { return this._isValid(t, undefined); } -} - \ No newline at end of file +} \ No newline at end of file