Author Topic: copy/move selection with mouse on linux, and other copy/paste.cut issues fixed  (Read 6233 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5209
Thanks to our good friend Eran, we now have solutions for the following problems :

1) drag and drop of selected text, to copy/move, will now work on linux by adjusting the wxScintilla sources
  http://forums.codeblocks.org/index.php/topic,8946.0.html

2) copy/paste/cut issues (example you cut/copy something, and during paste something that was copied earlier to the clipboard got pasted), will now work on linux by adjusting the wxScintilla sources
  http://forums.codeblocks.org/index.php/topic,8890.0.html

For informational purposes below I write down the solutions made by Eran (come on everyone : say thank you !!!)

I fixed a bug (other helped on tracking it down) in wxScintilla that might interest you, the DnD of wxScintilla was not functioning in my IDE (CodeLite) under GTK: selecting a portion of text and then moving it around with the mouse was not working under Linux, nor selecting portion of text holding down the control and then moving the text (for copy operation).

To fix this matter, I modified the following function, you can simply use it as is:
( I am sorry for not sending you a patch file, but my source file of wxScintilla are modified by me and I believe they don't match C::B ones)

Code: [Select]
void ScintillaWX::StartDrag() {
#if wxUSE_DRAG_AND_DROP
#if wxVERSION_NUMBER >= 2800 && defined(__WXGTK__)
// For recent wxGTKs, DnD won't work if we delay with the timer, so go there direct
DoStartDrag();
#else
     startDragTimer->Start (200, true);
#endif // wxVERSION_NUMBER >= 2701 && defined(__WXGTK20__)
#endif
}

In addition, to make the DnD a single operation (that is, that you will be able to undo it in a single Ctrl-Z) you will need to modify the function:
void ScintillaWX::DoStartDrag()
Code: [Select]
void ScintillaWX::DoStartDrag() {
#if wxUSE_DRAG_AND_DROP
...
sci->GetEventHandler()->ProcessEvent (evt);
pdoc->BeginUndoAction(); // <--- Add this line here
..
pdoc->EndUndoAction(); //  <--- And before the end of the function
#endif
}

Change the method GetDragAllowMove() of class wxScintillaEvent to always return wxDrag_DefaultMove like this (wxscintilla.h, around line 3493):

Code: [Select]
bool GetDragAllowMove()          { return wxDrag_DefaultMove; }
Next, in void ScintillaWX::DoStartDrag() (ScintillaWX.cpp, around line 308):
change this:
Code: [Select]
result = source.DoDragDrop(evt.GetDragAllowMove());into
Code: [Select]
result = source.DoDragDrop(wxDrag_DefaultMove);


While we are fixing bugs for Code::Blocks  :D, I saw another post about 'copy/paste flaky' http://forums.codeblocks.org/index.php/topic,8890.0.html under KDE ;) - this is a real bug and not just the imagination of that user... I got 8 reports of that bug from users using codelite all under KDE - I experienced it myself (I am using Kubuntu 8.04 64bit KDE), to fix it (the hack is a bit ugly, but all the users that reported that bug, reported it is gone for good):

Modify ScintillaWX::Copy to become this (just copy paste it):
Code: [Select]
void ScintillaWX::Copy() {
    if (currentPos != anchor) {
        SelectionText st;
        CopySelectionRange(&st);
#ifdef __WXGTK__
for(int i=0; i<5; i++) {
//wxPrintf(wxT("Copying to clipboard %ld\n"), i);
        CopyToClipboard(st);
}
#else
      CopyToClipboard(st);
#endif
    }
}

Kinda funny fix, but it fixes the problem

Once more, thanks Eran :-)

Available in revision 5185
« Last Edit: August 15, 2008, 08:22:38 pm by killerbot »