some more dark magic regarding hog speech input
authorsheepluva
Sun, 24 Apr 2016 22:41:24 +0200
changeset 11702 446ce60700dd
parent 11701 fa4bc078e509
child 11703 e86feecadced
some more dark magic regarding hog speech input
hedgewars/uChat.pas
--- a/hedgewars/uChat.pas	Sun Apr 24 22:10:37 2016 +0200
+++ b/hedgewars/uChat.pas	Sun Apr 24 22:41:24 2016 +0200
@@ -1011,10 +1011,12 @@
 procedure TextInput(var event: TSDL_TextInputEvent);
 var s: shortstring;
     l: byte;
+    isl: integer;
 begin
     DeleteSelected();
 
     l:= 0;
+    // fetch all bytes of character/input
     while event.text[l] <> #0 do
         begin
         s[l + 1]:= event.text[l];
@@ -1023,16 +1025,28 @@
 
     if l > 0 then
         begin
-        if byte(InputStr.s[0]) + l > 240 then exit;
-        s[0]:= char(l);
-        InsertIntoInputStr(s);
+        isl:= Length(InputStr.s);
+        // check if user is typing a redundant closing hog-speech quotation mark
+        if (l = 1) and (isl >= 2) and (cursorPos = isl - 1) and charIsForHogSpeech(s[1])
+          and (s[1] = InputStr.s[1]) and (s[1] = InputStr.s[isl]) then
+            begin
+            MoveCursorToNextChar();
+            UpdateCursorCoords();
+            end
+        else
+            begin
+            // don't add input that doesn't fit
+            if isl + l > MaxInputStrLen then exit;
+            s[0]:= char(l);
+            InsertIntoInputStr(s);
 
-        // add closing hog speech quotation marks automatically
-        if (l = 1) and (Length(InputStr.s) = 1) and charIsForHogSpeech(s[1]) then
-            begin
-            InsertIntoInputStr(s);
-            MoveCursorToPreviousChar();
-            UpdateCursorCoords();
+            // add closing hog speech quotation marks automagically
+            if (l = 1) and (Length(InputStr.s) = 1) and charIsForHogSpeech(s[1]) then
+                begin
+                InsertIntoInputStr(s);
+                MoveCursorToPreviousChar();
+                UpdateCursorCoords();
+                end;
             end;
 
         end