Ticket #21 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Item focus is lost when switching container

Reported by: Moxide Owned by: jf.hovinne
Priority: minor Milestone: 0.2
Component: editor Version: trunk
Keywords: Cc:

Description

Reference : http://forum.wymeditor.org/forum/viewtopic.php?t=80 In Mozilla, when switching a container, focus is lost, so you must click on the container to give the focus back to it.

This piece of (hacky) code might do the trick :

function setFocusToNode(node) {
  if (moz) {
    r=document.createRange();
    r.selectNode(node);
    sel=iframe().contentWindow.getSelection();
    sel.addRange(r);
    sel.collapse(node,0);
    iframe().contentWindow.focus();
  }
}

Attached is a modified 'wym.js' file, implementing the function above (for WYMeditor 0.2.2), in case someone wants to see this function in action.

Attachments

wym.js (23.2 kB) - added by Moxide 3 years ago.
keep_focus_on_nodes.patch (3.0 kB) - added by bermi 3 years ago.

Change History

Changed 3 years ago by Moxide

Changed 3 years ago by jf.hovinne

  • status changed from new to assigned

Great! I've created 0.2 branch and added the code. Changed a little:

sel.collapse(node, 1);

I think it's more convenient than setting the caret at the beginning of the container. OK?

Changed 3 years ago by Moxide

Ok ;-)

I tested it, but the cursor was not displayed at the end of the container, but at the end of its first child. The following seems to work :

sel.collapse(node,node.childNodes.length);

However, it does not work when switching the last container of the page (then, the cursor is set to the beginning of this container).

For IE, the following will roughly do the same :

if (ie) {
    r=document.body.createTextRange();
    r.moveToElementText(node);
    r.collapse(false);
    r.move('character',-1);
    r.select();
    node.focus();
  }

Changed 3 years ago by bermi

I've adapted Moxide changes to the current trunk. It works perfectly on Mozilla. Couldn't test it on IE

Changed 3 years ago by bermi

Changed 3 years ago by jf.hovinne

Great! Applied the patches and fixed MSIE version (trunk). See r257, r259, r261.

Changed 3 years ago by jf.hovinne

  • status changed from assigned to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.