public static void Copy()

in Office365APIEditor/External/ScintillaNET/Helpers.cs [135:228]


        public static void Copy(Scintilla scintilla, CopyFormat format, bool useSelection, bool allowLine, int startBytePos, int endBytePos)
        {
            // Plain text
            if ((format & CopyFormat.Text) > 0)
            {
                if (useSelection)
                {
                    if (allowLine)
                        scintilla.DirectMessage(NativeMethods.SCI_COPYALLOWLINE);
                    else
                        scintilla.DirectMessage(NativeMethods.SCI_COPY);
                }
                else
                {
                    scintilla.DirectMessage(NativeMethods.SCI_COPYRANGE, new IntPtr(startBytePos), new IntPtr(endBytePos));
                }
            }

            // RTF and/or HTML
            if ((format & (CopyFormat.Rtf | CopyFormat.Html)) > 0)
            {
                // If we ever allow more than UTF-8, this will have to be revisited
                Debug.Assert(scintilla.DirectMessage(NativeMethods.SCI_GETCODEPAGE).ToInt32() == NativeMethods.SC_CP_UTF8);

                if (!registeredFormats)
                {
                    // Register non-standard clipboard formats.
                    // Scintilla -> ScintillaWin.cxx
                    // NppExport -> HTMLExporter.h
                    // NppExport -> RTFExporter.h

                    CF_LINESELECT = NativeMethods.RegisterClipboardFormat("MSDEVLineSelect");
                    CF_VSLINETAG = NativeMethods.RegisterClipboardFormat("VisualStudioEditorOperationsLineCutCopyClipboardTag");
                    CF_HTML = NativeMethods.RegisterClipboardFormat("HTML Format");
                    CF_RTF = NativeMethods.RegisterClipboardFormat("Rich Text Format");
                    registeredFormats = true;
                }

                var lineCopy = false;
                StyleData[] styles = null;
                List<ArraySegment<byte>> styledSegments = null;

                if (useSelection)
                {
                    var selIsEmpty = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONEMPTY) != IntPtr.Zero;
                    if (selIsEmpty)
                    {
                        if (allowLine)
                        {
                            // Get the current line
                            styledSegments = GetStyledSegments(scintilla, false, true, 0, 0, out styles);
                            lineCopy = true;
                        }
                    }
                    else
                    {
                        // Get every selection
                        styledSegments = GetStyledSegments(scintilla, true, false, 0, 0, out styles);
                    }
                }
                else if (startBytePos != endBytePos)
                {
                    // User-specified range
                    styledSegments = GetStyledSegments(scintilla, false, false, startBytePos, endBytePos, out styles);
                }

                // If we have segments and can open the clipboard
                if (styledSegments != null && styledSegments.Count > 0 && NativeMethods.OpenClipboard(scintilla.Handle))
                {
                    if ((format & CopyFormat.Text) == 0)
                    {
                        // Do the things default (plain text) processing would normally give us
                        NativeMethods.EmptyClipboard();

                        if (lineCopy)
                        {
                            // Clipboard tags
                            NativeMethods.SetClipboardData(CF_LINESELECT, IntPtr.Zero);
                            NativeMethods.SetClipboardData(CF_VSLINETAG, IntPtr.Zero);
                        }
                    }

                    // RTF
                    if ((format & CopyFormat.Rtf) > 0)
                        CopyRtf(scintilla, styles, styledSegments);

                    // HTML
                    if ((format & CopyFormat.Html) > 0)
                        CopyHtml(scintilla, styles, styledSegments);

                    NativeMethods.CloseClipboard();
                }
            }
        }