-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix vim editing (Linux) + group related fs events #212
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,14 +156,63 @@ def _wait_for_changes | |
|
||
def _pop_changes | ||
popped = [] | ||
popped << @changes.pop until @changes.empty? | ||
popped << @changes.shift until @changes.empty? | ||
popped | ||
end | ||
|
||
def _smoosh_changes(changes) | ||
if _local_fs? | ||
_squash_changes(changes) | ||
else | ||
smooshed = { modified: [], added: [], removed: [] } | ||
changes.each { |h| type = h.keys.first; smooshed[type] << h[type].to_s } | ||
smooshed.each { |_, v| v.uniq! } | ||
smooshed | ||
end | ||
end | ||
|
||
def _local_fs? | ||
not registry[:adapter].is_a? Adapter::TCP | ||
end | ||
|
||
def _squash_changes(changes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
smooshed = { modified: [], added: [], removed: [] } | ||
changes.each { |h| type = h.keys.first; smooshed[type] << h[type].to_s } | ||
smooshed.each { |_, v| v.uniq! } | ||
|
||
actions = {} | ||
|
||
# group by file for more readable code below | ||
changes.each do |change| | ||
type = change.keys.first | ||
path = change[type] | ||
|
||
actions[path] ||= [] | ||
actions[path] << type | ||
end | ||
|
||
actions.each do |path, action_list| | ||
action = nil | ||
|
||
# This is to distinquish e.g. 'touch' (a+m) from 'vim patchmode' ('m+r+a+m') | ||
# (touch "adds" a file, while edit "modifies" a file) | ||
added_count = action_list.count {|x| x == :added } | ||
removed_count = action_list.count {|x| x == :removed } | ||
diff = added_count - removed_count | ||
|
||
if path.exist? | ||
|
||
if diff > 0 | ||
action = action_list.detect {|x| x == :added } | ||
elsif diff.zero? and added_count > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here with
|
||
action = :modified | ||
end | ||
|
||
action ||= action_list.detect {|x| x == :modified } | ||
elsif diff < 0 | ||
action = action_list.detect {|x| x == :removed } | ||
end | ||
|
||
smooshed[action] << path.to_s if action | ||
end | ||
smooshed | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to follow bbatsov Ruby style guideline, please could you change it to:
!registry[:adapter].is_a?(Adapter::TCP)