public void ExecuteSelectionOperation(HtmlEditorSelectionOperation op) { //suspend selection change events while the real HTML selection is temporarily adjusted //to include the smart content element while the selection operation executes. _editorComponentContext.BeginSelectionChange(); try { IHTMLDocument2 document = (IHTMLDocument2)HTMLElement.document; MarkupRange elementRange = CreateElementClingMarkupRange(); MarkupRange insertionRange = CreateSelectionBoundaryMarkupRange(); elementRange.ToTextRange().select(); op(this); //reset the selection if (elementRange.Start.Positioned && elementRange.End.Positioned) { document.selection.empty(); _editorComponentContext.Selection = this; } else { insertionRange.ToTextRange().select(); } } finally { _editorComponentContext.EndSelectionChange(); } }
public void ExecuteSelectionOperation(HtmlEditorSelectionOperation op) { //this isn't a valid selection to execute an operation on if (!IsEditableSelection()) { Debug.Fail("Selection is not positioned, operation will no-op"); return; } //adjust the selection to include for any adjacent HTML that is invisibly part of //the selection. This prevent bugs (like 256686) that are related to leaving behind //HTML elements that are invisibly part of a selection. _tempAdjustedSelection = AdjustSelection(); try { //Note: we saved the adjusted selection temporarily because the editor's IHTMLTxtRange.select() //call isn't guaranteed to postion the selection at exactly the adjusted location. This was //causing issues with operations not actually executing on the adjusted selection, so now these //operations will have access to the exact adjusted selection when they use SelectedMarkupRange. //execute the selection operation op(this); } finally { _tempAdjustedSelection = null; //unset the saved adjusted selection } }