Bug 421004 - Browser issues with embedding Orion v3.0 Editor in HTML source (scrolling problem)
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/edit.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/edit.js
index 96874dd..235c819 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/edit.js
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/edit.js
@@ -129,6 +129,7 @@
 		return options;
 	}
 	
+	/**	@private */
 	function getParents(document, className) {
 		if (document.getElementsByClassName) {
 			return document.getElementsByClassName(className);
@@ -166,6 +167,7 @@
 	 * @property {Boolean} [showAnnotationRuler=true] whether or not the annotation ruler is shown.
 	 * @property {Boolean} [showOverviewRuler=true] whether or not the overview ruler is shown.
 	 * @property {Boolean} [showFoldingRuler=true] whether or not the folding ruler is shown.
+	 * @property {Boolean} [noFocus=false] whether or not to focus the editor on creation.
 	 * @property {Number} [firstLineIndex=1] the line index displayed for the first line of text.
 	 */
 	/**
@@ -185,8 +187,10 @@
 				var parents = getParents(doc, options.className);
 				if (parents) {
 					options.className = undefined;
+					// Do not focus editors by default when creating multiple editors
+					if (parents.length > 1 && options.noFocus === undefined) { options.noFocus = true; }
 					var editors = [];
-					for (var i = 0; i < parents.length; i++) {
+					for (var i = parents.length - 1; i >= 0; i--) {
 						options.parent = parents[i];
 						editors.push(edit(options));
 					}
@@ -307,7 +311,7 @@
 		editor.setAnnotationRulerVisible(options.showAnnotationRuler === undefined || options.showFoldingRuler);
 		editor.setOverviewRulerVisible(options.showOverviewRuler === undefined || options.showOverviewRuler);
 		editor.setFoldingRulerVisible(options.showFoldingRuler === undefined || options.showFoldingRuler);
-		editor.setInput(options.title, null, contents);
+		editor.setInput(options.title, null, contents, false, options.noFocus);
 		
 		syntaxHighlighter.highlight(options.lang, editor);
 		if (contentAssist) {
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 98350a6..439ca9d 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
@@ -1006,8 +1006,9 @@
 		 * @param {String} message
 		 * @param {String} contents
 		 * @param {Boolean} contentsSaved
+		 * @param {Boolean} noFocus
 		 */
-		setInput: function(title, message, contents, contentsSaved) {
+		setInput: function(title, message, contents, contentsSaved, noFocus) {
 			if (this._textView) {
 				if (!contentsSaved) {
 					if (message) {
@@ -1020,7 +1021,9 @@
 						}
 					}
 					this._undoStack.reset();
-					this._textView.focus();
+					if (!noFocus) {
+						this._textView.focus();
+					}
 				}
 				this.checkDirty();
 			}