XCSourceTextBuffer should provide a simple way to get all selected text
| Originator: | pearapps | ||
| Number: | rdar://27293613 | Date Originated: | July 11, 2016 |
| Status: | Open | Resolved: | |
| Product: | OS X SDK | Product Version: | Xcode 8 beta 2 |
| Classification: | Reproducible: | Always |
Currently the easiest way to get all the selected text using XcodeKit, is to: - Iterate through XCSourceEditorCommandInvocation's XCSourceTextBuffer's selection property - Cast each member to XCSourceTextRange - Iterate through the lines property on the XCSourceTextRange - Include only the lines in between XCSourceTextRange's start and end - Figure out how to limit it to the correct "columns" in each line While I understand the flexibility allowed by exposing all of these things and how fundamental these are to how extensions work, it feels like a lot of custom logic must be implemented simply to get selected text. I also understand that some extensions should strictly interface with XcodeKit with these abstractions, specifically with the row/column one. However, I fear that every extension that must simply take some selected text and perform an action on it that doesn't modify selection will implement their own way of doing this operation that probably will not cover all edge cases, which in turn will introduce subtle differences between selection behavior in different extensions (and potentially even crashes) Steps to Reproduce: 1. Set up new extension for Xcode. 2. Try to get selected text from the invocation object. Expected Results: It is easy to safely get the selected text. Actual Results: It is pretty convoluted to get the selected text.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!