Skip to content

Return grouped objects based on similar actions #16

Description

@archonic

I'm liking the output of sdiff but each "segment" is a separate object. Would it be possible to merge adjacent objects with similar actions into 1 object?

In my case I'm feeding in arrays of sentences. If someone adds a paragraph, the difference is shown as a collection of new sentences. Instead, I would like one <ins> tag around the whole new paragraph.

Update: This is what I've done to accommodate for now

def consolidateDiff(sdiff)
  lastAction = ''
  sdiff.each_with_index do |diff, index|
    if diff.action == lastAction
      sdiff[index-1].old_element << diff.old_element unless sdiff[index-1].old_element.nil?
      sdiff[index-1].new_element << diff.new_element unless sdiff[index-1].new_element.nil?
      sdiff.delete_at(index)
      consolidateDiff(sdiff)
    end
    lastAction = diff.action
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions