public void Decorate(TextDecorationCollection td, SelectedTextBounds selectionBounds,
                             int lowerBound, int upperBound)
        {
            var startStr = selectionBounds.RealStart.Str;
            var startNum = selectionBounds.RealStart.Chr;
            var endStr   = selectionBounds.RealEnd.Str;
            var endNum   = selectionBounds.RealEnd.Chr;

            for (var i = Math.Max(startStr, lowerBound); i <= Math.Min(endStr, upperBound); i++)
            {
                if (startStr == endStr && startStr == i)
                {
                    this[i].SetTextDecorations(td, startNum, endNum - startNum);
                }
                else if (startStr < i && i < endStr)
                {
                    this[i].SetTextDecorations(td, 0, this[i].Text.Length);
                }
                else if (startStr == i)
                {
                    this[i].SetTextDecorations(td, startNum, this[i].Text.Length - startNum);
                }
                else if (endStr == i)
                {
                    this[i].SetTextDecorations(td, 0, endNum);
                }
            }
        }
 public void SelectedTextBoundsTest(
     IList <string> textLines,
     SelectedTextBounds bounds)
 {
     TestTextEditBoxModel.AddLines(textLines);
     TestTextEditBoxModel.SelectText(bounds);
     Assert.AreEqual(bounds, TestTextEditBoxModel.SelectedTextBounds,
                     "Bounds isn't equal to expected");
 }
 public void DeleteSelectedTextTest(
     IList <string> textLines,
     IList <string> expectedLines,
     SelectedTextBounds bounds)
 {
     TestTextEditBoxModel.AddLines(textLines);
     TestTextEditBoxModel.SelectText(bounds);
     TestTextEditBoxModel.DeleteSelected();
     Assert.AreEqual(expectedLines, TestTextEditBoxModel.TextLines,
                     "Remaining text isn't equal to expected");
 }
 public void CutRemainingTest(
     IList <string> textLines,
     IList <string> remainingLines,
     SelectedTextBounds bounds)
 {
     TestTextEditBoxModel.AddLines(textLines);
     TestTextEditBoxModel.SelectText(bounds);
     ContextMenuModel.Cut();
     Assert.AreEqual(remainingLines, TestTextEditBoxModel.TextLines,
                     "Text wasn't cut");
 }
 public void CutTest(
     IList <string> textLines,
     string expectedText,
     SelectedTextBounds bounds)
 {
     TestTextEditBoxModel.AddLines(textLines);
     TestTextEditBoxModel.SelectText(bounds);
     ContextMenuModel.Cut();
     Assert.AreEqual(expectedText, ClipboardHelper.GetText(expectedText),
                     "Text wasn't copy");
 }
 public void PasteSelectedTests(
     IList <string> textLines,
     string toPaste,
     IList <string> expectedLines,
     SelectedTextBounds bounds)
 {
     ClipboardHelper.SetText(toPaste);
     TestTextEditBoxModel.AddLines(textLines);
     TestTextEditBoxModel.SelectText(bounds);
     ContextMenuModel.Paste();
     Assert.AreEqual(expectedLines, TestTextEditBoxModel.TextLines,
                     "Lines isn't equal to expected");
 }
示例#7
0
 public TextEditBoxModel()
 {
     TextLines       = new TextLines(new[] { "" });
     SelectedText    = new SelectedTextBounds();
     CurrentPosition = new TextPosition();
 }
 public void RemoveDecoration(SelectedTextBounds bounds, int lowerBound, int upperBound) =>
 Decorate(null, bounds, lowerBound, upperBound);
 public void Underline(SelectedTextBounds selectionBounds, int lowerBound, int upperBound) =>
 Decorate(TextDecorations.Underline, selectionBounds, lowerBound, upperBound);
示例#10
0
 public void SelectText(SelectedTextBounds bounds)
 {
     TestLogger.Instance.Info($"Select text in Model:\r\n'{bounds}'");
     TextEditBoxModel.SetCurrentPosition(bounds.RealStart);
     TextEditBoxModel.SelectToPosition(bounds.RealEnd);
 }