native JS interfering with event system

In hosted mode, the MouseUpHandler works correctly. However, in server mode the event will not occur if getSelectedHtml() is called. The console doesn’t report any errors and indicates that the mouseup event is delivered to the canvas. Commenting out getSelectedHtml will display the SC.say.

		VLayout main = new VLayout();
		main.setPadding(10);
		main.setWidth100();
		main.setHeight100();
		main.setMembersMargin(10);
        
		main.addMouseUpHandler(new MouseUpHandler() {
			public void onMouseUp(MouseUpEvent e) {
				String text = getSelectedHtml();
				SC.say("test");
			}
		});
...
    public static native String getSelectedHtml() /*-{
		if ($wnd.getSelection) {
			var selection = window.getSelection();
			var range = selection.getRangeAt(0);
			if (range != null) {
				var div = document.createElement('div');
				div.appendChild(range.cloneContents());
				return div.toString();
			} else 
				return "";
	    } else if ($doc.getSelection) {
			var selection = $doc.getSelection();
			var range = selection.getRangeAt(0);
			if (range != null) {
				var div = document.createElement('div');
				div.appendChild(range.cloneContents());
				return div.toString();
			} else 
				return "";
	    } else if ($doc.selection) {
	        return $doc.selection.createRange().htmlText;
	    } else
	    	return '';
	}-*/;

Can you add a try / catch around String text = getSelectedHtml(); and add a SC.say call in the catch handler?

Also shouldn’t the code read $wnd.getSelection() instead of window.getSelection()?

If you’re using IE / Firebug or Safari 4, you can add a “debugger;” statement inside the getSelectedHtml() and it will invoke the JS debugger where you can step through the code to see if an exception is being raised in web mode.

attached is the error

Yes, it should have been $wnd instead of window, but that didn’t fix the problem. I have been using FF/Firebug but I can try it with IE and see what the problem is. In other contexts, the JS does work and works in Hosted mode.

Change from window to $wnd did fix problem

My fault when I was testing. I logged in this morning and it was working so I think I failed to clear the browser cache before I tested it.