From 13681b279b9129608a2074a6d87c9dd75aa96c43 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 16 May 2014 03:32:53 -0400 Subject: [PATCH] refactor(edit) add callFocus --- lib/client/edit.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index e38cb3de..a0a246b0 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -38,11 +38,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI isStr = Util.isString(value), name = Info.name, isDir = Info.isDir, - focus = function() { - Ace.focus(); + focus = Util.bind(callFocus, function() { Ace.clearSelection(); Ace.moveCursorTo(0, 0); - }; + }); if (!Loading) { Images.showLoad(); @@ -130,6 +129,11 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI Ace.gotoLine(number); }; + function callFocus(callback) { + Util.exec(callback); + Ace.focus(); + } + function isChanged() { var is, value = Ace.getValue(), @@ -381,15 +385,15 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI Menu = new MenuIO(element, options, { 'Save Ctrl+S' : save, - 'Go To Line Ctrl+G' : Edit.goToLine, - 'Select All Ctrl+A' : function() { + 'Go To Line Ctrl+G' : Util.bind(callFocus, function() { + Edit.goToLine(); + }), + 'Select All Ctrl+A' : Util.bind(callFocus, function() { Ace.selectAll(); - Ace.focus(); - }, - 'Delete Del' : function() { + }), + 'Delete Del' : Util.bind(callFocus, function() { Ace.remove('right'); - Ace.focus(); - }, + }), 'Close Esc' : Edit.hide }); });