×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Editable WebBrowser commands - enter key new list item

Editable WebBrowser commands - enter key new list item

Editable WebBrowser commands - enter key new list item

(OP)
Alright, I've been working on a HTML editor for an application, but lists aren't behaving properly.

I'm using WebBrowser.Document.Body.SetAttribute("contenteditable", "true"); to make the WebBrowser editable.

I'm creating lists by using ExecCommand("InsertUnorderedList", false, null).

I'm also trapping KeyDown and checking for the enter key. If shift is also pressed, inserting a BR and if not ExecCommand("InsertParagraph", false, null).

However, I want it so that when in a list (ordered or unordered - which I can already detect), a new list item is created at the cursor, carrying what is to the right of the cursor down to the next list item.

Is there a way I can get the WebBrowser to do this?

RE: Editable WebBrowser commands - enter key new list item

Borvik,
You need to decouple your feature need from your programming need.

You said you can already check for "InList" and you already have a method for creating the snippet for a new LI. At this point you just need to check if you're at the end of the line and if not add a another call to "ExecCommand("InsertPara..."

At least, that's what my Friday morning pre-coffee brain thinks.

Lodlaiden

You've got questions and source code. We want both!
Oh? That? That's not an important password. - IT Security Admin (pw on whiteboard)

RE: Editable WebBrowser commands - enter key new list item

(OP)
Well, I'm not certain what checking for the "end of line" has to do with it.

If I understood you correctly, here is what I think you were trying to say:

If you are within a list and the cursor is not at the end:
  • One |Two Three Four
Then when I press "Enter" is should run ExecCommand("InsertParagraph", false, null) and it would result in:
  • One
  • |Two Three Four
Unfortunately I have tried that and it is not what is happening. I end up getting this code:

CODE

<ul><li>One <p></p>Two Three Four</li></ul>

RE: Editable WebBrowser commands - enter key new list item

I thought I had understood your initial statement to indicate that you were using that for vanity line breaks (for the designers edification, not for real display).
You need to call whatever function you have for actually doing a CR+LF.

The checking for end of line is so that you don't wind up with a slew of unneeded CR+LF's.
BTW, if you're IN an <LI> </LI>, then wouldn't you would need to insert a </LI> {CR+LF} <LI>?

Lod

You've got questions and source code. We want both!
Oh? That? That's not an important password. - IT Security Admin (pw on whiteboard)

RE: Editable WebBrowser commands - enter key new list item

(OP)
This is my first foray into an editable WebBrowser, and I've been trying to incorporate some features - like this - into it so that it behaves as the user would expect it to.

Unfortunately without doing any trapping or key checking, pressing enter is triggering the forms AcceptButton - so even new paragraphs were failing.

So on trapping Document.Body.KeyDown I have the following code:

CODE

if (e.KeyPressedCode == 13)
{
if (e.ShiftKeyPressed) InsertBr(); //uses an IHTMLTxtRange with pasteHTML('<br />');
else wb.Document.ExecCommand("InsertParagraph", false, null);
}

Before I can here I was thinking I needed to insert an "</li><li>" and using "doc.queryCommandState("InsertOrderedList");" I had this for the above else statement:

CODE

else
{
if (IsOrderedList() || IsUnorderedList()) InsertHtml("</li><li>");
else wb.Document.ExecCommand("InsertParagraph", false, null);
}

What is weird is that when I had that before it wasn't working properly. Though I just tried it again, and for some reason it's working now. Why it's working now, and not earlier I don't know.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close