Method: View.txt_per_prefix

Defined in:
lib/xiki/view.rb

.txt_per_prefix(prefix = nil, options = {}) ⇒ Object

Returns text from view according to prefix…

  • 3 means 3 lines, etc.

  • no prefix means the notes block

  • etc



622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/xiki/view.rb', line 622

def self.txt_per_prefix prefix=nil, options={}
  prefix ||= Keys.prefix(:clear=>1)

  prefix = prefix.abs if prefix.is_a?(Fixnum)
  left, right = [nil, nil]

  case prefix
  when 0   # Do paragraph
    left, right = View.paragraph(:bounds=>true)
  when 1..6   # Should probably catch all numeric prefix?
    left = Line.left
    right = $el.point_at_bol(prefix+1)
  when :-
    left, right = View.range if options[:selection]
  end

  # If no prefixes
  if left == nil
    if options[:default_is_line]
      left, right = [Line.left, Line.right]
    else
      ignore, left, right = View.block_positions("^>")
    end
  end

  Effects.blink(:left=>left, :right=>right) if options[:blink]
  txt = options[:just_positions] ? nil : View.txt(left, right)

  if options[:remove_heading] && txt =~ /^>/
    txt.sub! /.+\n/, ''
    # left won't be fixed, but who cares, for now
  end

  return txt if options[:just_txt]

  return [txt, left, right]
end