Notro
Notro
CC#
Created by Notro on 8/20/2022 in #help
Get word at mouse function doesn't work as I want
Hi. I have this code:
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.WordBorder);
int offsetEnd = TextUtilities.GetNextCaretPosition(GetTextEditor().Document, offset, LogicalDirection.Forward, CaretPositioningMode.WordBorder);

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);
}
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.WordBorder);
int offsetEnd = TextUtilities.GetNextCaretPosition(GetTextEditor().Document, offset, LogicalDirection.Forward, CaretPositioningMode.WordBorder);

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);
}
The problem is, when I hover on "variable" in this: {variable.test} it gives me "variable", but I want it to return me {variable.test}. Can you help me, or is it AvalonEdit problem?
7 replies
CC#
Created by Notro on 8/16/2022 in #help
Open file in first instance
Hi. Im creating WPF app, that can open files. But, when i have opened app and use "Open with *my app*" , it creates new instance. How can i send file arg to the first instance and read it?
4 replies