Module: Holistic::Document

Defined in:
lib/holistic/document/cursor.rb,
lib/holistic/document/location.rb,
lib/holistic/document/unsaved/record.rb,
lib/holistic/document/unsaved/collection.rb

Defined Under Namespace

Modules: File, Unsaved

Constant Summary collapse

Cursor =
::Data.define(
  :file_path,
  :line,
  :column
)
Location =
::Data.define(
  :file,
  :start_line,
  :start_column,
  :end_line,
  :end_column
) do
  def identifier
    "#{file.path}[#{start_line},#{start_column},#{end_line},#{end_column}]"
  end

  def contains?(cursor)
    same_file = cursor.file_path == file.path
    contains_line = cursor.line >= start_line && cursor.line <= end_line
    
    contains_column =
      if start_line == end_line
        cursor.column > start_column && cursor.column <= end_column
      elsif start_line == cursor.line
        cursor.column > start_column
      elsif end_line == cursor.line
        cursor.column <= end_column
      else
        true
      end

    same_file && contains_line && contains_column
  end
end