The clipboard is a pretty amazing concept. It’s one of those things we use daily, take for granted, and rarely even think about …
… except when it doesn’t do what we expect.
Let’s review some of the magic behind the clipboard’s curtain. It’s more complex than you might realize.
Become a Patron of Ask Leo! and go ad-free!
I have to start with the usual caveat: this is not meant to be a detailed treatise on the inner workings of the clipboard. It almost certainly doesn’t work exactly as I outline below. I’m grossly oversimplifying in order to make concepts and behavior clearer for non-programmers.
Conceptually, the clipboard is extremely simple: you copy1 something to it, where it remains until overwritten by another copy-to-clipboard. You can then paste2 it somewhere, which copies what’s in the clipboard to the location you indicate.
It’s a two-step process. First, you identify the item you want to copy — usually via a selection of some sort — and then copy it to the clipboard using a keystroke or mouse sequence.
Then, you identify a new location into which you want to place the copied item, and paste it there, once again using a keystroke or mouse sequence.
In the example above, I’ve copy/pasted some text3 from one document to another via the clipboard. When done, the text I’ve selected exists in three places:
- The original location I copied from.
- The clipboard.
- The new location I pasted into.
The text will remain in the clipboard until the next time I copy something to it, because the clipboard can hold only one thing at a time.4
Conceptually, that’s how the clipboard works, and in some cases, it actually does work that way.
But in many cases, it doesn’t.
If you’ve ever copy/pasted from a word-processing program like Microsoft Word into a plain-text-editing program like Notepad, you may have noticed that all the formatting is lost. Notepad doesn’t do formatting; it’s text-only. Copy/pasting from Word to Notepad is, in fact, a convenient way to get only the text.
But as you might imagine, under the hood things are more complex. Word, for example, doesn’t know where the data will be pasted, or what the capabilities of the receiving program might be. Ideally, it makes the highest fidelity of whatever has been copied available, but someone has to handle the conversion from one format (fancy and formatted) to the other (plain text).
There are two catches:
- We can’t assume that the clipboard understands what is being copied.
- We can’t assume that the destination application knows what to do with the way the information is stored. (Though it would be nice if it did.)
The result is that when you copy something to the clipboard, the application you’re copying from provides a little more information than just the data to be copied; it includes the formats it can make that data available in.
Depending on the sophistication of the program you’re copying from, it may offer many different formats — as Word might — or it might offer only one. But that information, along with the data to be copied (in most cases; more on that in a moment), is given to the clipboard when you copy something.
Paste has a similar complication in that the program you’re pasting into asks the clipboard for the data in a priority-ordered list of preferred formats.
When you paste, the clipboard takes the highest-priority-requested format that was made available by the original copy, and provides that to application into which the data is to be pasted.
In our example, the “list” of preferred formats was only one item long, so the clipboard took the plain text of the copied data provided by Word and gave it to Notepad.
The clipboard doesn’t really care or even understand what’s being copied or pasted; it just acts as an intermediary between the program from which data is copied and the program into which the data is pasted.
Those programs, on the other hand, care a lot. For example, we can use copy/paste to move files around in Windows File Explorer, but pasting a file into Notepad doesn’t make sense.
You can’t paste just anything anywhere — one of the formats offered by the source of whatever it is you want to copy must be a form that the destination understands. If that can’t happen, you can’t paste. In most cases, that manifests as a greyed-out “Paste” item in the destination application.
When things get big, really big
There’s no conceptual limit as to how big something can be for copy/paste. There are practical limits, and they come from not-so-obvious places.
The clipboard itself can only hold so much, but that doesn’t prevent it from brokering larger items. When a large item is copied to the clipboard, it can elect to keep only the available format information and not the data. Instead, the application in which the copy happened must hold on to the data until the someone requests it (or the clipboard is replaced or emptied). When a paste occurs, the information is transferred from application to application — the clipboard acts only as an intermediary to facilitate the exchange.
- The application in which you hit “copy” tells the clipboard that the data is available, how large it is, and what formats are available.
- The application into which you “paste” tells the clipboard that it wants the data, and in which format.
- The clipboard essentially says, “You guys figure it out”, and the data is transferred directly from one application to the other.
This technique results in behavior that might confuse you. For example, what happens when you close the first application before you paste into the second?
Closing the copy source before the paste
When the data is copied to the clipboard, as in our earlier example of a small copy/paste, it doesn’t matter if the source application is closed before you paste. Everything necessary was placed into the clipboard and remains available for a paste operation.
In the example of a large copy, though, where the clipboard doesn’t hold the actual data, there are two options when the source application goes away:
- The clipboard can be emptied. The source application isn’t available to provide the copied data, so there’s nothing to paste.
- The data can be written to disk for the clipboard to access later when a paste is requested.
I’ve seen both; it varies from application to application. When you close an application that has made something large available to the clipboard, it may:
- Write it to disk without asking
- Offer to write to disk (as Word is doing in the example above)
- Offer to abort the exit so the program keeps running to provide the information via the clipboard
- Empty the clipboard without asking
The clipboard’s about more than the clipboard
Needless to say, I’ve only scratched the surface of the clipboard’s capabilities.
Perhaps most important is to realize that the clipboard’s functionality — beyond its role as intermediary — is provided by the applications from which you can copy and into which you can paste. They control what can be copied, where it can be pasted, and what results or transformations — like fancy text to plain text — are available.
If you found this article helpful, I'm sure you'll also love Confident Computing! My weekly email newsletter is full of articles that help you solve problems, stay safe, and give you more confidence with technology. Subscribe now and I'll see you there soon,