Forum closed. New forum available at http://community.wymeditor.org/

Editor cursor/focus issue

Discuss features, code, contributions, ideas, suggestions, ...
For bugs, patches and feature requests, please post on the Trac:
http://trac.wymeditor.org/

Editor cursor/focus issue

Postby oraknabo on Mon Feb 23, 2009 10:25 pm

Is there a way to force a cursor into the editor window when there isn't any focus on the editor?

I wrote a little function that inserts selected content from outside the editor as a new paragraph at the cursor. This is useful for things like quoting on message boards. It always works fine if there is a cursor, but when I do it without a cursor, it adds an uneditable paragraph before the inserted content.

It seems to me the easiest solution is for me to force focus on the last line of the editor before inserting the outside content, but nothing I've tried with focus() works. Any suggestions?
oraknabo
 
Posts: 8
Joined: Tue Feb 17, 2009 12:04 am

Re: Editor cursor/focus issue

Postby mr_lundis on Tue Feb 24, 2009 5:57 pm

There is already a functions for this inside WYMeditor, see [urlhttp://trac.wymeditor.org/trac/wiki/0.5/API#insertdata]the docs[/url] for more info.

Cheers ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Editor cursor/focus issue

Postby oraknabo on Tue Feb 24, 2009 7:37 pm

Thanks for replying.

Yes, I'm already using insert(data) inside the function, the problem is that if there isn't focus on the browser window when you execute insert(data), it adds a paragraph before the inserted data that can not be edited.

I just want to make sure there is a cursor in the editor before insert(data) is called.
oraknabo
 
Posts: 8
Joined: Tue Feb 17, 2009 12:04 am

Re: Editor cursor/focus issue

Postby mr_lundis on Wed Feb 25, 2009 4:54 pm

In which browser(s) does this occur?
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Editor cursor/focus issue

Postby oraknabo on Wed Feb 25, 2009 6:14 pm

Firefox 3.0.6 on ubuntu 8.10
I haven't checked to see if it behaves any differently in another browser or OS.
oraknabo
 
Posts: 8
Joined: Tue Feb 17, 2009 12:04 am

Re: Editor cursor/focus issue

Postby mr_lundis on Thu Feb 26, 2009 4:42 pm

Okay, the issue here is that you're trying to insert block level content using insert, which was primary intended for inline content. The insert method falls back to the paste method if it can't find any selection within the editor, and the paste method doesn't handle non inline things very well.

First I tried to create a new selection inside the editor to avoid this, which worked somewhat well. But when I wanted to collapse the selection (so that insert wouldn't replace all the content) Firefox just kept throwing exceptions at me. So I went for another approach - appending the html elements directly to the body. Doing so works perfectly!

Code: Select all
html = "<p>A paragraph</p>";
wym = jQuery.wymeditors(0);
jQuery("body", wym._iframe.contentDocument).append(jQuery(html, wym._iframe.contentDocument));


Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Editor cursor/focus issue

Postby oraknabo on Mon Mar 02, 2009 10:10 pm

Thanks, I'll try that.
oraknabo
 
Posts: 8
Joined: Tue Feb 17, 2009 12:04 am


Return to Developers

Who is online

Users browsing this forum: No registered users and 1 guest