Bug 404277 - Embeddable Editor and getSelectionText does not work correctly if style is display:none
diff --git a/bundles/org.eclipse.orion.client.editor/web/examples/editor/edit.html b/bundles/org.eclipse.orion.client.editor/web/examples/editor/edit.html
index a37be29..0de3689 100644
--- a/bundles/org.eclipse.orion.client.editor/web/examples/editor/edit.html
+++ b/bundles/org.eclipse.orion.client.editor/web/examples/editor/edit.html
@@ -5,6 +5,7 @@
 -->
 <html>
 <head>
+<title>Orion Editor Sample</title>
 <link rel="stylesheet" type="text/css" href="../../../orion/editor/themes/default.css"/>
 <style>
 #editor {
@@ -18,7 +19,7 @@
 }
 
 pre {
-	margin-top: 0px;
+	margin: 0px;
 }
 </style>
 <!-- Note if running this standalone you will need to copy requirejs from bundles/org.eclipse.orion.client.core/web/ -->
@@ -39,11 +40,11 @@
 </script>
 </head>
 <body>
-<div id="editor"><pre>/*
+<pre id="editor">/*
  * This is a orion editor sample.
  */
 function () {
 	var a = 'hi there!';
-}</pre></div>
+}</pre>
 </body>
 </html>
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 5899cb4..ba9785a 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
@@ -10,7 +10,7 @@
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
  
-/*globals define */
+/*globals define Node */
 
 define('orion/editor/edit', [ //$NON-NLS-0$
 	
@@ -42,6 +42,22 @@
 ], function(mTextView, mTextModel, mTextTheme, mProjModel, mEventTarget, mKeyBinding, mRulers, mAnnotations, mTooltip, mUndoStack, mTextDND, mEditor, mEditorFeatures, mContentAssist, mCSSContentAssist, mHtmlContentAssist, mJSContentAssist, mAsyncStyler, mMirror, mTextMateStyler, mHtmlGrammar, mTextStyler) {
 
 	/**	@private */
+	function getDisplay(window, document, element) {
+		var display;
+		var temp = element;
+		while (temp && temp !== document && display !== "none") { //$NON-NLS-0$
+			if (window.getComputedStyle) {
+				var style = window.getComputedStyle(temp, null);
+				display = style.getPropertyValue("display"); //$NON-NLS-0$
+			} else {
+				display = temp.currentStyle.display;
+			}
+			temp = temp.parentNode;
+		}
+		return display;
+	}
+
+	/**	@private */
 	function getTextFromElement(element) {
 		var firstChild = element.firstChild;
 		if (firstChild && firstChild.tagName === "TEXTAREA") { //$NON-NLS-0$
@@ -49,7 +65,10 @@
 		}
 		var document = element.ownerDocument;
 		var window = document.defaultView || document.parentWindow;
-		if (!window.getSelection) {
+		if (!window.getSelection ||
+			(element.childNodes.length === 1 && firstChild.nodeType === Node.TEXT_NODE) ||
+			getDisplay(window, document, element) === "none") //$NON-NLS-0$
+		{
 			return element.innerText || element.textContent;
 		}
 		var newRange = document.createRange();