html - Code to make a DHTMLEd control replace straight quotes with curly quotes -


i've got old, legacy vb6 application uses dhtml editing control html editor. microsoft dhtml editing control, a.k.a. dhtmled, nothing more ie control using ie's own native editing capability internally.

i'd modify app implement smart quotes word. specifically, " replaced or , ' replaced or appropriate typed; , if user presses ctrl+z after replacement, goes being straight quote.

does have code that?

if don't have code dhtml/vb6, have javascript code works in browser contenteditable regions, use that, too

here's vb6 version:

private sub dhtmledit1_onkeypress()     dim e object     set e = dhtmledit1.dom.parentwindow.event     'perform smart-quote replacement'     select case e.keycode     case 34: 'double-quote'         e.keycode = 0         if isatwordend             insertdoubleundo chrw$(8221), chrw$(34)         else             insertdoubleundo chrw$(8220), chrw$(34)         end if     case 39: 'single-quote'         e.keycode = 0         if isatwordend             insertdoubleundo chrw$(8217), chrw$(39)         else             insertdoubleundo chrw$(8216), chrw$(39)         end if     end select end sub  private function isletter(byval character string) boolean     isletter = ucase$(character) <> lcase$(character) end function  private sub insertdoubleundo(visibletext string, hiddentext string)     dim selection object     set selection = dhtmledit1.dom.selection.createrange()     selection.text = hiddentext     selection.movestart "character", -len(hiddentext)     selection.text = visibletext end sub  private function isatwordend() boolean      dim ch string     ch = previouschar     isatwordend = (ch <> " ") , (ch <> "")  end function  private function previouschar() string      dim selection object     set selection = m_dom.selection.createrange()     selection.movestart "character", -1     previouschar = selection.text  end function 

note: solution inserts additional level in undo chain. example, typing "this test" gives chain of “this test” -> “this test" -> “this test -> “ -> " (extra level in bold). remove level you'd have implement sort of postmessage+subclassing solution doesn't involve cancelling native keypress

edit: don't forget include dhtml editing control redistributable if targeting windows vista.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -