Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#1328 closed defect (fixed)

richtext/ Editor2 IE selection fix for non-activex mode

Reported by: me@… Owned by: liucougar
Priority: high Milestone:
Component: Widgets Version: 0.3
Keywords: selection Cc:
Blocked By: Blocking:

Description

When using the editor2 in IE in non-activex mode, there are selection problems when using the context menu, or for example the edit/create link dialog. A soon as you press a menu item in the contextmenu or focus an input field the selection in the editor is collapsed, due to IE's behaviour. To fix this I wrote a small patch that saves a selection bookmark just before the editor loses focus, which will be restores when you call the focus() method of the richtext editor.

Attachments (1)

editor2 IE selection fix.patch (3.3 KB) - added by me@… 13 years ago.
patch

Download all attachments as: .zip

Change History (6)

comment:1 Changed 13 years ago by me@…

Index: F:/myweb/dojo/src/widget/RichText.js
===================================================================
--- F:/myweb/dojo/src/widget/RichText.js	(revision 5340)
+++ F:/myweb/dojo/src/widget/RichText.js	(working copy)
@@ -312,6 +312,13 @@
 				dojo.lang.forEach(this.events, function(e){
 					dojo.event.connect(this.editNode, e.toLowerCase(), this, e);
 				}, this);
+
+				//Create a selection bookmark in case of IE + non-activex onbeforedeactive
+				dojo.event.browser.addListener(this.editNode, "beforedeactivate",  dojo.lang.hitch(this,function () {
+					var range = this.document.selection.createRange();
+					dojo.debug("bookmarking selection:" + range.htmlText);
+					this.ieSelectionBookmark = range.getBookmark();
+				}));
 				
 				this.onLoad();
 			} else { // designMode in iframe
@@ -324,7 +331,6 @@
 			
 			this.isClosed = false;
 		},
-
 		_hasCollapseableMargin: function(element, side) {
 			// check if an element has padding or borders on the given side
 			// which would prevent it from collapsing margins
@@ -886,9 +892,11 @@
 		},
 		
 		onClick: function(e){ this.onDisplayChanged(e); },
-		onBlur: function(e){ },
+		onBlur: function(e){},
 		_initialFocus: true,
 		onFocus: function(e){ 
+			this.ieSelectionBookmark = null; //clear any IE selection bookmark created
+			
 			//what's this for?
 			if( (dojo.render.html.mozilla)&&(this._initialFocus) ){
 				this._initialFocus = false;
@@ -906,8 +914,17 @@
 		},
 		
 		focus: function () {
-			if(this.iframe) { this.window.focus(); }
-			else if(this.object) { this.document.focus(); }
+			if(this.iframe) { 
+				if(dojo.render.html.ie && !this.useActiveX && this.ieSelectionBookmark) {
+					//Restore the selection in the iframe, if we got a selectionBookmark
+					dojo.debug("Repair IE selection");
+					var r = this.document.body.createTextRange();
+					r.moveToBookmark(this.ieSelectionBookmark);
+					r.select();
+					this.ieSelectionBookmark = null;
+				} else 
+					this.window.focus(); 
+			} else if(this.object) { this.document.focus(); }
 			// editNode may be hidden in display:none div, lets just punt in this case
 			else if(this.editNode && dojo.lang.isFunction(this.editNode.focus)) { this.editNode.focus(); }
 		},
Index: F:/myweb/dojo/src/widget/templates/Editor2/Dialog/createlink.html
===================================================================
--- F:/myweb/dojo/src/widget/templates/Editor2/Dialog/createlink.html	(revision 5340)
+++ F:/myweb/dojo/src/widget/templates/Editor2/Dialog/createlink.html	(working copy)
@@ -41,6 +41,7 @@
 
 this.ok = function(){
 	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
+	curInst.focus();
 	if(!this.linkNode){
 		var html = dojo.withGlobal(curInst.window, "getSelectedHtml", dojo.html.selection);
 	}else{
Index: F:/myweb/dojo/src/event/browser.js
===================================================================
--- F:/myweb/dojo/src/event/browser.js	(revision 5340)
+++ F:/myweb/dojo/src/event/browser.js	(working copy)
@@ -218,7 +218,8 @@
 		if(!evt){
 			if(window["event"]){
 				evt = window.event;
-			}
+			}else if(sender.document && sender.document.parentWindow && sender.document.parentWindow.event)
+				evt = sender.document.parentWindow.event;
 		}
 		
 		if((evt["type"])&&(evt["type"].indexOf("key") == 0)){ // key events

Changed 13 years ago by me@…

patch

comment:2 Changed 13 years ago by liucougar

Milestone: 0.4
Owner: changed from bill to liucougar

comment:3 Changed 13 years ago by liucougar

Resolution: fixed
Status: newclosed

(In [5571]) fixes #1328: richtext/ Editor2 IE selection fix for non-activex mode menu2 restores the original selection when close (before executing the onclick handler)

comment:4 Changed 13 years ago by liucougar

(In [6151]) references #1328: fixed dialog selection issue for none-activex mode IE

comment:5 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.