Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editable WebBrowser commands - enter key new list item

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
US
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?
 
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)
 
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:
[ul]
[li]One |Two Three Four[/li]
[/ul]
Then when I press "Enter" is should run ExecCommand("InsertParagraph", false, null) and it would result in:
[ul]
[li]One [/li]
[li]|Two Three Four[/li]
[/ul]

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>
 
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)
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top