Hi there, I’m currently working on updating an old plugin (EditorConfig — https://github.com/mr0grog/editorconfig-textmate) and it needs to be able to trim the trailing whitespace from lines. I’m currently doing this by getting the OakDocument’s `content` property, editing it, and setting it back, but that can cause selections to move around (not really surprising).
To address selections, the most straightforward method I could find was to use `OakTextView accessibilityAttributeValue: NSAccessibilitySelectedTextRangesAttribute` (and the associated setter), like so:
NSString *content = [document performSelector:@selector(content)]; NSMutableArray<NSValue *> *selections = [textView accessibilityAttributeValue:NSAccessibilitySelectedTextRangesAttribute]; // // do some stuff to manipulate `content` and `selections` here... // [document performSelector:@selector(setContent:) withObject:content]; [textView accessibilitySetValue:selections forAttribute:NSAccessibilitySelectedTextRangesAttribute];
This works great with normal selections, but I had expected column selections to show up as multiple selections here. However, they show up as a single contiguous selection from the starting column on the first row of the selection to the ending column on the last row of the selection. That means that, by the end of this operation, any column selections become normal contiguous text selections.
Is there any straightforward way to get and set column selections from a plugin, where I can’t easily mess with the C++ objects? Is there a better way I should be approaching this whole operation in the first place? (I recognize that my approach above might not be great, but couldn’t find anything else workable; I tried poking at OakTextView’s `filterDocumentThroughCommand` method, but had trouble with it since it requires arguments that are C++ types).
Thanks for any advice,
-Rob
On 3 Jan 2017, at 7:47, Rob Brackett wrote:
Is there any straightforward way to get and set column selections from a plugin, where I can’t easily mess with the C++ objects? Is there a better way I should be approaching this whole operation in the first place?
There isn’t really any API for plug-ins, and since 2.0 is open source, my view is that it’s better to do pull requests for new features, rather than plug-ins, because the latter has a good chance of breaking if they use API that is not marked as public (and pretty much no API is).
The most abstract way to change the document content (from the outside) is via search and replace, although this is easier done from a macro than a plug-in, so you might have to basically execute a macro to get this done.