Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight selected #123

Merged
merged 2 commits into from
Dec 15, 2020
Merged
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
59 changes: 53 additions & 6 deletions OneMore/Commands/Tools/ShowXmlDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace River.OneMoreAddIn.Commands
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Linq;
using Resx = River.OneMoreAddIn.Properties.Resources;
Expand Down Expand Up @@ -244,12 +245,6 @@ private void ChangeInfoScope(object sender, EventArgs e)
private void HideAttributes(object sender, EventArgs e)
{
ChangeInfoScope(sender, e);

if (hideBox.Checked || hideLFBox.Checked)
{
ApplyHideOptions();
}

okButton.Enabled = !hideBox.Checked;
}

Expand Down Expand Up @@ -292,6 +287,58 @@ private void ApplyHideOptions()
}

pageBox.Text = root.ToString(SaveOptions.None);

Highlights();
}


private void Highlights()
{
var text = pageBox.Text;

var matches = Regex.Matches(text, "selected=\"all\"");
var prev = -1;

foreach (Match match in matches)
{
if (match.Index > prev)
{
var start = match.Index;
while (start > 0 && text[start] != '\n')
{
start--;
}
while (start < match.Index && char.IsWhiteSpace(text[start])) start++;

var end = match.Index + match.Length;
while (end < text.Length && text[end] != '\n')
{
end++;
}

pageBox.SelectionStart = start;
pageBox.SelectionLength = end - start;
pageBox.SelectionBackColor = Color.Yellow;

prev = end;
}
}

if (!hideBox.Checked)
{
matches = Regex.Matches(text,
"(?:author|authorInitials|authorResolutionID|lastModifiedBy|" +
"lastModifiedByInitials|lastModifiedByResolutionID|creationTime|" +
"lastModifiedTime|objectID)=\"[^\"]*\""
);

foreach (Match m in matches)
{
pageBox.SelectionStart = m.Index;
pageBox.SelectionLength = m.Length;
pageBox.SelectionColor = Color.Silver;
}
}
}


Expand Down