move searchFiles command from setup.js to editorCommands.js
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js
index 3400bbb..3a7b50e 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js
@@ -517,8 +517,9 @@
 				// loop through all modes in case multiple modes are active.  Keep track of whether we processed the key.
 				var keyUsed = false;
 				for (var i=0; i<this._keyModes.length; i++) {
-					if (this._keyModes[i].isActive()) {
-						keyUsed = this._keyModes[i].cancel() || keyUsed;
+					var mode = this._keyModes[i];
+					if (mode.isActive() && mode.cancel) {
+						keyUsed = mode.cancel() || keyUsed;
 					}
 				}
 				return keyUsed;
@@ -526,25 +527,18 @@
 
 			textView.setAction("lineUp", function() { //$NON-NLS-0$
 				for (var i=0; i<this._keyModes.length; i++) {
-					if (this._keyModes[i].isActive()) {
-						return this._keyModes[i].lineUp();
+					var mode = this._keyModes[i];
+					if (mode.isActive() && mode.lineUp) {
+						return mode.lineUp();
 					}
 				}
 				return false;
 			}.bind(this));
 			textView.setAction("lineDown", function() { //$NON-NLS-0$
 				for (var i=0; i<this._keyModes.length; i++) {
-					if (this._keyModes[i].isActive()) {
-						return this._keyModes[i].lineDown();
-					}
-				}
-				return false;
-			}.bind(this));
-
-			textView.setAction("enter", function() { //$NON-NLS-0$
-				for (var i=0; i<this._keyModes.length; i++) {
-					if (this._keyModes[i].isActive()) {
-						return this._keyModes[i].enter();
+					var mode = this._keyModes[i];
+					if (mode.isActive() && mode.lineDown) {
+						return mode.lineDown();
 					}
 				}
 				return false;
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/editorFeatures.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/editorFeatures.js
index 587ee63..461ffc5 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/editorFeatures.js
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/editorFeatures.js
@@ -271,9 +271,17 @@
 			}.bind(this));
 			
 			textView.setAction("tab", function() { //$NON-NLS-0$
+				var editor = this.editor;
+				var keyModes = editor.getKeyModes();
+				for (var j = 0; j < keyModes.length; j++) {
+					var mode = keyModes[j];
+					if (mode.isActive() && mode.tab) {
+						return mode.tab();
+					}
+				}
+
 				if (textView.getOptions("readonly")) { return false; } //$NON-NLS-0$
 				if(!textView.getOptions("tabMode")) { return; } //$NON-NLS-0$
-				var editor = this.editor;
 				var model = editor.getModel();
 				var selection = editor.getSelection();
 				var firstLine = model.getLineAtOffset(selection.start);
@@ -292,14 +300,6 @@
 					editor.setSelection(lineStart === selection.start ? selection.start : selection.start + text.length, selection.end + ((lastLine - firstLine + 1) * text.length));
 					return true;
 				}
-				
-				var keyModes = editor.getKeyModes();
-				for (var j = 0; j < keyModes.length; j++) {
-					if (keyModes[j].isActive()) {
-						return keyModes[j].tab();
-					}
-				}
-				
 				return false;
 			}.bind(this));
 	
@@ -719,6 +719,38 @@
 				}
 				return false;
 			}.bind(this));
+			
+			textView.setAction("enter", function() { //$NON-NLS-0$
+				var editor = this.editor;
+				var keyModes = editor.getKeyModes();
+				for (var j = 0; j < keyModes.length; j++) {
+					var mode = keyModes[j];
+					if (mode.isActive() && mode.enter) {
+						return mode.enter();
+					}
+				}
+
+				// Auto indent
+				var textView = editor.getTextView();
+				if (textView.getOptions("readonly")) { return false; } //$NON-NLS-0$
+				var selection = editor.getSelection();
+				if (selection.start === selection.end) {
+					var model = editor.getModel();
+					var lineIndex = model.getLineAtOffset(selection.start);
+					var lineText = model.getLine(lineIndex, true);
+					var lineStart = model.getLineStart(lineIndex);
+					var index = 0, end = selection.start - lineStart, c;
+					while (index < end && ((c = lineText.charCodeAt(index)) === 32 || c === 9)) { index++; }
+					if (index > 0) {
+						//TODO still wrong when typing inside folding
+						var prefix = lineText.substring(0, index);
+						index = end;
+						while (index < lineText.length && ((c = lineText.charCodeAt(index++)) === 32 || c === 9)) { selection.end++; }
+						editor.setText(model.getLineDelimiter() + prefix, selection.start, selection.end);
+						return true;
+					}
+				}
+			}.bind(this));
 		
 			// Block comment operations
 			textView.setKeyBinding(new mKeyBinding.KeyBinding(191, true), "toggleLineComment"); //$NON-NLS-0$
