Monday, June 23, 2008

Extending cut-and-paste: template paste

Imagine that the clipboard contained the name of a car part and the identifier for that part

     1) black steering wheel
     2) sw_bw07

and that the user wants to put them into a destination document with the name followed by the identifier in brackets, like:

     black steering wheel (sw_bw07)

Rather than just pasting those items in then adding the brackets around the identifier, you could use a template paste to specify you want to paste the first item followed by a space then the second item enclosed in brackets.

Effectively, you'd enter (where an underscore is used to represent a space)

     ctrl(+shift) v t #1_(#2)

the 't' says you want a template paste. Following the 't' is the specification of the template: paste the first item on the clipboard followed by a space, an opening bracket, the second item on the clipboard then a closing bracket.

If you break that up into the individual keystrokes, what the user actually types is

     ctrl(+shift) v t # 1 _ ( # 2 )

Because the '#' has a special meaning (used to refer to items on the clipboard), if you wanted to include a literal '#' in the text, you'd have to type '\#'.

With paste commands, if you don't specify a specific position on the clipboard the last position is assumed. So to template paste the item in the last clipboard position with brackets on either side of it, you could type

     ctrl(+shift) v t ( # )

That is, you can have an anonymous item reference. It is possible to have multiple anonymous item references. The idea behind how they are parsed is that the further right an item is on the clipboard, the more likely (it's assumed) it is to be more recently entered. And it's assumed you want to fill the '#'s in the template in the order they've been added (that is, from left to right, starting at the position such that the last item in the template is the last item in the clipboard).

So if you had four items on the clipboard and the last two were a part name and a part identifier, and you wanted to paste it like before with the part name followed by a space then the identifier in brackets, you could type

     ctrl(+shift) v t # _ ( # )

The rightmost # is taken as referring to the last item on the clipboard, and the next rightmost # the second last item on the clipboard, the third last # the third last item on the board, and so on. Just specifying the '#' items without explicitly specifying the positions is just a shortcut, and what I've outlined is just my current thinking about how that might best work.

What if the template refers to more items than are in the clipboard? The same principle applies. The missing items are still to be filled in, so they are "more recent". That means that if there are three items in the template

     ctrl(+shift) v t # , _ # ( # )

but only two in the clipboard

then the third template item is still to be filled on. The second item is taken as the second on the clipboard, and the first the first on the clipboard.

then since there are only two items it'd paste

     item1, item2 ()

Handling (the various cases of) anonymous references to clipboard items is really about shortcuts. What I've described is just my current thinking about what'd be the most convenient default behaviour. You'd really need experience with template pastes to see how it was.

I suspect you'd soon enough pick up the way these default cases work. With cut and paste you've got fairly immediate feedback and you can always undo things if it's not what you want.

(You might have picked up that you could implement the functionality of a join paste with a template paste. But I think that the join paste is such a common pattern that it makes sense to have a specific command for it).

No comments:

Post a Comment