Browse Source

搜索时允许使用正则。

oldj 10 years ago
parent
commit
2a418f0aec
4 changed files with 20 additions and 5 deletions
  1. 1 0
      README.md
  2. 1 1
      app/SH3/MacGap/SwitchHosts!-Info.plist
  3. 0 0
      app/SH3/public/js/main.js
  4. 18 4
      app/src/main.js

+ 1 - 0
README.md

@@ -32,6 +32,7 @@ SwitchHosts! 的数据文件在 `~/.SwitchHosts` 目录下,其中 `~/.SwitchHo
 
 ### v3.1
 
+ - 2016-01-15 搜索时增加模糊搜索支持(eg. `go*le` matches `google`)及正则支持(eg. `/go.*le` matches `google`)
  - 2016-01-10 远程方案可以设置自动更新时间。
  - 2015-12-26 实现 Tray 菜单切换、Dock 图标隐藏、方案导入导出等功能。
  - 2015-12-20 从 Electron 切换至 MacGap 。

+ 1 - 1
app/SH3/MacGap/SwitchHosts!-Info.plist

@@ -21,7 +21,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>2954</string>
+	<string>2968</string>
 	<key>LSApplicationCategoryType</key>
 	<string>public.app-category.developer-tools</string>
 	<key>LSMinimumSystemVersion</key>

File diff suppressed because it is too large
+ 0 - 0
app/SH3/public/js/main.js


+ 18 - 4
app/src/main.js

@@ -375,11 +375,25 @@ var app = new Vue({
 
             // 模糊搜索
             var r;
-            if (kw.indexOf('*') > -1) {
-                r = new RegExp(kw.replace(/\*/g, '.*'));
-                if (r.test(item.content)) {
-                    return true;
+            var m;
+            var flag = [];
+            if ((m = kw.match(/^\/(.+?)\/?(\w*)$/))) {
+                if (m[2].indexOf('i') > -1) {
+                    flag.push('i');
                 }
+                if (m[2].indexOf('g') > -1) {
+                    flag.push('g');
+                }
+                try {
+                    r = new RegExp(m[1], flag.join(''));
+                } catch (e) {}
+            } else if (kw.indexOf('*') > -1) {
+                try {
+                    r = new RegExp(kw.replace(/\*/g, '.*'), 'ig');
+                } catch (e) {}
+            }
+            if (r && r.test(item.content)) {
+                return true;
             }
 
             return false;

Some files were not shown because too many files changed in this diff