Highlight(select) part of source/target text in editor's view

Is there a way how to select part of source/target text in editor's view?
I've prepared my own custom verifier and I'm able to report messages using IBilingualContentMessageReporter into messages view.
It's working well in this view - the part of source/target text is highlighted when the error is selected.
Now, I would like to implement similair functionality in my custom view part. I have a data - text locations, messages etc., but I don't know how to call "select part of source/target text "

After some experiments I ended with using reflection, but I would prefer cleaner way.

I'm curious if such sollution can be used in public plugin

 var target = doc.Selection.Target;
var cs = GetProperty("ContentSelection", target);
MethodInfo methodInfo = cs.GetType().GetMethod("MoveTo", new Type[] { typeof(ContentRange) });
var from = GetProperty("ContentSelection.From", target);
var pos = new Position((Position) from);
pos.TextOffset = error.Start.TextOffset;
var endPos = new Position(pos);
endPos.TextOffset = error.End.TextOffset;
var contentRange = new ContentRange(pos, endPos);
var result = methodInfo.Invoke(cs, new object[] { contentRange });
public object GetProperty(string compoundProperty, object target)
string[] bits = compoundProperty.Split('.');
for (int k = 0; k < bits.Length; k++)
PropertyInfo propertyToGet = target.GetType().GetProperty(bits[k], BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
target = propertyToGet.GetValue(target, null);
return target;

2 Replies Latest Replies: 30 Oct 2018 12:04 AM by Angela Sigee
  • Hi Lubos,

    I'm afraid there isn't another way to get to the ContentSelection, but then you have an IContentSelection instance which exposes (among other methods / properties) MoveTo and From, so there is no need to further use reflection.