Browse Source

EOL markers as glyph or text (#31)

pull/32/head
Michael Seibt 3 years ago
committed by GitHub
parent
commit
4e41ab6a5b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Project/Src/Document/DefaultTextEditorProperties.cs
  2. 16
      Project/Src/Document/EolMarkerStyle.cs
  3. 4
      Project/Src/Document/ITextEditorProperties.cs
  4. 14
      Project/Src/Gui/TextEditorControlBase.cs
  5. 43
      Project/Src/Gui/TextView.cs

4
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;
}
}
}

16
Project/Src/Document/EolMarkerStyle.cs

@ -0,0 +1,16 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="none" email=""/>
// <version>$Revision$</version>
// </file>
namespace ICSharpCode.TextEditor.Document
{
public enum EolMarkerStyle
{
None,
Glyph,
Text
}
}

4
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; }
}
}
}

14
Project/Src/Gui/TextEditorControlBase.cs

@ -493,17 +493,17 @@ namespace ICSharpCode.TextEditor
}
/// <value>
/// If true EOL markers are shown in the textarea
/// Whether and how EOL markers are shown in the textarea
/// </value>
[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
}
}
}

43
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;
}

Loading…
Cancel
Save