Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Carnac.Logic/Models/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,25 @@ static IEnumerable<string> CreateTextSequence(IEnumerable<KeyPress> 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));
Expand Down Expand Up @@ -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++;
Expand Down