Browse Source

编辑时复制一份对象,点击 OK 时才将它复制回去。

oldj 10 years ago
parent
commit
65d98bf4fb
6 changed files with 39 additions and 15 deletions
  1. 1 1
      app/SH3/MacGap/SwitchHosts!-Info.plist
  2. 0 0
      app/SH3/public/js/main.js
  3. 5 2
      app/src/main.js
  4. 2 1
      app/src/tt/hl.html
  5. 19 9
      app/src/tt/hl.js
  6. 12 2
      app/src/util.js

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

@@ -21,7 +21,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>2882</string>
+	<string>2890</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


+ 5 - 2
app/src/main.js

@@ -80,9 +80,11 @@ var app = new Vue({
         edit: function (host) {
             this.is_prompt_show = true;
             this.is_edit_show = true;
-            this.current_edit_host = host;
-            this.add_or_edit = 'edit';
+
             host.where = host.where || 'local';
+            this._current_edit_host = host;
+            this.current_edit_host = util.copyObj(host, true);
+            this.add_or_edit = 'edit';
 
             setTimeout(function () {
                 $('#ipt-host-title').focus()
@@ -171,6 +173,7 @@ var app = new Vue({
             //if (this.hosts.list.indexOf(this.current_edit_host) > -1) {
             if (this.add_or_edit == 'edit') {
                 // edit
+                util.updateObj(this._current_edit_host, this.current_edit_host);
                 this.getRemoteHost(this.current_edit_host);
             } else {
                 // add new

+ 2 - 1
app/src/tt/hl.html

@@ -6,6 +6,7 @@
 	<link rel="stylesheet" href="../../../node_modules/codemirror/lib/codemirror.css">
 	<link rel="stylesheet" href="../../../app/SH3/public/css/style.css">
 	<script src="../../../node_modules/codemirror/lib/codemirror.js"></script>
+	<script src="../../../node_modules/codemirror/addon/search/match-highlighter.js"></script>
 </head>
 
 <body>
@@ -20,7 +21,7 @@ bbb #bbb
 255.255.255.255 broadcasthost
 ::1 localhost
 fe80::1%lo0 localhost k1
-	k2
+	k2keywordaaa
 
 </textarea>
 

+ 19 - 9
app/src/tt/hl.js

@@ -15,26 +15,35 @@
 })(function (CodeMirror) {
     "use strict";
 
+    var keyword = 'k';
+
     CodeMirror.defineMode('host', function () {
         function tokenBase(stream) {
             if (stream.eatSpace()) return null;
 
             var sol = stream.sol();
             var ch = stream.next();
+            var styles = [];
 
+            if (stream.match(keyword)) {
+                console.log('match');
+                //stream.eat(keyword);
+                styles.push('hl');
+                stream.skipTo(0);
+            }
             if (ch === '#') {
                 stream.skipToEnd();
-                return 'comment';
-            }
-            if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
-                return 'error';
-            }
-            if (sol && ch.match(/[\w\.:%]/)) {
+                styles.push('comment');
+            } else if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
+                styles.push('error');
+            } else if (sol && ch.match(/[\w\.:%]/)) {
                 stream.eatWhile(/[\w\.:%]/);
-                return 'ip';
+                styles.push('ip');
             }
 
-            return null;
+            stream.next();
+
+            return styles.length > 0 ? styles.join(' ') : null;
         }
 
         function tokenize(stream, state) {
@@ -52,6 +61,7 @@
         };
     });
 
-    CodeMirror.defineMIME('text/x-sh', 'shell');
+
+    //CodeMirror.defineMIME('text/x-sh', 'shell');
 
 });

+ 12 - 2
app/src/util.js

@@ -26,6 +26,16 @@ function isArray(a) {
 }
 exports.isArray = isArray;
 
+function updateObj(o1, o2) {
+    var k;
+    for (k in o2) {
+        if (o2.hasOwnProperty(k)) {
+            o1[k] = o2[k];
+        }
+    }
+}
+exports.updateObj = updateObj;
+
 function copyObj(obj, deep) {
     var type = typeof obj;
     if (type == 'string' || type == 'number' || type == 'boolean') return obj;
@@ -35,7 +45,7 @@ function copyObj(obj, deep) {
         var a = [];
         var i;
         for (i = 0; i < obj.length; i++) {
-            a.push(deep ? copyObj(obj[i]) : obj[i]);
+            a.push(deep ? copyObj(obj[i], deep) : obj[i]);
         }
         return a;
     }
@@ -49,7 +59,7 @@ function copyObj(obj, deep) {
         for (k in obj) {
             if (obj.hasOwnProperty(k)) {
                 v = obj[k];
-                new_obj[k] = deep ? copyObj(v) : v;
+                new_obj[k] = deep ? copyObj(v, deep) : v;
             }
         }
         return new_obj;

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