[SVN] BUG: Output Text not inserted at caret when input is Scope
Alain O'Dea
alain.odea at gmail.com
Sat Feb 9 23:23:57 UTC 2008
On 8-Feb-08, at 3:03 PM, Joachim Mårtensson wrote:
> Here is the code in question
>
> require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
> don't forget to escape the relevant parts as I have done below with
> e_sn
>
> class String
> def index_of_nth_occurrence_of(n, ch)
> self.unpack("U*").each_with_index do |e, i|
> return i if e == ch && (n -= 1) == 0
> end
> return -1
> end
> end
>
> def caret_position(line)
> tmp = ENV['TM_LINE_NUMBER'].to_i - ENV['TM_INPUT_START_LINE'].to_i
> if tmp > 0
> caret_placement = line.index_of_nth_occurrence_of(tmp,?\n) +
> ENV['TM_LINE_INDEX'].to_i
> else
> caret_placement
> =ENV['TM_LINE_INDEX'].to_i-ENV['TM_INPUT_START_LINE_INDEX'].to_i - 1
> end
> end
>
> line = STDIN.read
> caret_placement = caret_position(line)
>
> print e_sn(line[0..caret_placement]) + res +
> e_sn(line[caret_placement + 1
> ..-1])
It looks like the Objective-C completion drops in a snippet with no
placeholders, but with a cursor position. This will work for my needs.
I just need to rebuild the scope and inject the chosen completion and
a $0 to position the caret.
Thank you :)
More information about the textmate-dev
mailing list