import sublime_plugin


class SelectExactMatchCommand(sublime_plugin.TextCommand):
    last_selection = None

    def run(self, edit):
        selections = self.view.sel()
        if selections[0].empty():
            selections.add(self.view.word(selections[0]))
            return
        word = self.view.substr(self.view.word(selections[0]))
        pattern = "\\b%s\\b" % (word)
        region = self.view.find(pattern, selections[-1].end())
        if not region:
            region = self.view.find(
                pattern,
                self.last_selection.end() if self.last_selection else 0
            )
            if region:
                self.last_selection = region
        else:
            self.last_selection = None
        if region:
            selections.add(region)

    def description():
        return "Select Exact Match"


class SelectAllExactMatchesCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        selections = self.view.sel()
        if selections[0].empty():
            selections.add(self.view.word(selections[0]))
        word = self.view.substr(self.view.word(selections[0]))
        pattern = "\\b%s\\b" % (word)
        selections.add_all(self.view.find_all(pattern))

    def description():
        return "Select All Exact Matches"

@@ -177,76 +177,288 @@
     
-if selections%5B0%5D.empty():%0A            selections.add(self.view.
+words_selection = False%0A        for selection in selections:%0A            if selection.empty():%0A                words_selection = True%0A                region = self.view.word(selection)%0A                selections.add(region)%0A                self.view.show(region)%0A        if 
 word
-(
+s_
 sele
@@ -454,38 +454,33 @@
  words_selection
-s%5B0%5D))
+:
 %0A            ret
@@ -533,33 +533,34 @@
 word(selections%5B
-0
+-1
 %5D))%0A        patt
@@ -993,16 +993,51 @@
 (region)
+%0A            self.view.show(region)
 %0A%0A    de
@@ -1239,17 +1239,18 @@
 ections%5B
-0
+-1
 %5D.empty(
@@ -1297,33 +1297,34 @@
 word(selections%5B
-0
+-1
 %5D))%0A        word
@@ -1369,17 +1369,18 @@
 ections%5B
-0
+-1
 %5D))%0A    

Fix the issue when use with multiple cursors and scroll the view when selected