Sha256: 0c74f7dacdabf527ea410cd300e9304f0095dbb960de23edb7973824c70b3b46

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Ruco
  class Editor
    attr_reader :file
    attr_reader :text_area
    private :text_area
    delegate :view, :color_mask, :cursor,
      :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
      @text_area = EditorArea.new(content, options)
      @modified = false
    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

    %w[insert indent unindent delete delete_line redo undo].each do |modifying|
      eval <<-RUBY
        def #{modifying}(*args)
          text_area.#{modifying}(*args)
          @modified = true
        end
      RUBY
    end

    def modified?
      @modified
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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