@@ -925,7 +957,7 @@
 			return false;
 		},
 		isActive: function() {
-			return true;
+			return false;
 		},
 		isStatusActive: function() {
 			// SourceCodeActions never reports status
@@ -938,27 +970,6 @@
 			return false;
 		},
 		enter: function() {
-			// Auto indent
-			var textView = this.editor.getTextView();
-			if (textView.getOptions("readonly")) { return false; } //$NON-NLS-0$
-			var editor = this.editor;
-			var selection = editor.getSelection();
-			if (selection.start === selection.end) {
-				var model = editor.getModel();
-				var lineIndex = model.getLineAtOffset(selection.start);
-				var lineText = model.getLine(lineIndex, true);
-				var lineStart = model.getLineStart(lineIndex);
-				var index = 0, end = selection.start - lineStart, c;
-				while (index < end && ((c = lineText.charCodeAt(index)) === 32 || c === 9)) { index++; }
-				if (index > 0) {
-					//TODO still wrong when typing inside folding
-					var prefix = lineText.substring(0, index);
-					index = end;
-					while (index < lineText.length && ((c = lineText.charCodeAt(index++)) === 32 || c === 9)) { selection.end++; }
-					editor.setText(model.getLineDelimiter() + prefix, selection.start, selection.end);
-					return true;
-				}
-			}
 			return false;
 		},
 		tab: function() {
diff --git a/bundles/org.eclipse.orion.client.ui/web/edit/setup.js b/bundles/org.eclipse.orion.client.ui/web/edit/setup.js
index fd8f3d6..ee0b4c0 100644
--- a/bundles/org.eclipse.orion.client.ui/web/edit/setup.js
+++ b/bundles/org.eclipse.orion.client.ui/web/edit/setup.js
@@ -91,8 +91,7 @@
 
 	var sidebarDomNode = lib.node("sidebar"), //$NON-NLS-0$
 	    sidebarToolbar = lib.node("sidebarToolbar"), //$NON-NLS-0$
-		editorDomNode = lib.node("editor"), //$NON-NLS-0$
-		searchFloat = lib.node("searchFloat"); //$NON-NLS-0$
+		editorDomNode = lib.node("editor"); //$NON-NLS-0$
 
 	var editor, inputManager, settings;
 	var updateSettings = function(prefs) {
@@ -124,45 +123,6 @@
 			return textView;
 		};
 	
-		var tabHandler = {
-			handlers: [],
-			
-			addHandler: function(handler) {
-				this.handlers.push(handler);
-			},
-			
-			cancel: function() {
-				return false;
-			},
-		
-			isActive: function() {
-				for (var i=0; i<this.handlers.length; i++) {
-					if (this.handlers[i].isActive()) {
-						return true;
-					}
-				}
-				return false;
-			},
-		
-			lineUp: function() {
-				return false;
-			},
-			lineDown: function() {
-				return false;
-			},
-			enter: function() {
-				return false;
-			},
-			tab: function() {
-				for (var i=0; i<this.handlers.length; i++) {
-					if (this.handlers[i].isActive()) {
-						return this.handlers[i].tab();
-					}
-					
-				}
-			}
-		};
-	
 		var escHandler = {
 			handlers: [],
 			
@@ -187,26 +147,11 @@
 					}
 				}
 				return false;
