rplugin/ruby/sources/LeftBracketAdder.rb
# modified the existing buffer
# returns the new caret position (after it inserts "]")
modified the existing buffer
returns the new caret position (after it inserts "]")
modified the existing buffer returns the new caret position ( after it inserts " ] " )
def apply_inserted_line()
    inserted_lines = self.get_inserted_line
    return @caret_location.x unless inserted_lines
    modified_lines = inserted_lines.split("\n")
    if @modified_begin_location.x > 0
      first_line = @buffer[@modified_begin_location.y]
      modified_lines[0] =  first_line[0..@modified_begin_location.x - 1] + modified_lines[0]
    end
    current_line = modified_lines[@caret_location.y]
    match = current_line.match(/\$0/)
    return @caret_location.x unless match 
    index = match.begin(0)
    if index > 0
      modified_lines[@caret_location.y] = current_line[0..index-1] + current_line[index+2..-1]
    else
      modified_lines[@caret_location.y] = current_line[2..-1]
    end
    for i in (0..@caret_location.y) 
      if modified_lines[i] != @lines[i]
        @buffer[i + @modified_begin_location.y] = modified_lines[i]
      end
    end
    return index
  end
def apply_inserted_line ( ) inserted_lines = self . get_inserted_line return @caret_location . x unless inserted_lines modified_lines = inserted_lines . split ( "\n" ) if @modified_begin_location . x > 0 first_line = @buffer [ @modified_begin_location . y ] modified_lines [ 0 ] = first_line [ 0 .. @modified_begin_location . x - 1 ] + modified_lines [ 0 ] end current_line = modified_lines [ @caret_location . y ] match = current_line . match ( / \$ 0 / ) return @caret_location . x unless match index = match . begin ( 0 ) if index > 0 modified_lines [ @caret_location . y ] = current_line [ 0 .. index - 1 ] + current_line [ index + 2 .. - 1 ] else modified_lines [ @caret_location . y ] = current_line [ 2 .. - 1 ] end for i in ( 0 .. @caret_location . y ) if modified_lines [ i ] != @lines [ i ] @buffer [ i + @modified_begin_location . y ] = modified_lines [ i ] end end return index end
modified the existing buffer
returns the new caret position (after it inserts "]")
modified the existing buffer returns the new caret position ( after it inserts " ] " )
# return original caret # find and remove $0 (the caret after insertion) # something is wrong # the lines after @caret will not be modified