anchor.diff:                      let! result = 
                           try 
                               let selection = input.Substring(fromOffset, toOffset - fromOffset)
  -                            let result = 
  -                                 trimIfNeeded selection 
  -                                              (CodeFormatter.formatSelectionOnly isFsiFile range input config)
  -                            if doc.IsSome then
  +                            let result = trimIfNeeded selection (CodeFormatter.formatSelectionOnly isFsiFile range input config)
  +
  +                            match editor with
  +                            | Some editor -> 
                                   //If onTheFly do the replacements in the document
  -                                doc.Value.Editor.Document.Replace(fromOffset, selection.Length, result)
  +                                editor.ReplaceText(fromOffset, selection.Length, result)
                                   None
  -                            else Some(result)
  +                            | None -> Some(result)
                            with exn -> 
                                LoggingService.LogError("**Fantomas Error occured: {0}", exn.Message)
                                None
  
positive.code:             | Some newCode -> newCode
              | None -> null
  
      let formatText (doc : Gui.Document option) (policyParent : PolicyContainer) (mimeTypeInheritanceChain : string seq) input formattingOption = 
          let textStylePolicy = policyParent.Get<TextStylePolicy>(mimeTypeInheritanceChain)
          let formattingPolicy = policyParent.Get<FSharpFormattingPolicy>(mimeTypeInheritanceChain)
          format doc textStylePolicy formattingPolicy input formattingOption
  
      static member MimeType = "text/x-fsharp"
  
  
negative.code:                     let result =
                          trimIfNeeded input (CodeFormatter.formatSourceString isFsiFile input config)
                      //If onTheFly do the replacements in the document
                      editor |> Option.iter (fun d -> d.ReplaceText(0, input.Length, result))
                      result
                  with exn -> 
                      LoggingService.LogError("Error occured: {0}", exn.Message)
  