<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi there, I’m currently working on updating an old plugin (EditorConfig — <a href="https://github.com/mr0grog/editorconfig-textmate" class="">https://github.com/mr0grog/editorconfig-textmate</a>) 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).<div class=""><br class=""></div><div class="">To address selections, the most straightforward method I could find was to use `OakTextView accessibilityAttributeValue:<br class="">NSAccessibilitySelectedTextRangesAttribute` (and the associated setter), like so:<div class=""><br class=""></div><div class=""><div class=""><font face="Courier" class="">    NSString *content = [document performSelector:@selector(content)];</font></div><div class=""><font face="Courier" class="">    NSMutableArray<NSValue *> *selections =</font></div><div class=""><font face="Courier" class="">      [textView accessibilityAttributeValue:NSAccessibilitySelectedTextRangesAttribute];</font></div><div class=""><font face="Courier" class="">    //</font></div><div class=""><font face="Courier" class="">    // do some stuff to manipulate `content` and `selections` here...</font></div><div class=""><font face="Courier" class="">    //</font></div><div class=""><font face="Courier" class="">    [document performSelector:@selector(setContent:) withObject:content];</font></div><div class=""><font face="Courier" class="">    [textView accessibilitySetValue:selections forAttribute:NSAccessibilitySelectedTextRangesAttribute];</font></div></div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">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).</div><div class=""><br class=""></div><div class="">Thanks for any advice,</div><div class=""><br class=""></div><div class="">-Rob</div></div></body></html>