News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

wxScintilla rectangular/block pasting bug

Started by SiegeLord, May 10, 2008, 01:35:16 AM

Previous topic - Next topic

SiegeLord

A continuation of this thread: http://forums.next.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:



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?

SiegeLord

#1
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:


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...

MortenMacFly

Quote from: SiegeLord on May 15, 2008, 06:51:53 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Jenna

#3
I tried your patch on linux (64 debian unstable/experimental) and on W2K, both seem to work without any problems.

Quote from: SiegeLord on May 10, 2008, 01:35:16 AM
A continuation of this thread: http://forums.next.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.

MortenMacFly

Quote from: MortenMacFly on May 15, 2008, 08:52:39 AM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

SiegeLord

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

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!