diff --git a/Project/Src/Document/DefaultTextEditorProperties.cs b/Project/Src/Document/DefaultTextEditorProperties.cs index 8bef45b..83f9d45 100644 --- a/Project/Src/Document/DefaultTextEditorProperties.cs +++ b/Project/Src/Document/DefaultTextEditorProperties.cs @@ -48,7 +48,7 @@ namespace ICSharpCode.TextEditor.Document public bool ShowTabs { get; set; } = false; - public bool ShowEOLMarker { get; set; } = false; + public EolMarkerStyle EolMarkerStyle { get; set; } = EolMarkerStyle.None; public bool ShowInvalidLines { get; set; } = false; @@ -94,4 +94,4 @@ namespace ICSharpCode.TextEditor.Document public bool SupportReadOnlySegments { get; set; } = false; } -} \ No newline at end of file +} diff --git a/Project/Src/Document/EolMarkerStyle.cs b/Project/Src/Document/EolMarkerStyle.cs new file mode 100644 index 0000000..0f6d212 --- /dev/null +++ b/Project/Src/Document/EolMarkerStyle.cs @@ -0,0 +1,16 @@ +// +// +// +// +// $Revision$ +// + +namespace ICSharpCode.TextEditor.Document +{ + public enum EolMarkerStyle + { + None, + Glyph, + Text + } +} diff --git a/Project/Src/Document/ITextEditorProperties.cs b/Project/Src/Document/ITextEditorProperties.cs index 371d3b5..f0aaf09 100644 --- a/Project/Src/Document/ITextEditorProperties.cs +++ b/Project/Src/Document/ITextEditorProperties.cs @@ -95,7 +95,7 @@ namespace ICSharpCode.TextEditor.Document set; } - bool ShowEOLMarker + EolMarkerStyle EolMarkerStyle { // is wrapped in text editor control get; @@ -181,4 +181,4 @@ namespace ICSharpCode.TextEditor.Document bool SupportReadOnlySegments { get; set; } } -} \ No newline at end of file +} diff --git a/Project/Src/Gui/TextEditorControlBase.cs b/Project/Src/Gui/TextEditorControlBase.cs index f763ad2..fe889bf 100644 --- a/Project/Src/Gui/TextEditorControlBase.cs +++ b/Project/Src/Gui/TextEditorControlBase.cs @@ -493,17 +493,17 @@ namespace ICSharpCode.TextEditor } /// - /// If true EOL markers are shown in the textarea + /// Whether and how EOL markers are shown in the textarea /// [Category("Appearance")] - [DefaultValue(value: false)] - [Description("If true EOL markers are shown in the textarea")] - public bool ShowEOLMarkers + [DefaultValue(value: EolMarkerStyle.None)] + [Description("Whether and how EOL markers are shown in the textarea")] + public EolMarkerStyle EolMarkerStyle { - get => document.TextEditorProperties.ShowEOLMarker; + get => document.TextEditorProperties.EolMarkerStyle; set { - document.TextEditorProperties.ShowEOLMarker = value; + document.TextEditorProperties.EolMarkerStyle = value; OptionsChanged(); } } @@ -762,4 +762,4 @@ namespace ICSharpCode.TextEditor #endregion } -} \ No newline at end of file +} diff --git a/Project/Src/Gui/TextView.cs b/Project/Src/Gui/TextView.cs index 32619de..61a5f01 100644 --- a/Project/Src/Gui/TextView.cs +++ b/Project/Src/Gui/TextView.cs @@ -197,10 +197,9 @@ namespace ICSharpCode.TextEditor var selectionBeyondEOL = selectionRange.EndColumn > currentLine.Length || ColumnRange.WholeColumn.Equals(selectionRange); - if (TextEditorProperties.ShowEOLMarker) + if (TextEditorProperties.EolMarkerStyle != EolMarkerStyle.None) { - var eolMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("EOLMarkers"); - physicalXPos += DrawEOLMarker(g, eolMarkerColor.Color, selectionBeyondEOL ? bgColorBrush : backgroundBrush, physicalXPos, lineRectangle.Y, currentLine.EolMarker); + physicalXPos += DrawEOLMarker(g, selectionBeyondEOL ? bgColorBrush : backgroundBrush, physicalXPos, lineRectangle.Y, currentLine.EolMarker); } else { @@ -663,6 +662,17 @@ namespace ICSharpCode.TextEditor return fontBoundCharWidth[font][ch]; } + public int GetWidth(Graphics g, string text, Font font) + { + int width = 0; + foreach (char ch in text) + { + width += GetWidth(g, ch, font); + } + + return width; + } + public int GetVisualColumn(int logicalLine, int logicalColumn) { var column = 0; @@ -1062,40 +1072,35 @@ namespace ICSharpCode.TextEditor DrawString(g, "\u00BB", tabMarkerColor.GetFont(TextEditorProperties.FontContainer), color, x, y); } - private int DrawEOLMarker(Graphics g, Color color, Brush backBrush, int x, int y, EolMarker eolMarker) + private int DrawEOLMarker(Graphics g, Brush backBrush, int x, int y, EolMarker eolMarker) { - var eolMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("EOLMarkers"); - - int eolMarkerWidth = 0; - string representation = ""; - - int backslashWidth = GetWidth(ch: '\\', eolMarkerColor.GetFont(TextEditorProperties.FontContainer)); - int nWidth = GetWidth(ch: 'n', eolMarkerColor.GetFont(TextEditorProperties.FontContainer)); - int rWidth = GetWidth(ch: 'r', eolMarkerColor.GetFont(TextEditorProperties.FontContainer)); + string? representation; switch (eolMarker) { case EolMarker.Cr: - eolMarkerWidth = backslashWidth + rWidth; - representation = "\\r"; + representation = TextEditorProperties.EolMarkerStyle == EolMarkerStyle.Glyph ? "«" : @"\r"; break; case EolMarker.CrLf: - eolMarkerWidth = backslashWidth + rWidth + backslashWidth + nWidth; - representation = "\\r\\n"; + representation = TextEditorProperties.EolMarkerStyle == EolMarkerStyle.Glyph ? "¤" : @"\r\n"; break; case EolMarker.Lf: - eolMarkerWidth = backslashWidth + nWidth; - representation = "\\n"; + representation = TextEditorProperties.EolMarkerStyle == EolMarkerStyle.Glyph ? "¶" : @"\n"; break; case EolMarker.None: default: return 0; } + HighlightColor eolMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("EOLMarkers"); + Font font = eolMarkerColor.GetFont(TextEditorProperties.FontContainer); + int eolMarkerWidth = GetWidth(g, representation, font); + g.FillRectangle( backBrush, new RectangleF(x, y, eolMarkerWidth, FontHeight)); - DrawString(g, representation, eolMarkerColor.GetFont(TextEditorProperties.FontContainer), color, x, y); + DrawString(g, representation, font, eolMarkerColor.Color, x, y); + return eolMarkerWidth; }