refactor
This commit is contained in:
		
							parent
							
								
									97a6b1b69f
								
							
						
					
					
						commit
						1b60c8712e
					
				|  | @ -27,9 +27,20 @@ | ||||||
|                 "LineHeight": "17px" |                 "LineHeight": "17px" | ||||||
|             }, |             }, | ||||||
|             "LatestSessionContent": { |             "LatestSessionContent": { | ||||||
|                 "FileTree": [], |                 "FileTree": [ | ||||||
|                 "Files": [], |                     "E:\\Work\\go\\src", | ||||||
|                 "CurrentFile": "" |                     "E:\\Work\\go\\src\\code.google.com\\p", | ||||||
|  |                     "E:\\Work\\go\\src\\code.google.com\\p\\go.net", | ||||||
|  |                     "E:\\Work\\go\\src\\github.com", | ||||||
|  |                     "E:\\Work\\go\\src\\github.com\\88250", | ||||||
|  |                     "E:\\Work\\go\\src\\github.com\\88250\\gohtml" | ||||||
|  |                 ], | ||||||
|  |                 "Files": [ | ||||||
|  |                     "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\consts.go", | ||||||
|  |                     "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\doc.go", | ||||||
|  |                     "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\formatter.go" | ||||||
|  |                 ], | ||||||
|  |                 "CurrentFile": "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\formatter.go" | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     ] |     ] | ||||||
|  |  | ||||||
|  | @ -371,11 +371,11 @@ var editors = { | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         CodeMirror.commands.autocompleteAfterDot = function (cm) { |         CodeMirror.commands.autocompleteAfterDot = function (cm) { | ||||||
|            var token = cm.getTokenAt(cm.getCursor()); |             var token = cm.getTokenAt(cm.getCursor()); | ||||||
|            if ("comment" === token.type) { |             if ("comment" === token.type) { | ||||||
|                return; |                 return; | ||||||
|            } |             } | ||||||
|              | 
 | ||||||
|             setTimeout(function () { |             setTimeout(function () { | ||||||
|                 if (!cm.state.completionActive) { |                 if (!cm.state.completionActive) { | ||||||
|                     cm.showHint({hint: CodeMirror.hint.go, completeSingle: false}); |                     cm.showHint({hint: CodeMirror.hint.go, completeSingle: false}); | ||||||
|  | @ -448,6 +448,7 @@ var editors = { | ||||||
|                     var request = newWideRequest(); |                     var request = newWideRequest(); | ||||||
|                     request.path = data.path; |                     request.path = data.path; | ||||||
| 
 | 
 | ||||||
|  |                     // TODO: refactor
 | ||||||
|                     $.ajax({ |                     $.ajax({ | ||||||
|                         type: 'POST', |                         type: 'POST', | ||||||
|                         url: '/file', |                         url: '/file', | ||||||
|  | @ -466,7 +467,7 @@ var editors = { | ||||||
| 
 | 
 | ||||||
|                             data.cursorLine = cursorLine; |                             data.cursorLine = cursorLine; | ||||||
|                             data.cursorCh = cursorCh; |                             data.cursorCh = cursorCh; | ||||||
|                             editors.newEditor(data); |                             tree.openFile(wide.curNode); | ||||||
|                         } |                         } | ||||||
|                     }); |                     }); | ||||||
|                 } |                 } | ||||||
|  | @ -577,30 +578,6 @@ var editors = { | ||||||
|         $(".toolbars").show(); |         $(".toolbars").show(); | ||||||
|         var id = wide.curNode.tId; |         var id = wide.curNode.tId; | ||||||
| 
 | 
 | ||||||
|         var cursor = CodeMirror.Pos(0, 0); |  | ||||||
|         if (data.cursorLine && data.cursorCh) { |  | ||||||
|             cursor = CodeMirror.Pos(data.cursorLine - 1, data.cursorCh - 1); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $(".footer .cursor").text('|   ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + '   |'); |  | ||||||
| 
 |  | ||||||
|         for (var i = 0, ii = editors.data.length; i < ii; i++) { |  | ||||||
|             if (editors.data[i].id === id) { |  | ||||||
|                 editors.tabs.setCurrent(id); |  | ||||||
|                 wide.curEditor = editors.data[i].editor; |  | ||||||
|                 var editor = wide.curEditor; |  | ||||||
| 
 |  | ||||||
|                 editor.setCursor(cursor); |  | ||||||
| 
 |  | ||||||
|                 var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2); |  | ||||||
|                 var cursorCoords = editor.cursorCoords({line: cursor.line - half, ch: 0}, "local"); |  | ||||||
|                 editor.scrollTo(0, cursorCoords.top); |  | ||||||
| 
 |  | ||||||
|                 editor.focus(); |  | ||||||
|                 return false; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         editors.tabs.add({ |         editors.tabs.add({ | ||||||
|             id: id, |             id: id, | ||||||
|             title: '<span title="' + wide.curNode.path + '"><span class="' |             title: '<span title="' + wide.curNode.path + '"><span class="' | ||||||
|  | @ -610,9 +587,6 @@ var editors = { | ||||||
| 
 | 
 | ||||||
|         menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install']); |         menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install']); | ||||||
| 
 | 
 | ||||||
|         var rulers = []; |  | ||||||
|         rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"}); |  | ||||||
| 
 |  | ||||||
|         var textArea = document.getElementById("editor" + id); |         var textArea = document.getElementById("editor" + id); | ||||||
|         textArea.value = data.content; |         textArea.value = data.content; | ||||||
| 
 | 
 | ||||||
|  | @ -622,7 +596,7 @@ var editors = { | ||||||
|             autoCloseBrackets: true, |             autoCloseBrackets: true, | ||||||
|             matchBrackets: true, |             matchBrackets: true, | ||||||
|             highlightSelectionMatches: {showToken: /\w/}, |             highlightSelectionMatches: {showToken: /\w/}, | ||||||
|             rulers: rulers, |             rulers: [{color: "#ccc", column: 120, lineStyle: "dashed"}], | ||||||
|             styleActiveLine: true, |             styleActiveLine: true, | ||||||
|             theme: 'wide', |             theme: 'wide', | ||||||
|             indentUnit: 4, |             indentUnit: 4, | ||||||
|  | @ -825,16 +799,18 @@ var editors = { | ||||||
|             editor.setOption("autoCloseTags", true); |             editor.setOption("autoCloseTags", true); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         editor.setCursor(cursor); |  | ||||||
| 
 |  | ||||||
|         var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2); |  | ||||||
|         var cursorCoords = editor.cursorCoords({line: cursor.line - half, ch: 0}, "local"); |  | ||||||
|         editor.scrollTo(0, cursorCoords.top); |  | ||||||
| 
 |  | ||||||
|         wide.curEditor = editor; |         wide.curEditor = editor; | ||||||
|         editors.data.push({ |         editors.data.push({ | ||||||
|             "editor": editor, |             "editor": editor, | ||||||
|             "id": id |             "id": id | ||||||
|         }); |         }); | ||||||
|  | 
 | ||||||
|  |         var cursor = CodeMirror.Pos(0, 0); | ||||||
|  |         if (data.cursorLine && data.cursorCh) { | ||||||
|  |             cursor = CodeMirror.Pos(data.cursorLine - 1, data.cursorCh - 1); | ||||||
|  |         } | ||||||
|  |         $(".footer .cursor").text('|   ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + '   |'); | ||||||
|  |         editor.setCursor(cursor); | ||||||
|  |         editor.focus(); | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
|  | @ -239,7 +239,7 @@ var tree = { | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|          | 
 | ||||||
|         this._initSearch(); |         this._initSearch(); | ||||||
|     }, |     }, | ||||||
|     openFile: function (treeNode) { |     openFile: function (treeNode) { | ||||||
|  | @ -249,12 +249,17 @@ var tree = { | ||||||
|             // 该节点文件已经打开
 |             // 该节点文件已经打开
 | ||||||
|             if (editors.data[i].id === treeNode.tId) { |             if (editors.data[i].id === treeNode.tId) { | ||||||
|                 editors.tabs.setCurrent(treeNode.tId); |                 editors.tabs.setCurrent(treeNode.tId); | ||||||
|                 wide.curNode = treeNode; |  | ||||||
|                 wide.curEditor = editors.data[i].editor; |                 wide.curEditor = editors.data[i].editor; | ||||||
|                 wide.curEditor.focus(); |                  | ||||||
| 
 |  | ||||||
|                 var cursor = wide.curEditor.getCursor(); |                 var cursor = wide.curEditor.getCursor(); | ||||||
|                 $(".footer .cursor").text('|   ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + '   |'); |                 $(".footer .cursor").text('|   ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + '   |'); | ||||||
|  |    | ||||||
|  |                 wide.curEditor.setCursor(cursor); | ||||||
|  |                 var half = Math.floor(wide.curEditor.getScrollInfo().clientHeight / wide.curEditor.defaultTextHeight() / 2); | ||||||
|  |                 var cursorCoords = wide.curEditor.cursorCoords({line: cursor.line - half, ch: 0}, "local"); | ||||||
|  |                 wide.curEditor.scrollTo(0, cursorCoords.top); | ||||||
|  |                 wide.curEditor.focus(); | ||||||
|  | 
 | ||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -288,7 +293,7 @@ var tree = { | ||||||
|         } |         } | ||||||
|     }, |     }, | ||||||
|     _initSearch: function () { |     _initSearch: function () { | ||||||
|          $("#dialogSearchForm > input:eq(0)").keyup(function (event) { |         $("#dialogSearchForm > input:eq(0)").keyup(function (event) { | ||||||
|             var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)"); |             var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)"); | ||||||
|             if (event.which === 13 && !$okBtn.prop("disabled")) { |             if (event.which === 13 && !$okBtn.prop("disabled")) { | ||||||
|                 $okBtn.click(); |                 $okBtn.click(); | ||||||
|  |  | ||||||
|  | @ -262,6 +262,7 @@ var wide = { | ||||||
|                 $("#dialogGoFilePrompt").on("dblclick", "li", function () { |                 $("#dialogGoFilePrompt").on("dblclick", "li", function () { | ||||||
|                     var tId = tree.getTIdByPath($(this).find(".ft-small").text()); |                     var tId = tree.getTIdByPath($(this).find(".ft-small").text()); | ||||||
|                     tree.openFile(tree.fileTree.getNodeByTId(tId)); |                     tree.openFile(tree.fileTree.getNodeByTId(tId)); | ||||||
|  |                     tree.fileTree.selectNode(wide.curNode); | ||||||
|                     $("#dialogGoFilePrompt").dialog("close"); |                     $("#dialogGoFilePrompt").dialog("close"); | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|  | @ -275,6 +276,7 @@ var wide = { | ||||||
|                 hotkeys.bindList($("#dialogGoFilePrompt > input"), $("#dialogGoFilePrompt > .list"), function ($selected) { |                 hotkeys.bindList($("#dialogGoFilePrompt > input"), $("#dialogGoFilePrompt > .list"), function ($selected) { | ||||||
|                     var tId = tree.getTIdByPath($selected.find(".ft-small").text()); |                     var tId = tree.getTIdByPath($selected.find(".ft-small").text()); | ||||||
|                     tree.openFile(tree.fileTree.getNodeByTId(tId)); |                     tree.openFile(tree.fileTree.getNodeByTId(tId)); | ||||||
|  |                     tree.fileTree.selectNode(wide.curNode); | ||||||
|                     $("#dialogGoFilePrompt").dialog("close"); |                     $("#dialogGoFilePrompt").dialog("close"); | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|  | @ -330,6 +332,7 @@ var wide = { | ||||||
|             "ok": function () { |             "ok": function () { | ||||||
|                 var tId = tree.getTIdByPath($("#dialogGoFilePrompt .selected .ft-small").text()); |                 var tId = tree.getTIdByPath($("#dialogGoFilePrompt .selected .ft-small").text()); | ||||||
|                 tree.openFile(tree.fileTree.getNodeByTId(tId)); |                 tree.openFile(tree.fileTree.getNodeByTId(tId)); | ||||||
|  |                 tree.fileTree.selectNode(wide.curNode); | ||||||
|                 $("#dialogGoFilePrompt").dialog("close"); |                 $("#dialogGoFilePrompt").dialog("close"); | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue