Browse Source

Don't show folding region tooltip when the mouse hovers behind the collapsed section (after the end of line).

pull/23/head
Daniel Grunwald 14 years ago
parent
commit
aa83bf1c44
  1. 74
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  2. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingSection.cs
  3. 21
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

74
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -8,27 +8,27 @@ using System.ComponentModel.Design; @@ -8,27 +8,27 @@ using System.ComponentModel.Design;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.AddIn.Snippets;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Editor.Commands;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Refactoring;
using Ast = ICSharpCode.NRefactory.Ast;
namespace ICSharpCode.AvalonEdit.AddIn
{
@ -233,7 +233,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -233,7 +233,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
Debug.Assert(sender == this);
ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.Adapter);
var pos = GetPositionFromPoint(e.GetPosition(this));
var pos = this.TextArea.TextView.GetPositionFloor(e.GetPosition(this.TextArea.TextView) + this.TextArea.TextView.ScrollOffset);
args.InDocument = pos.HasValue;
if (pos.HasValue) {
args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value);
@ -244,11 +244,11 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -244,11 +244,11 @@ namespace ICSharpCode.AvalonEdit.AddIn
FoldingManager foldings = this.Adapter.GetService(typeof(FoldingManager)) as FoldingManager;
if (foldings != null) {
var foldingsAtOffset = foldings.GetFoldingsContaining(offset);
var foldingsAtOffset = foldings.GetFoldingsAt(offset);
FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);
if (collapsedSection != null) {
args.SetToolTip(collapsedSection.TooltipText);
args.SetToolTip(GetTooltipTextForCollapsedSection(collapsedSection));
}
}
@ -396,6 +396,68 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -396,6 +396,68 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
popup = null;
}
#region GetTooltipTextForCollapsedSection
string GetTooltipTextForCollapsedSection(FoldingSection foldingSection)
{
// This fixes SD-1394:
// Each line is checked for leading indentation whitespaces. If
// a line has the same or more indentation than the first line,
// it is reduced. If a line is less indented than the first line
// the indentation is removed completely.
//
// See the following example:
// line 1
// line 2
// line 3
// line 4
//
// is reduced to:
// line 1
// line 2
// line 3
// line 4
const int maxLineCount = 15;
TextDocument document = this.Document;
int startOffset = foldingSection.StartOffset;
int endOffset = foldingSection.EndOffset;
DocumentLine startLine = document.GetLineByOffset(startOffset);
DocumentLine endLine = document.GetLineByOffset(endOffset);
StringBuilder builder = new StringBuilder();
DocumentLine current = startLine;
ISegment startIndent = TextUtilities.GetLeadingWhitespace(document, startLine);
int lineCount = 0;
while (current != endLine.NextLine && lineCount < maxLineCount) {
ISegment currentIndent = TextUtilities.GetLeadingWhitespace(document, current);
if (current == startLine && current == endLine)
builder.Append(document.GetText(startOffset, endOffset - startOffset));
else if (current == startLine) {
if (current.EndOffset - startOffset > 0)
builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart());
} else if (current == endLine) {
if (startIndent.Length <= currentIndent.Length)
builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length));
else
builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length));
} else {
if (startIndent.Length <= currentIndent.Length)
builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length));
else
builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length));
}
current = current.NextLine;
lineCount++;
}
return builder.ToString();
}
#endregion
#endregion
#region Ctrl+Click Go To Definition

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingSection.cs

@ -84,6 +84,7 @@ namespace ICSharpCode.AvalonEdit.Folding @@ -84,6 +84,7 @@ namespace ICSharpCode.AvalonEdit.Folding
/// <summary>
/// Gets the content of the collapsed lines as tooltip text.
/// </summary>
[Obsolete]
public string TooltipText {
get {
// This fixes SD-1394:

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

@ -1612,6 +1612,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -1612,6 +1612,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// <summary>
/// Gets the text view position from the specified visual position.
/// If the position is within a character, it is rounded to the next character boundary.
/// </summary>
/// <param name="visualPosition">The position in WPF device-independent pixels relative
/// to the top left corner of the document.</param>
@ -1628,6 +1629,26 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -1628,6 +1629,26 @@ namespace ICSharpCode.AvalonEdit.Rendering
int documentOffset = line.GetRelativeOffset(visualColumn) + line.FirstDocumentLine.Offset;
return new TextViewPosition(document.GetLocation(documentOffset), visualColumn);
}
/// <summary>
/// Gets the text view position from the specified visual position.
/// If the position is inside a character, the position in front of the character is returned.
/// </summary>
/// <param name="visualPosition">The position in WPF device-independent pixels relative
/// to the top left corner of the document.</param>
/// <returns>The logical position, or null if the position is outside the document.</returns>
public TextViewPosition? GetPositionFloor(Point visualPosition)
{
VerifyAccess();
if (this.Document == null)
throw ThrowUtil.NoDocumentAssigned();
VisualLine line = GetVisualLineFromVisualTop(visualPosition.Y);
if (line == null)
return null;
int visualColumn = line.GetVisualColumnFloor(visualPosition);
int documentOffset = line.GetRelativeOffset(visualColumn) + line.FirstDocumentLine.Offset;
return new TextViewPosition(document.GetLocation(documentOffset), visualColumn);
}
#endregion
#region Service Provider

Loading…
Cancel
Save