Fix Plm Completion Bugs

This commit is contained in:
Benjamin Popp
2019-06-14 22:06:51 -05:00
parent 356f016a96
commit 94cdc127d3
3 changed files with 41 additions and 3 deletions

View File

@@ -83,7 +83,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
public IEnumerable<string> GetAutoCompleteOptions(string header) {
var moveNames = ModelCacheScope.GetCache(model).GetOptions(EggMoveRun.MoveNamesTable);
return moveNames.Select(name => $"{header} {name} "); // autocomplete needs to complete after selection, so add a space
return moveNames.Select(name => $"{header} {name}" + (name.EndsWith("\"") ? "" : " ")); // autocomplete needs to complete after selection, so add a space if there's no quotes
}
public string SerializeRun() {

View File

@@ -51,8 +51,13 @@ namespace HavenSoft.HexManiac.Core {
// no perfect match found. How about a partial match?
var match = names.FirstOrDefault(name => name.Contains(input));
if (match == null) return -1;
return names.IndexOf(match);
if (match != null) names.IndexOf(match);
for (var i = 0; i < names.Count; i++) {
if (names[i].MatchesPartial(input)) return i;
}
return -1;
}
}
}

View File

@@ -290,6 +290,39 @@ namespace HavenSoft.HexManiac.Tests {
Assert.Contains("3 One", viewPort.Tools.StringTool.Content);
}
[Fact]
public void AutoCompletePlmMoveNameContainingSpaceWorksWithNoQuotes() {
SetupMoveTable(0x00);
viewPort.SelectionStart = new Point(0, 1); // start of move "Two"
viewPort.Edit("Bob Par");
SetupPlmStream(0x50, 8);
viewPort.Goto.Execute("000000");
viewPort.SelectionStart = new Point(2, 5); // should select '2 One'
viewPort.Edit("2 bobpar ");
Assert.IsNotType<UnderEdit>(viewPort[2, 5].Format);
Assert.Contains("2 \"Bob Par\"", viewPort.Tools.StringTool.Content);
}
[Fact]
public void ChoosingAutoCompleteOptionClosesPlmEdit() {
SetupMoveTable(0x00);
viewPort.SelectionStart = new Point(0, 1); // start of move "Two"
viewPort.Edit("Bob Par");
SetupPlmStream(0x50, 8);
viewPort.Goto.Execute("000000");
viewPort.SelectionStart = new Point(2, 5); // should select '2 One'
viewPort.Edit("3 \"Bo");
var format = (UnderEdit)viewPort[2, 5].Format;
viewPort.Autocomplete(format.AutocompleteOptions[0].CompletionText);
Assert.IsNotType<UnderEdit>(viewPort[2, 5].Format);
Assert.Contains("3 \"Bob Par\"", viewPort.Tools.StringTool.Content);
}
// creates a move table that is 0x40 bytes long
private void SetupMoveTable(int start) {
viewPort.Goto.Execute(start.ToString("X6"));