Page 1 of 1

[Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Wed Jun 09, 2010 12:46 am
by DrOptix
Hi :),

This is the patch that address this feature request:
Copy line under cursor if no selection - ID: 3012730
Ctrl+C only works when something is selected
When there is NO selection, a good feature is to copy the whole line.
Thanks

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Tue Jun 15, 2010 11:00 pm
by irmlab
Hi,
This is my first message and the first time I try to patch something !!
I submitted myself the Feature request, implemented using LineCopy() / SCI_LINECOPY message in wxscntilla.

This does not work as expected.
So I downloaded CodeLite from SVN and had look at the code, to see how to improve the patch above.
Finally, I found the solution is in the source code of Scintilla.

-- To have a working patch in the expected way, I guess the solution should be to use the SCI_COPYALLOWLINE message in scintilla. See the Scintilla Documentation : http://www.scintilla.org/ScintillaDoc.h ... YALLOWLINE

-- However, the COPYALLOWLINE message is NOT implemented in wxscintilla.h/cpp !!!

-- Obviously, I should contact first the maintainer of wxscintilla code, but before that, I would like to test the code.
And for testing the code, I would like to run my CodeLite SVN version !
My CodeLite workspaace compiles OK, but crashes at welcome screen ("memory at 0x0... The memory could not be read").I suppose it is related to the path or version of my wxWidget library (=> MINGW gcc, UNICODE SHARED).

BTW: Would it be possible to have the file "BuildInfo.txt" more precise (paths,configurations etc) ?

For now, if you ave a chance to implement the correction below, or similar,
in the meantime, maybe I will be able to use a patched runtime of CodeLite ! :- )


--- Below is the code I try to test:

In wxscintilla.h (after LineCopy() declaration):

Code: Select all

 
// Same as COPY except that if the selection is empty then the current line is copied.
void CopyAllowLine();		// [IRMLAB-100615]
In wxscintilla.cpp (after wxScintilla::LineCopy()):

Code: Select all

// SCI_COPYALLOWLINE works the same as SCI_COPY except that if the selection
// is empty then the current line is copied.
// On Windows, an extra "MSDEVLineSelect" marker is added to the clipboard
// which is then used in SCI_PASTE to paste the whole line before the current
// line.
// [IRMLAB-100615]
void wxScintilla::CopyAllowLine() {
    SendMsg (SCI_COPYALLOWLINE, 0, 0);
}
Finally, this patch becomes:

Code: Select all

if (event.GetId() == wxID_COPY) {
-		editor->Copy();
+		
+		if (editor->GetSelectedText() == wxT(""))
+		{
+			editor->CopyAllowLine();                  // [CHANGE:100615-IRMLAB]
+		}
+		else
+		{
+			editor->Copy();
+		}
 
 	} else if (event.GetId() == wxID_CUT) {
 		editor->Cut();
Voila ! Thanks for this good IDE.
I choose it because its implementation of _VIRTUAL_ folders in Workspace, with the Explorer tab as a complement.
I searched this (obvious !) feature long time ago.
Don't know any other IDE that offers this way to manage projects :)

Best regards - IRM

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Tue Jun 15, 2010 11:05 pm
by irmlab
And more probably, I notice the simplified code would result as:

Code: Select all

    if (event.GetId() == wxID_COPY) {
    +         editor->CopyAllowLine();                  // [CHANGE:100615-IRMLAB]
       } else if (event.GetId() == wxID_CUT) {
          editor->Cut();
BR!
IRMLAB

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Wed Jun 16, 2010 3:34 pm
by DrOptix
interesting! I will take a closer look at this. Idk why the version with:

Code: Select all

if (editor->GetSelectedText() == wxT(""))
+		{
+			editor->LineCopy();
Works here and not for you. Anyway thanx a lot for the info!

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Thu Jun 17, 2010 9:45 pm
by irmlab
I just saw your comments on Feature-Request comments
http://sourceforge.net/tracker/?func=de ... tid=979963
BTW: my environment is Windows 7. I am also used with keyboard shortcuts like in visual Studio 6

To explain the feature better, here is the comparison:
- In CodeLite : Ctrl+U will duplicate the line under cursor.
But no line appears in Clipboard, then you cannot re-paste it everywhere.

- In VStudio6: Ctrl+C + Ctrl+V will also duplicate the line under cursor.
But the line is also copied to Clipboard.
The sequence pasted is probably [\n+PastedChars+\n] in Clipboard.
You can re-paste it anywhere o multiple times
Each time you re-paste it, you create a new line before the line under cursor.

- In CodeLite v2.5.3.4075, under Windows7:
Ctrl+C + Ctrl+V will *insert* the line *inside* the current line under cursor.
The sequence pasted is only [PastedChars] with no heading or trailing '\n'.
When you re-paste it, you insert the pasted chars _inside_ the row, at the current character under cursor.

My goal is to emulate the VStudio6 shortcut.
scintilla sources already include the SCI_COPYALLOWLINE that appears to be the same.
However, the wxScintilla interface does not.
And a function like CopyAllowLine(), would replace the whole test in the Ctrl+C handler

Well, the feature is not very critical. But since I suggested it, I would like to try it myself :)
And currently, it builds, but still does not run, even under with debug... (Will see it again later)

Thanks for your answers ! :)

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Thu Jun 17, 2010 10:48 pm
by DrOptix
Thanx irmlab, now I understand what you want. I will try to implement it but it might take me one week to fully implement and test it because of my exams that are scheduled beginning with 28 this month and I have a lot to learn (damn Baccalaureate exam :evil: ).
irmlab
But since I suggested it, I would like to try it myself
Another thing I want to add: don't be afraid to provide patches. Just make sure they work post them here and CodeLite community give a final test and if all is ok I don't think it will be left unimplemented. One more thing tho, if I remember right eranif mentioned on one of the forum posts that changes to scintilla sources are to be avoided or at least mark the changes.
EDIT: Link to the post related to scintilla changes (http://codelite.org/forum/viewtopic.php?f=13&t=923)

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Fri Jun 18, 2010 10:51 pm
by irmlab
Last news, bad news.
(Last new: I can run OK Codelite project in debug mode --- my wxLib compiled under a different MINGW version)

Bad new : I tested and debugged my "solution" and it will NOT work "as-is".

AFAIK, to get a result, we would need to go inside the scintilla/editor.cxx
More precisely I played with :

FILE: scintilla/editor.cxx
LINE: 5377
FUNC: void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy)

It is not enough to insert \r\n just /before/ the string.
Rather, when pasting the line, the cursor should must be located on Row 0.

----

Well, Definitely, we are outside the scope of both CodeLite, wxScintilla.
This patch/feature request is for Neil Hodgson.
So I will try to compile the Scite project and play with it and try to contact him

Indeed, I want to learn to use the scintilla editor and customize it, if I can.
:)

Thanks for all ! I think this thread (with currently 46 views!?!) can be closed (under the strict CodeLite scope).
For sure, if a solution appears in the future, I will update this thread
:-)

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Sat Jun 19, 2010 8:44 am
by eranif
I took a closer look yesterday and did all the changes required (I am now using CopyAllowLine()) however, although the 'Copy' inserts \r\n at the start, the paste method should look for it and use it.

This fix should be in ScintillaWX::Paste() method.
I will have a look at it today and see if i can "patch" it

Eran

Re: [Patch] - ID: 30127 - Copy line under cursor if no selection

Posted: Sat Jun 19, 2010 9:53 am
by eranif
Try to update codelite sources from SVN and give it a try
Let me know if you think it is working as expected or something still needs to be done

Eran