Skip to content

Commit

Permalink
Merge pull request #4 from LordBrom/master
Browse files Browse the repository at this point in the history
Adding command to select all the duplicate lines.
  • Loading branch information
qur2 authored Oct 17, 2017
2 parents 6067539 + 482b174 commit 56ad683
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
{
"caption": "Highlight Duplicates: Toggle highlighting",
"command": "toggle_highlight_duplicates"
},
{
"caption": "Select Duplicates",
"command": "toggle_select_duplicates"
}
]
]
5 changes: 4 additions & 1 deletion highlight_duplicates.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"highlight_duplicates_color" : "invalid",

// By default plugin is enabled or disabled (true|false)
"highlight_duplicates_enabled" : true
"highlight_duplicates_enabled" : true,

// If true, whitespace gets trimmed off each line before checking for matching lines
"ignore_white_space" : true
}
30 changes: 29 additions & 1 deletion hightlight_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def count_lines(lines, view):
'''
counts = defaultdict(list)
for line in lines:
string = view.substr(line).strip()
if bool(settings.get('ignore_white_space', DEFAULT_IS_ENABLED)):
string = view.substr(line).strip()
else:
string = view.substr(line)
if is_candidate(string):
counts[string].append(line)
return counts
Expand Down Expand Up @@ -67,6 +70,15 @@ def show_lines(regions, view):
sublime.DRAW_OUTLINED)


def add_lines(regions, view):
'''Merges all duplicated regions in one set and highlights them.'''
all_regions = []
for r in regions:
for i in r:
print(i)
view.sel().add(i)


def highlight_duplicates(view):
'''Main function that glues everything for hightlighting.'''
# get all lines
Expand All @@ -77,6 +89,17 @@ def highlight_duplicates(view):
show_lines(duplicates.values(), view)



def select_duplicates(view):
'''Main function that glues everything for hightlighting.'''
# get all lines
lines = view.lines(sublime.Region(0, view.size()))
# count and filter out non duplicated lines
duplicates = filter_counts(count_lines(lines, view))
# select duplicated lines
add_lines(duplicates.values(), view)


def downlight_duplicates(window):
'''Removes any region highlighted by this plugin accross all views.'''
for view in window.views():
Expand Down Expand Up @@ -122,3 +145,8 @@ def run(self):
highlight_duplicates(self.window.active_view())
else:
downlight_duplicates(self.window)


class ToggleSelectDuplicatesCommand(sublime_plugin.WindowCommand):
def run(self):
select_duplicates(self.window.active_view())

0 comments on commit 56ad683

Please sign in to comment.