// get the selected range object protected HtmlTextRange GetTextRange() { // define the selected range object HtmlSelection selection; HtmlTextRange range = null; try { // calculate the text range based on user selection selection = GetDomDocument().selection; if (IsStatedTag(selection.type, SELECT_TYPE_TEXT) || IsStatedTag(selection.type, SELECT_TYPE_NONE)) { range = selection.createRange() as HtmlTextRange; } } catch (Exception) { // have unknown error so set return to null range = null; } return(range); } // GetTextRange
internal Range(mshtml.IHTMLTxtRange range) { msHtmlTxRange = range; }
/// <summary> /// Executes the execCommand on the selected range (given the range) /// </summary> private void ExecuteCommandRange(mshtmlTextRange range, string command, object data) { try { if (!range.IsNull()) { // ensure command is a valid command and then enabled for the selection if (range.queryCommandSupported(command)) { if (range.queryCommandEnabled(command)) { // mark the selection with the appropriate tag range.execCommand(command, false, data); } } } } catch (Exception ex) { // Unknown error so inform user throw new HtmlEditorException("Unknown MSHTML Error.", command, ex); } }
/// <summary> /// Executes the queryCommandState on the selected range (given the range) /// </summary> private bool ExecuteCommandQuery(mshtmlTextRange range, string command, bool isEnabled = false) { // set the initial state as false bool retValue = false; try { if (!range.IsNull()) { // ensure command is a valid command and then enabled for the selection if (range.queryCommandSupported(command)) { if (isEnabled) { retValue = range.queryCommandEnabled(command); } else { if (range.queryCommandEnabled(command)) { // mark the selection with the appropriate tag retValue = range.queryCommandState(command); } } } } } catch (Exception ex) { // Unknown error so inform user throw new HtmlEditorException("Unknown MSHTML Error.", command, ex); } // return the value return retValue; }