async Task <string> CreateMarkupAsync(SearchResultWidget widget, TextEditor doc, Editor.IDocumentLine line) { int startIndex = 0, endIndex = 0; int indent = line.GetIndentation(doc).Length; string lineText; int col = Offset - line.Offset; int markupStartOffset = 0; bool trimStart = false, trimEnd = false; int length; if (col < indent) { trimEnd = line.Length > maximumMarkupLength; length = Math.Min(maximumMarkupLength, line.Length); // search result contained part of the indent. lineText = doc.GetTextAt(line.Offset, length); } else { // if not crop the indent length = line.Length - indent; if (length > maximumMarkupLength) { markupStartOffset = Math.Min(Math.Max(0, col - indent - maximumMarkupLength / 2), line.Length - maximumMarkupLength); trimEnd = markupStartOffset + maximumMarkupLength < line.Length; trimStart = markupStartOffset > 0; length = maximumMarkupLength; } lineText = doc.GetTextAt(line.Offset + markupStartOffset + indent, length); col -= indent; } if (col >= 0) { uint start; uint end; try { start = (uint)TranslateIndexToUTF8(lineText, col - markupStartOffset); end = (uint)TranslateIndexToUTF8(lineText, Math.Min(lineText.Length, col - markupStartOffset + Length)); } catch (Exception e) { LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + Length + " line text:" + lineText + ")", e); return(""); } startIndex = (int)start; endIndex = (int)end; } var tabSize = doc.Options.TabSize; this.markup = this.selectedMarkup = markup = Ambience.EscapeText(lineText); var searchColor = GetBackgroundMarkerColor(widget.HighlightStyle); var selectedSearchColor = widget.Style.Base(Gtk.StateType.Selected); selectedSearchColor = searchColor.AddLight(-0.2); double b1 = HslColor.Brightness(searchColor); double b2 = HslColor.Brightness(SearchResultWidget.AdjustColor(widget.Style.Base(Gtk.StateType.Normal), SyntaxHighlightingService.GetColor(widget.HighlightStyle, EditorThemeColors.Foreground))); // selected markup = FormatMarkup(PangoHelper.ColorMarkupBackground(selectedMarkup, (int)startIndex, (int)endIndex, searchColor), trimStart, trimEnd, tabSize); selectedMarkup = FormatMarkup(PangoHelper.ColorMarkupBackground(selectedMarkup, (int)startIndex, (int)endIndex, selectedSearchColor), trimStart, trimEnd, tabSize); string newMarkup; using (var markupTimeoutSource = new CancellationTokenSource(150)) { newMarkup = await doc.GetMarkupAsync(line.Offset + markupStartOffset + indent, length, new MarkupOptions (MarkupFormat.Pango), markupTimeoutSource.Token).ConfigureAwait(false); newMarkup = widget.AdjustColors(newMarkup); } try { double delta = Math.Abs(b1 - b2); if (delta < 0.1) { var color1 = SyntaxHighlightingService.GetColor(widget.HighlightStyle, EditorThemeColors.FindHighlight); if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } if (startIndex != endIndex) { newMarkup = PangoHelper.ColorMarkupBackground(newMarkup, (int)startIndex, (int)endIndex, searchColor); } } catch (Exception e) { LoggingService.LogError("Error while setting the text renderer markup to: " + newMarkup, e); } return(FormatMarkup(newMarkup, trimStart, trimEnd, tabSize)); }
void CreateMarkup(SearchResultWidget widget, TextEditor doc, Editor.IDocumentLine line) { int startIndex = 0, endIndex = 0; int indent = line.GetIndentation(doc).Length; string lineText; int col = Offset - line.Offset; int markupStartOffset = 0; bool trimStart = false, trimEnd = false; if (col < indent) { trimEnd = line.Length > maximumMarkupLength; // search result contained part of the indent. lineText = doc.GetTextAt(line.Offset, Math.Min(maximumMarkupLength, line.Length)); markup = doc.GetMarkup(line.Offset, Math.Min(maximumMarkupLength, line.Length), new MarkupOptions(MarkupFormat.Pango)); } else { // if not crop the indent var length = line.Length - indent; if (length > maximumMarkupLength) { markupStartOffset = Math.Min(Math.Max(0, col - indent - maximumMarkupLength / 2), line.Length - maximumMarkupLength); trimEnd = markupStartOffset + maximumMarkupLength < line.Length; trimStart = markupStartOffset > 0; length = maximumMarkupLength; } lineText = doc.GetTextAt(line.Offset + markupStartOffset + indent, length); markup = doc.GetMarkup(line.Offset + markupStartOffset + indent, length, new MarkupOptions(MarkupFormat.Pango)); col -= indent; } selectedMarkup = Ambience.EscapeText(lineText); markup = widget.AdjustColors(markup); if (col >= 0) { uint start; uint end; try { start = (uint)TranslateIndexToUTF8(lineText, col - markupStartOffset); end = (uint)TranslateIndexToUTF8(lineText, Math.Min(lineText.Length, col - markupStartOffset + Length)); } catch (Exception e) { LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + Length + " line text:" + lineText + ")", e); return; } startIndex = (int)start; endIndex = (int)end; } try { var searchColor = GetBackgroundMarkerColor(widget.HighlightStyle); double b1 = HslColor.Brightness(searchColor); double b2 = HslColor.Brightness(SearchResultWidget.AdjustColor(widget.Style.Base(Gtk.StateType.Normal), SyntaxHighlightingService.GetColor(widget.HighlightStyle, EditorThemeColors.Foreground))); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { var color1 = SyntaxHighlightingService.GetColor(widget.HighlightStyle, EditorThemeColors.FindHighlight); if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } if (startIndex != endIndex) { markup = PangoHelper.ColorMarkupBackground(markup, (int)startIndex, (int)endIndex, searchColor); } // selected var selectedSearchColor = widget.Style.Base(Gtk.StateType.Selected); selectedSearchColor = searchColor.AddLight(-0.2); selectedMarkup = PangoHelper.ColorMarkupBackground(selectedMarkup, (int)startIndex, (int)endIndex, selectedSearchColor); } catch (Exception e) { LoggingService.LogError("Error while setting the text renderer markup to: " + markup, e); } markup = markup.Replace("\t", new string (' ', doc.Options.TabSize)); selectedMarkup = selectedMarkup.Replace("\t", new string (' ', doc.Options.TabSize)); if (trimStart) { markup = "…" + markup; selectedMarkup = "…" + selectedMarkup; } if (trimEnd) { markup += "…"; selectedMarkup += "…"; } }