Beispiel #1
0
        protected static string HighlightMatch(Widget widget, string text, string toMatch)
        {
            var           lane   = StringMatcher.GetMatcher(toMatch, true).GetMatch(text);
            StringBuilder result = new StringBuilder();

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos));
                    }
                    result.Append("<span foreground=\"#4d4d4d\" font_weight=\"bold\">");
                    MarkupUtilities.AppendEscapedString(result, text[pos].ToString());
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos));
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text);
            }
            return(result.ToString());
        }
Beispiel #2
0
        protected static string HighlightMatch(string text, string toMatch, bool selected)
        {
            var           lane   = StringMatcher.GetMatcher(toMatch, true).GetMatch(text);
            StringBuilder result = new StringBuilder();

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos));
                    }
                    var matchColor = selected ? Styles.GlobalSearch.SelectedResultMatchTextColor : Styles.GlobalSearch.ResultMatchTextColor;
                    result.Append("<span foreground=\"" + Styles.ColorGetHex(matchColor) + "\" font_weight=\"bold\">");
                    MarkupUtilities.AppendEscapedString(result, text[pos].ToString());
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos));
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text);
            }
            return(result.ToString());
        }
Beispiel #3
0
        protected static string HighlightMatch(string text, string toMatch, bool selected)
        {
            var           lane          = StringMatcher.GetMatcher(toMatch, true).GetMatch(text);
            var           matchHexColor = selected ? selectedResultMatchTextColor : resultMatchTextColor;
            StringBuilder result        = new StringBuilder(text.Length + matchHexColor.Length + 46);

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text, lastPos, pos - lastPos);
                    }
                    result.Append("<span foreground=\"");
                    result.Append(matchHexColor);
                    result.Append("\" font_weight=\"bold\">");
                    MarkupUtilities.AppendEscapedString(result, text, pos, 1);
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text, lastPos, text.Length - lastPos);
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text, 0, text.Length);
            }
            return(result.ToString());
        }
Beispiel #4
0
        protected static string HighlightMatch(Widget widget, string text, string toMatch)
        {
            var           lane   = StringMatcher.GetMatcher(toMatch, false).GetMatch(text);
            StringBuilder result = new StringBuilder();

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos));
                    }
                    result.Append("<span foreground=\"");
                    var color = Mono.TextEditor.HslColor.GenerateHighlightColors(widget.Style.Base(StateType.Normal),
                                                                                 widget.Style.Text(StateType.Normal), 3)[2];
                    result.Append(color.ToPangoString());
                    result.Append("\">");
                    MarkupUtilities.AppendEscapedString(result, text[pos].ToString());
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos));
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text);
            }
            return(result.ToString());
        }