-			},
-		
-			lineUp: function() {
-				return false;
-			},
-			lineDown: function() {
-				return false;
-			},
-			enter: function() {
-				return false;
-			},
-			tab: function() {
-				return false;
 			}
 		};
 		
 		var keyBindingFactory = function(editor, keyModeStack, undoStack, contentAssist) {
 			
-			keyModeStack.push(tabHandler);
-			
 			var localSearcher = new mSearcher.TextSearcher(editor, commandRegistry, undoStack);
 			// Create keybindings for generic editing, no dependency on the service model
 			var genericBindings = new mEditorFeatures.TextActions(editor, undoStack , localSearcher);
@@ -223,80 +168,13 @@
 			
 			// Register commands that depend on external services, the registry, etc.  Do this after
 			// the generic keybindings so that we can override some of them.
-			var commandGenerator = new mEditorCommands.EditorCommandFactory(serviceRegistry, commandRegistry, fileClient, inputManager, "pageActions", isReadOnly, "pageNavigationActions", localSearcher, settings); //$NON-NLS-1$ //$NON-NLS-0$
+			var commandGenerator = new mEditorCommands.EditorCommandFactory(serviceRegistry, commandRegistry, fileClient, inputManager, "pageActions", isReadOnly, "pageNavigationActions", localSearcher, searcher, settings); //$NON-NLS-1$ //$NON-NLS-0$
 			commandGenerator.generateEditorCommands(editor);
-	
 			
 			// give our external escape handler a shot at handling escape
 			keyModeStack.push(escHandler);
 			
 			editor.getTextView().setKeyBinding(new mKeyBinding.KeyBinding('w', true, false, true), "toggleWrapMode"); //$NON-NLS-1$ //$NON-NLS-0$
-			
-			// global search
-			editor.getTextView().setKeyBinding(new mKeyBinding.KeyBinding("h", true), "searchFiles"); //$NON-NLS-1$ //$NON-NLS-0$
-			editor.getTextView().setAction("searchFiles", function() { //$NON-NLS-0$
-				window.setTimeout(function() {
-					var e = editor.getTextView();
-					var selection = e.getSelection();
-					var searchPattern = "";
-					if (selection.end > selection.start) {
-						searchPattern = e.getText().substring(selection.start, selection.end);
-					} if (searchPattern.length <= 0) {
-						searchPattern = prompt(messages["Enter search term:"], searchPattern);
-					} if (!searchPattern) {
-						return;
-					}
-					document.addEventListener("keydown", function (e){  //$NON-NLS-0$
-						if (e.charOrCode === lib.KEY.ESCAPE) {
-							searchFloat.style.display = "none"; //$NON-NLS-0$
-							if(lib.$$array("a", searchFloat).indexOf(document.activeElement) !== -1) { //$NON-NLS-0$
-								editor.getTextView().focus();
-							}
-						}
-					}, false);
-					
-					var searchFloatTabHandler = {
-						isActive: function() {
-							return searchFloat.style.display === "block"; //$NON-NLS-0$
-						},
-						
-						tab: function() {
-							if (this.isActive()) {
-								lib.$("a",searchFloat).focus(); //$NON-NLS-0$
-								return true;
-							}
-							return false;
-						}
-					};
-					tabHandler.addHandler(searchFloatTabHandler);
-					
-					var searchFloatEscHandler = {
-						isActive: function() {
-							return searchFloat.style.display === "block"; //$NON-NLS-0$
-						},
-						
-						cancel: function() {
-							if (this.isActive()) {
-								searchFloat.style.display = "none"; //$NON-NLS-0$
-								return true;
-							}
-							return false;   // not handled
-						}
-					};
-					escHandler.addHandler(searchFloatEscHandler);
-										
-					searchFloat.appendChild(document.createTextNode(messages["Searching for occurrences of "])); 
-					var b = document.createElement("b"); //$NON-NLS-0$
-					searchFloat.appendChild(b);
-					b.appendChild(document.createTextNode("\"" + searchPattern + "\"...")); //$NON-NLS-1$ //$NON-NLS-0$
-					searchFloat.style.display = "block"; //$NON-NLS-0$
-					var searchParams = searcher.createSearchParams(searchPattern, false, true);
-					searchParams.sort = "Name asc"; //$NON-NLS-0$
-					var renderer = searcher.defaultRenderer.makeRenderFunction(null, searchFloat, false);
-					searcher.search(searchParams, inputManager.getInput(), renderer);
-				}, 0);
-				return true;
-			}, {name: messages["Search Files"]}); //$NON-NLS-0$
 		};
 		
 		// Content Assist
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js b/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js
index 0fb227f..1111bf2 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js
@@ -24,7 +24,7 @@
 
 var contentTypesCache = null;
 exports.EditorCommandFactory = (function() {
-	function EditorCommandFactory (serviceRegistry, commandService, fileClient, inputManager, toolbarId, isReadOnly, navToolbarId, searcher, editorSettings) {
+	function EditorCommandFactory (serviceRegistry, commandService, fileClient, inputManager, toolbarId, isReadOnly, navToolbarId, localSearcher, searcher, editorSettings) {
 		this.serviceRegistry = serviceRegistry;
 		this.commandService = commandService;
 		this.fileClient = fileClient;
@@ -32,6 +32,7 @@
 		this.toolbarId = toolbarId;
 		this.pageNavId = navToolbarId;
 		this.isReadOnly = isReadOnly;
+		this._localSearcher = localSearcher;
 		this._searcher = searcher;
 		this.editorSettings = editorSettings;
 	}
@@ -76,12 +77,76 @@
 				}
 			}
 
+			var self = this;
+
+			// global search
+			var searchFloat = lib.node("searchFloat"); //$NON-NLS-0$
+			if (searchFloat && self._searcher) {
+				var searchCommand =  new mCommands.Command({
+					name: messages["Search Files"],
+					tooltip: messages["Search Files"],
+					id: "orion.searchFiles", //$NON-NLS-0$
+					callback: function(data) {
+						editor.getTextView().invokeAction("searchFiles"); //$NON-NLS-0$
+					}
+				});
+				this.commandService.addCommand(searchCommand);
+				this.commandService.registerCommandContribution(this.pageNavId, "orion.searchFiles", 1, null, true, new mKeyBinding.KeyBinding("h", true)); //$NON-NLS-1$ //$NON-NLS-0$
+
+				editor.getTextView().setKeyBinding(new mKeyBinding.KeyBinding("h", true), "searchFiles"); //$NON-NLS-1$ //$NON-NLS-0$
+				editor.getTextView().setAction("searchFiles", function() { //$NON-NLS-0$
+					window.setTimeout(function() {
+						var e = editor.getTextView();
+						var selection = e.getSelection();
+						var searchPattern = "";
+						if (selection.end > selection.start) {
+							searchPattern = e.getText().substring(selection.start, selection.end);
+						} if (searchPattern.length <= 0) {
+							searchPattern = prompt(messages["Enter search term:"], searchPattern);
+						} if (!searchPattern) {
+							return;
+						}
+						document.addEventListener("keydown", function (e){  //$NON-NLS-0$
+							if (e.charOrCode === lib.KEY.ESCAPE) {
+								searchFloat.style.display = "none"; //$NON-NLS-0$
+								if(lib.$$array("a", searchFloat).indexOf(document.activeElement) !== -1) { //$NON-NLS-0$
+									editor.getTextView().focus();
+								}
+							}
+						}, false);
+						searchFloat.appendChild(document.createTextNode(messages["Searching for occurrences of "])); 
+						var b = document.createElement("b"); //$NON-NLS-0$
+						searchFloat.appendChild(b);
+						b.appendChild(document.createTextNode("\"" + searchPattern + "\"...")); //$NON-NLS-1$ //$NON-NLS-0$
+						searchFloat.style.display = "block"; //$NON-NLS-0$
+						var searchParams = self._searcher.createSearchParams(searchPattern, false, true);
+						searchParams.sort = "Name asc"; //$NON-NLS-0$
+						var renderer = self._searcher.defaultRenderer.makeRenderFunction(null, searchFloat, false);
+						self._searcher.search(searchParams, self.inputManager.getInput(), renderer);
+					}, 0);
+					return true;
+				}, searchCommand);
+				var searchFloatMode = {
+					isActive: function() {
+						return searchFloat.style.display === "block"; //$NON-NLS-0$
+					},
+					tab: function() {
+						lib.$("a",searchFloat).focus(); //$NON-NLS-0$
+						return true;
+					},
+					cancel: function() {
+						searchFloat.style.display = "none"; //$NON-NLS-0$
+						return true;
+					}
+				};
+				editor.getKeyModes().push(searchFloatMode);
+			}
+
 			// create commands common to all editors
 			if (!this.isReadOnly) {
 				editor.getTextView().setKeyBinding(new mKeyBinding.KeyBinding('s', true), "save"); //$NON-NLS-1$ //$NON-NLS-0$
 				//If we are introducing other file system to provide save action, we need to define an onSave function in the input manager
 				//That way the file system knows how to implement their save mechanism
-				var self = this;
 				editor.getTextView().setAction("save", function () { //$NON-NLS-0$
 					if (self.inputManager.save) {
 						self.inputManager.save();
@@ -163,14 +228,13 @@
 																			}
 																			return [new mCommandRegistry.CommandParameter('find', 'text', 'Find:', searchString)]; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
 																		});
-				var that = this;
 				var findCommand =  new mCommands.Command({
 					name: messages.Find,
 					tooltip: messages.Find,
 					id: "orion.editor.find", //$NON-NLS-0$
 					parameters: findParameter,
 					callback: function(data) {
-						if (that._searcher) {
+						if (self._localSearcher) {
 							var searchString = "";
 							var parsedParam = null;
 							var selection = editor.getSelection();
@@ -185,20 +249,20 @@
 								}
 							}
 							if(parsedParam){
-								that._searcher.setOptions({useRegExp: parsedParam.regEx, ignoreCase: !parsedParam.caseSensitive});
+								self._localSearcher.setOptions({useRegExp: parsedParam.regEx, ignoreCase: !parsedParam.caseSensitive});
 								if(parsedParam.atLine){
 									var offset = editor.getModel().getLineStart(parsedParam.atLine-1);
 									editor.moveSelection(offset, offset, function(){
-										that._searcher.buildToolBar(searchString, parsedParam.replaceWith);
-										that._searcher.findNext(true);
+										self._localSearcher.buildToolBar(searchString, parsedParam.replaceWith);
+										self._localSearcher.findNext(true);
 										}, 
 									focus);
 								} else {
-									that._searcher.buildToolBar(searchString, parsedParam.replaceWith);
-									that._searcher.findNext(true);
+									self._localSearcher.buildToolBar(searchString, parsedParam.replaceWith);
+									self._localSearcher.findNext(true);
 								}
 							} else {
-								that._searcher.buildToolBar(searchString);
+								self._localSearcher.buildToolBar(searchString);
 							}
 							return true;
 						}