protected override bool ApplySnapResult(SelectionBlueprint <ITextTag>[] blueprints, SnapResult result) { if (!base.ApplySnapResult(blueprints, result)) { return(false); } // handle lots of ruby / romaji drag position changed. var items = blueprints.Select(x => x.Item).ToArray(); if (!items.Any()) { return(false); } var leftPosition = ToLocalSpace(result.ScreenSpacePosition).X; var startIndex = TextIndexUtils.ToStringIndex(editorLyricPiece.GetHoverIndex(leftPosition)); var diff = startIndex - items.First().StartIndex; if (diff == 0) { return(false); } foreach (var item in items) { var newStartIndex = item.StartIndex + diff; var newEndIndex = item.EndIndex + diff; if (!LyricUtils.AbleToInsertTextTagAtIndex(Lyric, newStartIndex) || !LyricUtils.AbleToInsertTextTagAtIndex(Lyric, newEndIndex)) { continue; } item.StartIndex = newStartIndex; item.EndIndex = newEndIndex; } return(true); }
public void TestAbleToInsertTextTagAtIndex(string text, int index, bool actual) { var lyric = TestCaseTagHelper.ParseLyricWithTimeTag(text); Assert.AreEqual(LyricUtils.AbleToInsertTextTagAtIndex(lyric, index), actual); }