Browse Source

CalcCaretOverstrikeRectangle() now works at the border between LTR and RTL text.

pull/331/head
Daniel Grunwald 12 years ago
parent
commit
e5aa4d329b
  1. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/GeneralEditorOptions.xaml
  2. 35
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs
  3. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/GeneralEditorOptions.xaml

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
IsChecked="{core:OptionBinding local:CodeEditorOptions.ShowHiddenDefinitions}"
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.Markers.ShowHiddenDefinitionsCheckBox}" />
<CheckBox
IsChecked="{core:OptionBinding local:CodeEditorOptions.AllowOverstrikeMode}"
IsChecked="{core:OptionBinding local:CodeEditorOptions.AllowToggleOverstrikeMode}"
Content="Allow Overstrike mode" />
</widgets:StackPanelWithSpacing>
</GroupBox>

35
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
@ -395,23 +396,31 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -395,23 +396,31 @@ namespace ICSharpCode.AvalonEdit.Editing
RevalidateVisualColumn(visualLine);
}
TextLine textLine = visualLine.GetTextLine(position.VisualColumn, position.IsAtEndOfLine);
double lineTop = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.TextTop);
double lineBottom = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.TextBottom);
int currentPos = position.VisualColumn;
double xPos = visualLine.GetTextLineVisualXPosition(textLine, currentPos);
// The text being overwritten in overstrike mode is everything up to the next normal caret stop
int nextPos = visualLine.GetNextCaretPosition(currentPos, LogicalDirection.Forward, CaretPositioningMode.Normal, true);
double nextXPos = visualLine.GetTextLineVisualXPosition(textLine, nextPos);
// Use Math.Abs (and Math.Min below) in case of right-to-left text
// Use a minimum width of SystemParameters.CaretWidth in case of extremely thin characters (e.g. zero-width space)
double charSize = Math.Max(Math.Abs(xPos - nextXPos), SystemParameters.CaretWidth);
TextLine textLine = visualLine.GetTextLine(currentPos);
return new Rect(Math.Min(xPos, nextXPos),
lineTop,
charSize,
lineBottom - lineTop);
Rect r;
if (currentPos < visualLine.VisualLength) {
// If the caret is within the text, use GetTextBounds() for the text being overwritten.
// This is necessary to ensure the rectangle is calculated correctly in bidirectional text.
var textBounds = textLine.GetTextBounds(currentPos, nextPos - currentPos)[0];
r = textBounds.Rectangle;
r.Y += visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.LineTop);
} else {
// If the caret is at the end of the line (or in virtual space),
// use the visual X position of currentPos and nextPos (one or more of which will be in virtual space)
double xPos = visualLine.GetTextLineVisualXPosition(textLine, currentPos);
double xPos2 = visualLine.GetTextLineVisualXPosition(textLine, nextPos);
double lineTop = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.TextTop);
double lineBottom = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.TextBottom);
r = new Rect(xPos, lineTop, xPos2 - xPos, lineBottom - lineTop);
}
// If the caret is too small (e.g. in front of zero-width character), ensure it's still visible
if (r.Width < SystemParameters.CaretWidth)
r.Width = SystemParameters.CaretWidth;
return r;
}
/// <summary>

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

@ -2074,7 +2074,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -2074,7 +2074,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// <summary>
/// Gets/Sets highlighted line number.
/// </summary>
public int HighlightedLine {
internal int HighlightedLine { // TODO: move this logic out of the TextView
get { return this.currentLineHighlighRenderer.Line; }
set { this.currentLineHighlighRenderer.Line = value; }
}

Loading…
Cancel
Save