#464 Pasting into virtual space places the text incorrectly

Undefined
open
nobody
Editor (11)
Undefined
2017-01-17
2017-01-10
Riot
No

when Settings->general->enable virtual space is enabled, you can place the cursor anywhere in the editor window, as expected.

If you place the cursor past the end of the line and start typing, that works correctly and places your text at the cursor.

However, if you paste there, the pasted text is moved back to the end of the real line, i.e. space isn't inserted to make it appear at the cursor position.

Tested on 64bit linux, svn 10922.

Discussion

  • Teodor Petrov

    Teodor Petrov - 2017-01-10

    Does this problem happens with Scite or any other scintilla based editor?

     
    • Riot

      Riot - 2017-01-11

      I haven't a clue how to enable virtual space in scite, so I'll leave it to you to try it :)

       
  • Teodor Petrov

    Teodor Petrov - 2017-01-10
    • labels: --> Editor
     
  • bluehazzard

    bluehazzard - 2017-01-14

    i can confirm this bug with codeblocks on windows

    i have tested it with notepad++ on windows (which uses also scintilla) and there it works, so it seems to be a bug in codeblocks

     
  • bluehazzard

    bluehazzard - 2017-01-14

    btw i noted a other bug with virtual space:
    The column counter in the status bar does not show the correct caret position, but always the position where the text gets inserted, i am not quite sure what position this exactly is, but it seems to be the end of the last text in this line.

    I have looked in to the paste code and it is quite complicated, i still try to understand what all this code does...

     
    Last edit: bluehazzard 2017-01-14
  • Teodor Petrov

    Teodor Petrov - 2017-01-14

    What version of Notepad++ and what version of scintilla is it using? It might be using different version that is not affected by this. C::B is on 3.5.x if I remember correctly.

     
  • bluehazzard

    bluehazzard - 2017-01-14

    i am quite sure that the culprit is codeblocks...
    in sdk\wxscintilla\src\ScintillaWX.cpp:608
    is the code for pasting into the editor:

    void ScintillaWX::Paste() {
    /* C::B begin */
        UndoGroup ug(pdoc);
        // Selection::First
        SelectionPosition firstPosition = SelectionStart();
        if (sel.IsRectangular() && !sel.Empty()) {
            for (size_t i=0; i<sel.Count()-1; i++) {
                sel.RotateMain();
                if (firstPosition > SelectionStart())
                    firstPosition = SelectionStart();
            }
        }
    /* C::B end */
        ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH);
    
    #if wxUSE_DATAOBJ
        wxTextDataObject data;
    /* C::B begin */
        wxString textString;
    
        bool isRectangularClipboard = false;
    
        wxTheClipboard->UsePrimarySelection(false);
        if (wxTheClipboard->Open()) {
            // Leave the following lines that way to enable compilation with GCC 3.3.3
            wxDataFormat dataFormat(wxString(wxT("application/x-cbrectdata")));
            wxCustomDataObject selData(dataFormat);
            bool gotRectData = wxTheClipboard->GetData(selData);
    
            if (gotRectData && selData.GetSize()>1) {
                wxTheClipboard->Close();
                const char* rectBuf = (const char*)selData.GetData();
                isRectangularClipboard = rectBuf[0] == (char)1;
                int 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);
                wxTheClipboard->Close();
                if (gotData) {
                    textString = wxTextBuffer::Translate(data.GetText(),
                                                         wxConvertEOLMode(pdoc->eolMode));
                }
            }
        }
    
        // Send an event to allow the pasted text to be changed
        wxScintillaEvent evt(wxEVT_SCI_CLIPBOARD_PASTE, sci->GetId());
        evt.SetEventObject(sci);
        evt.SetPosition(sel.MainCaret());
        evt.SetString(textString);
        sci->GetEventHandler()->ProcessEvent(evt);
    
        wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(textString);
    #if wxUSE_UNICODE
        // free up the old character buffer in case the text is real big
        data.SetText(wxEmptyString);
        textString = wxEmptyString;
    #endif
        int len  = strlen(buf);
        int newPos = 0;
        int caretMain = CurrentPosition();
        if (isRectangularClipboard) {
            SelectionPosition selStart = sel.Range(sel.Main()).Start();
            int newLine = pdoc->LineFromPosition (caretMain) + wxCountLines (buf, pdoc->eolMode);
            int newCol = pdoc->GetColumn(caretMain);
            PasteRectangular(selStart, buf, len);
            newPos = pdoc->FindColumn (newLine, newCol);
        } else {
            pdoc->InsertString(caretMain, buf, len);
            newPos = caretMain + len;
        }
        SetEmptySelection (newPos);
    /* C::B end */
    #endif // wxUSE_DATAOBJ
    
        NotifyChange();
        Redraw();
    }
    

    quite a bit codeblock specific, and notepad++ uses all the scintilla code as far as i can see.

    The problem is that

    ~~~~~~
    int caretMain = CurrentPosition();
    ~~~~~~

    does not return the caret position but the position of the last character...
    i have tried a quick fix to simply replace this with the caret position, but you have to add the spaces by yourself. And i don't know what happens if you paste a block of text....

    [edit: rip english]

     
    Last edit: bluehazzard 2017-01-14
  • bluehazzard

    bluehazzard - 2017-01-17

    fix is attached

    one open point are the lines:

    wxScintillaEvent evt(wxEVT_SCI_CLIPBOARD_PASTE, sci->GetId());
        evt.SetEventObject(sci);
        evt.SetPosition(sel.MainCaret());
        evt.SetString(textString);
        sci->GetEventHandler()->ProcessEvent(evt);
    

    i don't know the intended behaviour here... Shall the event get the virtual caret position?

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks