Line copy/paste

145 views
Skip to first unread message

280Z28

unread,
Nov 26, 2007, 8:28:56 PM11/26/07
to scintilla-interest
I created a small patch that allows line copy and paste. When there is
no text selected, ctrl+c is normally useless. With this, ctrl+c with
no text selected copies the current line to the clipboard. When you
paste, the line is pasted above the line the cursor is on, regardless
of where on that line the cursor is.

I created the patch with TortoiseSVN.

http://www.280z28.org/downloads/linecopy.7z

Neil Hodgson

unread,
Nov 27, 2007, 10:05:48 PM11/27/07
to scintilla...@googlegroups.com
While this may be useful, there are some issues and I'm not sure yet
what to do.

Neil

maciejr

unread,
Nov 28, 2007, 4:39:09 AM11/28/07
to scintilla-interest
I like Ctrl+C to do nothing when the selection is empty! It is an
extra layer of safety for imperfect users, like me, who sometimes
mistakenly press Ctrl+C when they want Ctrl+V (e.g., after Ctrl+X
during a quick cut & paste).
Visual Studio has such a feature, and a mistake like that made me
loose clipboard contents quite a few times.

Btw, Scite has keyboard shortcuts for line cut/copy, so I assume
Scintilla has it, too. I would suggest to keep that and make the
special "line paste" behaviour (as implemented by 280Z28) occur only
when pasting after these special line cut/copy commands. It does make
sense that line cut/copy/paste should work on entire lines. In other
words:

normal copy -> normal paste
copy line with a special shortcut -> special paste above the present
line

If you do make Ctrl+C on empty selection act as line copy, please make
it optional in SciTE!

Maciej.

Paul Hutchinson

unread,
Nov 28, 2007, 8:47:33 AM11/28/07
to scintilla...@googlegroups.com

