<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br>On 16.01.2014, at 16:38, Allan Odgaard <<a href="mailto:mailinglist@textmate.org">mailinglist@textmate.org</a>> wrote:<br><br><blockquote type="cite">On 16 Jan 2014, at 21:42, Kai Wood wrote:<br><br><blockquote type="cite" style="font-family: DejaVuSansMono; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I need the first and last line number in a range of lines where either a blinking cursor or a selection appears in the document. Only visible selections count.<br></blockquote><br>Here is a ruby function that parses the selection string syntax and maps it to a “first, last” line that is rendered selected:<br><br>   def parse_selection_string(str)<br>     str.split('&').map do |range|<br>       if range =~ /(\d+)(?::(\d+))?(?:\+\d+)?(?:([-x])(\d+)(?::(\d+))?(?:\+\d+)?)?/<br>         l1, l2, c1, c2 = $1.to_i, ($4 ? $4.to_i : nil), ($2 || 1).to_i, ($5 || 1).to_i<br>         l1, l2, c1, c2 = l2, l1, c2, c1 if l2 && (l1 > l2 || l1 == l2 && c2 > c1)<br><br>         case $3<br>           when 'x'<br>             [ l1, l2 ]<br>           when '-'<br>             l2 -= 1 if c2 == 1<br>             [ l1, l2 ]<br>           else<br>             [ l1, l1 ]<br>         end<br>       else<br>         abort "unsupported selection string syntax: ‘#{range}’"<br>       end<br>     end<br>   end<br><br>You may want to post-process the result to merge overlapping ranges.<br></blockquote><br><div>I hope this will not cost you a sleepless night, because…</div><div><br></div><div><img apple-inline="yes" id="0FAF880F-0724-410B-8007-A52EB5217ED4" height="421" width="717" apple-width="yes" apple-height="yes" src="cid:6A9CDAE9-07E8-4A49-977F-FA54A42C2D06@boerding.local"></div><div><br></div><div>Result: [[18, 22], [4, 3], [11, 11]] (Lowest value: 3, one less on the minimum side)</div><div><br></div><div>But a very nice try anyway, thanks!</div><div><br></div></body></html>