Home Forums General XMetaL Discussion What is selected Reply To: What is selected

Derek Read

Reply to: What is selected

Selection.ContainerNode does actually give you the current node. However, the definition of the current node as far as XMetaL is concerned is the element containing the current selection. When you select an entire element the containing node is actually that element's parent. This might be more apparent if you watch the “mini context” that is displayed at the bottom below the document. It is a list of elements like so: root / child1 / child2 / etc... It might also be more clear if you have the Element List open with the Insert radio button selected and then make various selections. If you have the Attribute Inspector open it also displays what XMetaL considers to be the container node at the top (as the default, you have the option to select and set attributes for ancestors as well).

However, I think I understand your issue as some people customizing the product wish to try to “fix” the idea of how XMetaL treats selections and insertion points for their users. You can either write your script assuming your users know how XMetaL treats selections or you can try to “fix” it. However, keep in mind that if you fix this you may introduce further confusion for any users that use the “mini context” to navigate or the Element List to insert elements or the Attribute Inspector to set attribute values.

There are various other APIs that might help here, but you'll need to figure out which because I'm not sure what the final goal is. I think you might experiment with Selection.IsInsertionPoint to figure out if the user has anything selected (anything from a single character up to an entire element returns false). You might then set a Range and try to move it into what you consider to be the correct position by calling Range.Collapse() and then move the Range around. Or perhaps you could store the current Range in a variable, call Range.SelectElement(); and store that in a second variable, then compare the two using IsEqual. If they are different you might assume the “correct” element is actually the ContainerNode of the first Range.