kankri  committed 9a3928e

Don't match same word more than once

The simpler matching algorithm didn't account that several input patterns might match with a single word from the window. E.g. "wi wi" would not only match
"Windows Explorer" opened in "C:\WINDOWS" but also any other Windows Explorer,
since both of the "wi" patterns were matching the same word "Windows".

  • Participants
  • Parent commits aaf54f8

Comments (0)

Files changed (1)

File plugins/

 		if pattern == "":
+		def match(patterns, inputs):
+			if not patterns:
+				return True
+			pattern = patterns[0]
+			rest = patterns[1:]
+			for i, input in enumerate(inputs):
+				if input.startswith(pattern):
+					if match(rest, inputs[:i]+inputs[i+1:]):
+						return True
+			return False
 		word_split = re.compile(r'\W+', re.UNICODE).split
 		pattern = word_split(pattern)
 		def matcher(inputs):
 			words = [w for input in inputs for w in word_split(input.lower())]
-			return all(any(w.startswith(p) for w in words) for p in pattern)
+			return match(pattern, words)
 		for hwnd, window in self._getTopLevelWindows(matcher):