Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
meebey committed Jul 5, 2015
2 parents 0b8ebe1 + 0cdd9f4 commit 6c9cb7f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
36 changes: 31 additions & 5 deletions src/Frontend-Tests/NickCompleterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,43 @@ public void TestNoIrssiCompletionAcrossChats() {
Assert.AreEqual(8, curPos);

// simulate switching chats
cv.ClearParticipants();
cv.ID = "#elsinore";
cv.AddParticipant("Hamlet");
cv.AddParticipant("HamletSr|Ghost");
var elsinoreCV = new MockChatView();
elsinoreCV.ID = "#elsinore";
elsinoreCV.AddParticipant("Hamlet");
elsinoreCV.AddParticipant("HamletSr|Ghost");

tcnc.Complete(ref inputLine, ref curPos, cv);
tcnc.Complete(ref inputLine, ref curPos, elsinoreCV);

AssertNoMessagesOutput();
Assert.AreEqual("Helena: ", inputLine);
Assert.AreEqual(8, curPos);
}

[Test]
public void TestNoRecompletionIfLineChangesButSameLength() {
cv.ID = "#athena";
cv.AddParticipant("Hippolyta");
cv.AddParticipant("Hermia");
cv.AddParticipant("Helena");

string inputLine = "Hip";
int curPos = 3;

tcnc.Complete(ref inputLine, ref curPos, cv);

AssertNoMessagesOutput();
Assert.AreEqual("Hippolyta: ", inputLine);
Assert.AreEqual(11, curPos);

// replace with a message of the same length
inputLine = "/kick Hermi";

tcnc.Complete(ref inputLine, ref curPos, cv);

AssertNoMessagesOutput();
Assert.AreEqual("/kick Hermia ", inputLine);
Assert.AreEqual(13, curPos);
}
}
}

8 changes: 7 additions & 1 deletion src/Frontend/TabCycleNickCompleter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TabCycleNickCompleter : NickCompleter
int PreviousMatchLength { get; set; }
int PreviousMatchCursorOffset { get; set; } // offset from match pos + match len
IChatView PreviousChatView { get; set; }
string InitialMatch { get; set; }

public TabCycleNickCompleter()
{
Expand All @@ -51,6 +52,7 @@ public TabCycleNickCompleter()
PreviousMatchLength = -1;
PreviousMatchCursorOffset = 0;
PreviousChatView = null;
InitialMatch = null;
}

public override void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView)
Expand All @@ -61,7 +63,8 @@ public override void Complete(ref string entryLine, ref int cursorPosition, ICha
string matchMe = IsolateNickToComplete(entryLine, cursorPosition, out matchPosition, out appendSpace, out leadingAt);

int rematchCursorPosition = PreviousMatchPos + PreviousMatchLength + PreviousMatchCursorOffset;
if (PreviousNickIndex != -1 && currentChatView == PreviousChatView && cursorPosition == rematchCursorPosition) {
if (PreviousNickIndex != -1 && currentChatView == PreviousChatView && cursorPosition == rematchCursorPosition
&& InitialMatch != null && (matchMe.Length == 0 || matchMe.StartsWith(InitialMatch))) {
// re-match
PreviousNickIndex = (PreviousNickIndex + 1) % PreviousNicks.Count;

Expand All @@ -76,6 +79,9 @@ public override void Complete(ref string entryLine, ref int cursorPosition, ICha
return;
}

// store this to check for re-matches
InitialMatch = matchMe;

// don't re-match even if the user moves the cursor back to the "correct" position
PreviousNickIndex = -1;

Expand Down

0 comments on commit 6c9cb7f

Please sign in to comment.