Пример #1
0
        /// <summary>
        /// The currently selected text/controls will be replaced by the given HTML code.
        /// If nothing is selected, the HTML code is inserted at the cursor position
        /// </summary>
        /// <param name="sHtml"></param>
        /// <returns></returns>
        public static bool PasteIntoSelection(string sHtml)
        {
            if (_mPDoc2.IsNull())
            {
                return(false);
            }
            var sel = _mPDoc2.selection as IHTMLSelectionObject;

            if (sel.IsNull())
            {
                return(false);
            }
            var range = sel.createRange() as IHTMLTxtRange;

            if (range.IsNull())
            {
                return(false);
            }
            //none
            //text
            //control
            if ((!sel.EventType.IsNullOrEmpty()) &&
                (sel.EventType == "control"))
            {
                var ctlrange = range as IHTMLControlRange;
                if (!ctlrange.IsNull()) //Control(s) selected
                {
                    int ctls = ctlrange.length;
                    for (int i = 0; i < ctls; i++)
                    {
                        //Remove all selected controls
                        IHTMLElement elem = ctlrange.item(i);
                        if (!elem.IsNull())
                        {
                            RemoveNode(elem, true);
                        }
                    }
                    // Now get the textrange after deleting all selected controls
                    range = sel.createRange() as IHTMLTxtRange;
                }
            }

            if (!range.IsNull())
            {
                // range will be valid if nothing is selected or if text is selected
                // or if multiple elements are seleted
                range.pasteHTML(sHtml);
                range.collapse(false);
                range.select();
            }
            return(true);
        }
        private void Unmonitor(IHTMLElement span)
        {
            try
            {
                var htmlDoc = ContentUtils.GetFocusedHTMLDocument();
                var body    = htmlDoc?.body;
                if (body.IsNull() || span.IsNull())
                {
                    return;
                }

                // Remove events
                ((IHTMLElement2)body).detachEvent("onkeyup", _keyup);
            }
            catch (RemotingException) { }
        }