Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Crash using copy and paste (reproducable)

<< < (2/6) > >>

eranif:
Hi,
Couple of months ago I encountered the same problem I posted this issue at wxCode forum, but unfortunaly I got no replies but one, but I did managed to find a solution for this
(it is, in my opinion wxScintilla bug)

the bug report and the solution can be found here:
http://wxforum.shadonet.com/viewtopic.php?t=9907

A quick solution is to replace the Paste function with this one: (ScintillWX.cpp):

--- Code: ---void ScintillaWX::Paste() {
    pdoc->BeginUndoAction();
    ClearSelection();

#if wxUSE_DATAOBJ
    wxTextDataObject data;
    wxString textString;

    wxWX2MBbuf buf;
    int   len  = 0;
    bool  rectangular = false;

    if (wxTheClipboard->Open()) {
        wxTheClipboard->UsePrimarySelection(false);
        wxCustomDataObject selData(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_PRIVATE);
        bool gotRectData = wxTheClipboard->GetData(selData);

        if (gotRectData && selData.GetSize()>1) {
            const char* rectBuf = (const char*)selData.GetData();
            rectangular = rectBuf[0] == (char)1;
            len = selData.GetDataSize()-1;
            char* buffer = new char[len];
            memcpy (buffer, rectBuf+1, len);
            textString = sci2wx(buffer, len);
            delete buffer;
        } else {
            bool gotData = wxTheClipboard->GetData(data);
            if (gotData) {
                textString = wxTextBuffer::Translate (data.GetText(),
                                                      wxConvertEOLMode(pdoc->eolMode));
            }
        }
        data.SetText(wxEmptyString); // free the data object content
        wxTheClipboard->Close();
    }

    buf = (wxWX2MBbuf)wx2sci(textString);
    len  = strlen(buf);
    int newPos = 0;
    if (rectangular) {
        int newLine = pdoc->LineFromPosition (currentPos) + wxCountLines (buf, pdoc->eolMode);
        int newCol = pdoc->GetColumn(currentPos);
        PasteRectangular (currentPos, buf, len);
        newPos = pdoc->FindColumn (newLine, newCol);
    } else {
        pdoc->InsertString (currentPos, buf, len);
        newPos = currentPos + len;
    }
    SetEmptySelection (newPos);
#endif // wxUSE_DATAOBJ

    pdoc->EndUndoAction();
    NotifyChange();
    Redraw();
}
--- End code ---
Eran

manciuleas:
Eran,

Who is wxCountLines? It seems that it is not defined.

stahta01:

--- Quote from: manciuleas on December 12, 2006, 05:52:03 pm ---Eran,

Who is wxCountLines? It seems that it is not defined.


--- End quote ---

From ScintillaWX.cxx right after the wxConvertEOLMode method; this is from code written after C::B version of it.

--- Code: ---static int wxCountLines(const char* text, int scintillaMode)
{
    char eolchar;

    switch (scintillaMode) {
        case wxSCI_EOL_CRLF:
        case wxSCI_EOL_LF:
            eolchar = '\n';
            break;
        case wxSCI_EOL_CR:
            eolchar = '\r';
            break;
        default:
            return 0;
    }

    int count = 0;
    int i     = 0;
    while (text[i] != 0) {
        if (text[i] == eolchar) {
            count++;
        }
        i++;
    }

    return count;
}

--- End code ---

manciuleas:
Thanks stahta01.

Pulle:
Hi,
thanks for the help Eran, but the bug is still there after changing ScintillaWX.cpp as you suggested and recompile C::B. So the error must be somewhere else.
btw: disabling code-completition didn't helped either.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version