[TxMt] API for getting/setting column selections

Rob Brackett rob at robbrackett.com
Tue Jan 3 00:47:14 UTC 2017


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20170102/44012a86/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1375 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20170102/44012a86/attachment.p7s>


More information about the textmate mailing list