Method: Textbringer::Buffer#get_line_and_column

Defined in:
lib/textbringer/buffer.rb

#get_line_and_column(pos) ⇒ Object



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'lib/textbringer/buffer.rb', line 528

def get_line_and_column(pos)
  line = 1 + @contents.byteslice(0...user_to_gap(pos)).count("\n")
  if pos == point_min
    column = 1
  else
    begin
      i = @contents.byterindex("\n", user_to_gap(get_pos(pos, -1)))
    rescue RangeError
      i = nil
    end
    if i
      i += 1
    else
      i = 0
    end
    column = 1 + substring(gap_to_user(i), pos).size
  end
  [line, column]
end