I am one of the developers for Code Roar (http://coderoar.com). Roar
is build around Scintilla and we have implemented selectionless
cut/copy (without changing Scintilla). You can down load it and try
this feature out to see if you like it before putting it in Scite.

The way we have done it is as follows:
We register a new clipboard format the same as MSDEVColumnSelect is:
cfSingleLine=RegisterClipboardFormat("RoarSingleLine");

When CTRL+C is pressed we check to see if there is a selection, if not
we get the caret line. We then get that line into a buffer.

We then copy into the clip board setting "RoarSingleLine" (as this is
a line copy).
SetClipboardData(cfSingleLine,0);

Now when CTRL+V is pressed we first check to see if the "RoarSingleLine" is set:
if(Clipboard()->HasFormat(cfSingleLine))
SingleLine=true;

If it is then we remove the old selection, move the caret to the start
of the line:
if(SingleLine)
{
/* We need to move the caret to the start of the line before the
paste (kill off the selection before we do this) */
UIReplaceSelectionText(UIControl,"");
DoRAWSciCMD(SCI_HOME,0,0);
DoRAWSciCMD(SCI_REPLACESEL,0,(long)ReplaceText);
}

This seems to work well. I can post the full code that we use for
this as a reference on how to put it in Scite (I skipped some the
little details like rect selections above).

Paul Hutchinson
Lead Developer,
http://CodeRoar.com

Neil Hodgson

unread,
Nov 28, 2007, 6:13:38 PM11/28/07
to scintilla...@googlegroups.com
Paul Hutchinson:

> The way we have done it is as follows:
> We register a new clipboard format the same as MSDEVColumnSelect is:
> cfSingleLine=RegisterClipboardFormat("RoarSingleLine");

The patch uses the format name MSDEVLineSelect but I can't find any
mention of MSDEVLineSelect on the 'net. Compatibility of whatever
technique is used by Visual Studio would be better than something that
just works with Scintilla.

It was much more difficult to place multiple formats on the
clipboard with GTK+ (and other platforms over X) so there is a low
quality hack for differentiating rectangular and stream selection
there. Possibly this has improved with newer GTK+ clipboard APIs but I
don't have much time for exploration. Having line copy only work on
Windows isn't great and its one reason for making this a separate
command CopyWithLine (or VCCopy) that is then marked as Windows-only.

Neil

280Z28

unread,
Nov 29, 2007, 2:58:11 PM11/29/07
to scintilla-interest
MSDEVLineSelect causes line copies to work between Visual Studio and
Scintilla. Yes this is Windows only, and the patch was on 1.7.4, but
the code still worked when I merged in the 1.7.5 code. I can't really
help with the other platforms :( but I hope this gets worked out since
it's tremendously useful. :)

Note that the caret placement on line-paste is very important: it
shouldn't move at all (stays on the line below the pasted line)! One
thing I didn't fix is the Undo command does move the cursor to the
beginning of the line (it shouldn't move the cursor if the action
being undone was a line-paste).

Erik

unread,
Nov 30, 2007, 8:51:20 AM11/30/07
to scintilla-interest
> MSDEVLineSelect causes line copies to work between Visual Studio and
> Scintilla. Yes this is Windows only, and the patch was on 1.7.4, but
> the code still worked when I merged in the 1.7.5 code. I can't really
> help with the other platforms :( but I hope this gets worked out since
> it's tremendously useful. :)

An easier approach might be to just check if the last character in the
clipboard is \r or \n, then it's a line, so use line paste. Otherwise
use normal paste. It will work on all platforms, and you won't have to
bother about different clipboard formats.

Paul Hutchinson

unread,
Nov 30, 2007, 9:52:13 AM11/30/07
to scintilla...@googlegroups.com

We implemented it this way the first time round but it doesn't really
work. Basically you have a problem where if you select a line for
coping (highlight and CTRL+C) you expect the line to be pasted out
starting at the caret. If you use line copy (no selection) then when
you paste it in you expect it to insert the line at column 1 no matter
where the caret is.

As for using MSDEVLineSelect I would say that using an existing
standard is better than making up your own. I don't know if
MSDEVLineSelect is a standard or not (I don't see any other references
to it with Google). If we find a standard I will be changing Roar to
match it.

Earlier on we did the selectionless line copy with using multi-clip
formats by keeping a hash of what we placed on the clip board and
storing the line copy status (and rect status) our selfs. When the
user pressed paste we grabed the contents of the system clip board and
did the hash. If they where the same we used our stored status, if
not we assumed that someone else had changed the contents. Of course
there are down sides to doing this (mainly speed) and we changed it in
favor of the multi-clip format.

280Z28

unread,
Dec 8, 2007, 3:32:17 AM12/8/07
to scintilla-interest
MSDEVLineSelect does work with Visual Studio. We can't change VS, but
we can match it. There may not be an official standard, but the method
I used is a simple way to maintain cross-program support for the
feature. :) Not many programs offer this (only my version of
Scintilla, Roar, and Visual Studio that I know of). You could change
Roar to match this without changing the functionality to your users,
and you gain the new feature of working with VS. Most users probably
wouldn't care, but you aren't affecting them. The ones who do use VS
would be greatly appreciative.

I found MSDEVLineSelect by lucky guess. Worked the first time and I
was like :woot:

Sam

On Nov 30, 8:52 am, "Paul Hutchinson" <hutchinson.p...@gmail.com>
wrote:

Neil Hodgson

unread,
Dec 12, 2007, 12:43:25 AM12/12/07
to scintilla...@googlegroups.com
An updated version of this feature can be found at
http://scintilla.sourceforge.net/scite_copy.zip
with a diff at
http://scintilla.sourceforge.net/scite_copy.diff

This uses a separate API CopyAllowLine instead of including the
feature in the standard Copy. On GTK+, CopyAllowLine works as on
Windows except there is no extra format added to the clipboard so the
receiver does not know when to perform a line paste so performs a
standard paste. There is some difference between the original patch
(or the update) and Visual Studio when a paste is performed with
MSDEVLineSelect present with Visual Studio first deleting the
selection then performing a line paste. The download includes some
temporary assignment to keys and keyboard commands - SciTE should
probably add an option to choose between CopyAllowLine and Copy.

This is all still a little too messy for me to be completely
content yet. Inconsistency between platforms is a support and
documentation sink.

Neil

Neil Hodgson

unread,
Jan 18, 2008, 11:25:33 PM1/18/08
to scintilla...@googlegroups.com
A slightly rewritten version of this is now committed to CVS. There
is no key mapped to CopyAllowLine in Scintilla and no support in
SciTE. The documentation is:

<p><code>SCI_COPYALLOWLINE</code> 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
<code>SCI_PASTE</code> to paste
the whole line before the current line.</p>

Neil

Reply all
Reply to author
Forward
0 new messages