From 6739401d456136c81a6cb688c4464913ae38ddc1 Mon Sep 17 00:00:00 2001 From: Boris Fritscher Date: Mon, 17 Jul 2017 14:30:32 +0200 Subject: [PATCH] better repeat logic for text and ... --- src/Carnac.Logic/Models/Message.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Carnac.Logic/Models/Message.cs b/src/Carnac.Logic/Models/Message.cs index 415492b0..53bca268 100644 --- a/src/Carnac.Logic/Models/Message.cs +++ b/src/Carnac.Logic/Models/Message.cs @@ -132,10 +132,25 @@ static IEnumerable CreateTextSequence(IEnumerable keys) if (acc.Any()) { var last = acc.Last(); - if (last.IsRepeatedBy(curr)) + var secondLast = acc.Count() > 1 ? acc.SkipLast(1).Last() : null; + var thirdLast = acc.Count() > 2 ? acc.SkipLast(2).Last() : null; + if (last.IsRepeatedBy(curr) && + // not a letter or a letter with a modifier or repeated letter + (!(curr.InterceptKeyEventArgs.IsLetter() || curr.GetTextParts().First() == ".") || curr.HasModifierPressed || last.RepeatCount > 2)) { last.IncrementRepeat(); } + else if (last.IsRepeatedBy(curr) && + // a letter is repeated 4 times now count it x times + (curr.InterceptKeyEventArgs.IsLetter() || curr.GetTextParts().First() == ".") && secondLast != null && secondLast.IsRepeatedBy(curr) + && thirdLast != null && thirdLast.IsRepeatedBy(curr)) + { + acc.Remove(last); + acc.Remove(secondLast); + thirdLast.IncrementRepeat(); + thirdLast.IncrementRepeat(); + thirdLast.IncrementRepeat(); + } else { acc.Add(new RepeatedKeyPress(curr, last.NextRequiresSeperator)); @@ -172,6 +187,8 @@ public RepeatedKeyPress(KeyPress keyPress, bool requiresPrefix = false) public bool NextRequiresSeperator { get { return nextRequiresSeperator; } } + public int RepeatCount { get { return repeatCount; } } + public void IncrementRepeat() { repeatCount++;