Problem with tooltip
Closed this issue · 0 comments
NotroDev commented
Hi.
I have this function:
private string GetWordAtMousePosition(MouseEventArgs e)
{
var mousePosition = GetTextEditor().GetPositionFromPoint(e.GetPosition(GetTextEditor()));
if (mousePosition == null)
return string.Empty;
var line = mousePosition.Value.Line;
var column = mousePosition.Value.Column;
var offset = GetTextEditor().Document.GetOffset(line, column);
if (offset >= GetTextEditor().Document.TextLength)
offset--;
int offsetStart = TextUtilities.GetNextCaretPosition(GetTextEditor().Document, offset, LogicalDirection.Backward, CaretPositioningMode.WordBorderOrSymbol);
int offsetEnd = TextUtilities.GetNextCaretPosition(GetTextEditor().Document, offset, LogicalDirection.Forward, CaretPositioningMode.WordBorderOrSymbol);
if (offsetEnd == -1 || offsetStart == -1)
return string.Empty;
var currentChar = GetTextEditor().Document.GetText(offset, 1);
if (string.IsNullOrWhiteSpace(currentChar))
return string.Empty;
return GetTextEditor().Document.GetText(offsetStart, offsetEnd - offsetStart);
}
And this event:
void TextEditorMouseHover(object sender, MouseEventArgs e)
{
string word = GetWordAtMousePosition(e);
toolTip.PlacementTarget = sender as UIElement;
toolTip.Content = word;
toolTip.IsOpen = true;
e.Handled = true;
}
But, it works like this:
How can i make it to give me everytime "{test}"?