# HG changeset patch # User sheepluva # Date 1430757153 -7200 # Node ID 43612076e989081e3ce5458a280183ef73628723 # Parent ed1b6914cac557e979b0e9282647050b75faca27 chat: simplify some code and fix bugs I noticed during testing diff -r ed1b6914cac5 -r 43612076e989 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);