Author Topic: wxScintilla rectangular/block pasting bug  (Read 7056 times)

Offline SiegeLord

  • Single posting newcomer
  • *
  • Posts: 7
    • SiegeLord's Abode
wxScintilla rectangular/block pasting bug
« on: May 10, 2008, 01:35:16 am »
A continuation of this thread: http://forums.codeblocks.org/index.php/topic,8309.0.html. (A new thread since I can now provide some code...  8))

I believe I tracked the source of the bug down to some weird behaviour on the part of the wx's clipboard...

This particular code blurb illustrates the problem:

Code

wxDataFormatId type = wxDF_PRIVATE;

//First, try putting something into the clipboard
wxTheClipboard->Open()
wxCustomDataObject* data = new wxCustomDataObject(type);

//now fill data with something

wxTheClipboard->SetData(data);
wxTheClipboard->Close()

//now lets see if we can get it back
wxTheClipboard->Open()
wxCustomDataObject test_data(type);
bool weHaveData = wxTheClipboard->GetData(test_data);
wxTheClipboard->Close()


This roughly follows the pathway between ScintillaWX::CopyToClipboard and ScintillaWX::Paste.

I have observed that the data is returned if and only if type is either wxDF_UNICODETEXT or wxDF_TEXT. The clipboard appears to discard anything else. Since the block pasting relies on the custom data block of the type wxDF_PRIVATE, it naturally gets discarded and fails to work. I tried replacing wxDF_PRIVATE with wxDF_UNICODETEXT, and voila, the block pasting worked. This is naturally a hack, and probably unsuitable to solve this.

So, anyone have any idea what is going on here? Some bug in the clipboard that only allows to put text onto it?
« Last Edit: May 10, 2008, 01:42:46 am by SiegeLord »

Offline SiegeLord

  • Single posting newcomer
  • *
  • Posts: 7
    • SiegeLord's Abode
Re: wxScintilla rectangular/block pasting bug
« Reply #1 on: May 15, 2008, 06:51:53 am »
Success!

Turns out the person who coded that part of wxScintilla did not know how to work with the clipboard...

I don't know how to do diffs unfortunately, but here are the two lines that need to be changed:

Code
Line 505: ScintillaWX.cpp
Change from:
wxCustomDataObject selData(wxDF_PRIVATE);
to
wxCustomDataObject selData(wxDataFormat(wxString(wxT("rect_data"))));

Line 558: ScintillaWX.cpp
Change from:
        wxCustomDataObject* rectData = new wxCustomDataObject (wxDF_PRIVATE);
to
        wxCustomDataObject* rectData = new wxCustomDataObject (wxDataFormat(wxString(wxT("rect_data"))));

This makes block pasting work. It is maybe a little hacky... But it works.

The pasting behaviour is still a little suboptimal, but at least it actually uses the correct rect data, and does a pretty good job at pasting blocks. I'll fix the remaining annoyances in the actual PasteRectangular algorithm when I get the chance...
« Last Edit: May 15, 2008, 06:57:37 am by SiegeLord »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: wxScintilla rectangular/block pasting bug
« Reply #2 on: May 15, 2008, 08:52:39 am »
I'll fix the remaining annoyances in the actual PasteRectangular algorithm when I get the chance...
Nice work! Just to tell you that I am tracking this... will try myself and look for side effects...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: wxScintilla rectangular/block pasting bug
« Reply #3 on: May 16, 2008, 11:47:35 am »
I tried your patch on linux (64 debian unstable/experimental) and on W2K, both seem to work without any problems.

A continuation of this thread: http://forums.codeblocks.org/index.php/topic,8309.0.html. (A new thread since I can now provide some code...  8))
I would prefer not to open a new topic for the same thing, because I sometimes watch threads using the notify ability, what of course does not work if a new topic is opened.
« Last Edit: May 16, 2008, 11:54:16 am by jens »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: wxScintilla rectangular/block pasting bug
« Reply #4 on: May 16, 2008, 01:09:15 pm »
will try myself and look for side effects...
So far no issues (but a working paste behaviour) under Windows here, too...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline SiegeLord

  • Single posting newcomer
  • *
  • Posts: 7
    • SiegeLord's Abode
Re: wxScintilla rectangular/block pasting bug
« Reply #5 on: May 19, 2008, 06:44:27 am »
Quote
I would prefer not to open a new topic for the same thing, because I sometimes watch threads using the notify ability, what of course does not work if a new topic is opened.

My apologies. In retrospect I guess the difference in topics might not have been large enough to warrant a new thread... oh well, errare humanum est.

The annoyances I mentioned turned out to be nothing, it's just the way code::blocks handles the cursor after the paste procedure goes through. For some reason I expected the cursor position to be unchanged (if you note when you paste using the rectangular mode, the cursor jumps down a line). Since this is actually consistent with the non-rectangular pasting behaviour, I decided to leave it be.

I guess one last thing about this is the actual string 'rect_data' that I used. In theory it is encouraged for wxDataFormat to have the string be a MIME type, so for the sake of being professional I'd suggest using something like 'application/x-cbrectdata' instead.

Lunazoid

  • Guest
Re: wxScintilla rectangular/block pasting bug
« Reply #6 on: May 21, 2008, 04:04:17 pm »
This is great to hear!  I use block pasting a LOT in that other IDE, so I really missed it in C::B.  Thanks for working on this!