Sha256: abe4b71b2868316a38be3d82cff3f16136585b0eafc9dc1d0d13b4b897186ce9

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

module Ruco
  class Editor
    attr_reader :file
    attr_reader :text_area
    private :text_area
    delegate :view, :color_mask, :cursor,
      :insert, :indent, :unindent, :delete, :delete_line,
      :redo, :undo,
      :selecting, :selection, :text_in_selection, :reset,
      :move, :resize,
      :to => :text_area

    def initialize(file, options)
      @file = file
      content = (File.exist?(@file) ? File.read(@file) : '')
      if content.include?("\t")
        if options[:convert_tabs]
          content.tabs_to_spaces!
        else
          raise "#{@file} contains tabs.\nRuco atm does not support tabs, but will happily convert them to spaces if started with --convert-tabs or -c"
        end
      end
      @saved_content = content
      @text_area = EditorArea.new(content, options)
    end

    def find(text)
      move(:relative, 0,0) # reset selection
      return unless start = text_area.content.index(text, text_area.index_for_position+1)
      finish = start + text.size
      move(:to_index, finish)
      selecting{ move(:to_index, start) }
      true
    end

    def modified?
      @saved_content != text_area.content
    end

    def save
      content = text_area.content
      File.open(@file,'w'){|f| f.write(content) }
      @saved_content = content
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruco-0.0.35 lib/ruco/editor.rb