chat: simplify some code and fix bugs I noticed during testing
authorsheepluva
Mon, 04 May 2015 18:32:33 +0200
changeset 10926 43612076e989
parent 10924 ed1b6914cac5
child 10928 4d8826a87419
chat: simplify some code and fix bugs I noticed during testing
hedgewars/uChat.pas
--- a/hedgewars/uChat.pas	Mon May 04 18:39:00 2015 +0300
+++ b/hedgewars/uChat.pas	Mon May 04 18:32:33 2015 +0200
@@ -594,26 +594,19 @@
 procedure MoveCursorToPreviousChar();
 begin
     if cursorPos > 0 then
-        begin
-        while (not IsFirstCharByte(InputStr.s[cursorPos])) do
-            begin
+        repeat
             dec(cursorPos);
-            end;
-        dec(cursorPos);
-        end;
+        until ((cursorPos = 0) or IsFirstCharByte(InputStr.s[cursorPos + 1]));
 end;
 
 procedure MoveCursorToNextChar();
+var len: integer;
 begin
-    if cursorPos <  Length(InputStr.s) then
-        begin
-        inc(cursorPos, 2);
-        while (cursorPos <  Length(InputStr.s)) and (not IsFirstCharByte(InputStr.s[cursorPos])) do
-            begin
+    len:= Length(InputStr.s);
+    if cursorPos < len then
+        repeat
             inc(cursorPos);
-            end;
-        dec(cursorPos);
-        end;
+        until ((cursorPos = len) or IsFirstCharByte(InputStr.s[cursorPos + 1]));
 end;
 
 procedure DeleteLastUTF8CharFromStr(var s: shortstring);