Jump to content

Why does copy-pasting text also keep original font and background color?

 Share

For example, when I copy something from a web site or an IDE and then paste it into a word processor, font, font size, font color and background color are somehow copied over.How is that possible?When I paste it into a notepad, it is just plain text without any inserted metadata.

Link to comment
Share on other sites

Link to post
Share on other sites

notepad is quite literally just a text file viewer/editor in it's most basic modern form. it's pretty much the oldest program still in use in windows

 

Quote

Features

Notepad is a text editor, i.e., an app specialized in editing plain text. It can edit text files (bearing the ".txt" filename extension) and compatible formats, such as batch files, INI files, and log files. Notepad can read and write plain texts encoded in ASCII, UTF-8, and UTF-16. It supports both left-to-right and right-to-left based languages.

Notepad offers only the most basic text manipulation functions, such as finding and replacing text. Until Windows ME, there were almost no keyboard shortcuts and no line-counting feature. Starting with Windows 2000, shortcuts for common commands like "New", "Open", and "Save" were added, as well as a status bar with a line counter (available only when word-wrap is disabled). Before Windows 10 version 1809, Notepad could not properly interpret Unix-style or Mac-style newline characters.[13] Windows 10 version 1809 also introduced the Ctrl+← Backspace keyboard shortcut (deletes the previous word), zoom functionality, the ability to zoom in and out, and the "Search with Bing" function.[14][15]

Improving performance has been the main focus of Notepad's development. As part of this effort, Notepad is capable of reading text files even when other apps have acquired a range-based lock on the file.[16]

On Windows 95 and earlier, Notepad renders text files in the Fixedsys font. Starting with Windows NT 4.0 and Windows 98, it allows users to choose their own font to display the text. They cannot, however, select individual parts of the text and change their fonts.[17][18] Its default font changed to Lucida Console on Windows 2000, and Consolas on Windows 8.

Notepad can print files. It allows customizing headers, footers, and margins before printing. The date, file name, and other information can be placed in the headers and footers with various codes consisting of an ampersand ('&') followed by a letter.[19]

Notepad accepts text from the Windows clipboard, but only in the CF_TEXT format.[20] It strips the pasted text of any embedded font and style information. One could temporarily paste formatted text into Notepad, then immediately copy it again to obtain the raw text. The app also has a simple logging function. Each time it opens a file with ".LOG" on its first line, the app inserts a timestamp on the file's last line.[21][22]

Limitations

Notepad used a built-in window class named EDIT. The maximum file size Notepad can open depends on operating system limitations on the size of the EDIT window class, with a different limit in each version of Windows. Because to this limitation, on Windows 3.0, Windows 3.1, and Windows 3.11, Notepad could not open files larger than 54 KB. (Microsoft recommended using another text editor for opening files larger than 45 KB.)[23] This limit was extended to 64 KB in Windows 95, with users now directed to WordPad for larger files. On Windows XP, Notepad was limited to 32 MB and declined to open bigger files.[24] On Windows 11, Notepad uses the RichEdit control.[25] The size limit was raised to about 1 GB, and attempting to open any file larger than that shows a dialog box suggesting that the user open it with a different text editor.[26]

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, MyName13 said:

For example, when I copy something from a web site or an IDE and then paste it into a word processor, font, font size, font color and background color are somehow copied over.How is that possible?When I paste it into a notepad, it is just plain text without any inserted metadata.

Why. Because a Word processor like Gdoc and Word is made for editing and customizing text in different ways. Notepad is made for doing anything from just quick and dirty note taking to making Windows batch files. Hell, even make coding documents sometimes depending on programming language.

 

How it does it, I have no idea at all.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, emosun said:

notepad is quite literally just a text file viewer/editor in it's most basic modern form. it's pretty much the oldest program still in use in windows

 

 

What I am interested in is how does preserving the font and background work?I don't remember this happening on Windows 7.

Does Linux do this too?

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, MyName13 said:

What I am interested in is how does preserving the font and background work?I don't remember this happening on Windows 7.

I would imagine the same way it does so for the text itself, it stores the font and formatting properties of the copied text in your clipboard and just retrieves it and applies it once you paste somewhere, provided that the target application supports that type of formatting in the first place. Remember, what you see on your screen is all just stuff being presented to you in a specific way based on how it's programmed to be seen. And if displaying text in Windows is programmed in a structured way of describing its formatting with a predictable pattern, you can just retrieve that information while you're copying the text. And if the source and target application use the same way of describing how the text should be rendered, you can obviously just pass along all that metadata with the text.

 

And just because an older operating system didn't work that way doesn't preclude a newer one from introducing it. Microsoft added that functionality later on. You can override it by using ctrl+shift+v to just paste plain text without the formatting.

And now a word from our sponsor: 💩

-.-. --- --- .-.. --..-- / -.-- --- ..- / -.- -. --- .-- / -- --- .-. ... . / -.-. --- -.. .

ᑐᑌᑐᑢ

Spoiler

    ▄██████                                                      ▄██▀

  ▄█▀   ███                                                      ██

▄██     ███                                                      ██

███   ▄████  ▄█▀  ▀██▄    ▄████▄     ▄████▄     ▄████▄     ▄████▄██   ▄████▄

███████████ ███     ███ ▄██▀ ▀███▄ ▄██▀ ▀███▄ ▄██▀ ▀███▄ ▄██▀ ▀████ ▄██▀ ▀███▄

████▀   ███ ▀██▄   ▄██▀ ███    ███ ███        ███    ███ ███    ███ ███    ███

 ██▄    ███  ▀██▄██▀    ███▄ ▄██   ███▄ ▄██   ███▄ ▄███  ███▄ ▄███▄ ███▄ ▄██

  ▀█▄    ▀█ ██▄ ▀█▀      ▀████▀     ▀████▀     ▀████▀▀██▄ ▀████▀▀██▄ ▀████▀

       ▄█ ▄▄      ▄█▄  █▀            █▄                   ▄██  ▄▀

       ▀  ██      ███                ██                    ▄█

          ██      ███   ▄   ▄████▄   ██▄████▄     ▄████▄   ██   ▄

          ██      ███ ▄██ ▄██▀ ▀███▄ ███▀ ▀███▄ ▄██▀ ▀███▄ ██ ▄██

          ██     ███▀  ▄█ ███    ███ ███    ███ ███    ███ ██  ▄█

        █▄██  ▄▄██▀    ██  ███▄ ▄███▄ ███▄ ▄██   ███▄ ▄██  ██  ██

        ▀███████▀    ▄████▄ ▀████▀▀██▄ ▀████▀     ▀████▀ ▄█████████▄

 

Link to comment
Share on other sites

Link to post
Share on other sites

When you copy something it goes to a sort scratch pad space in the cache on your cpu (or ram). This will store it sort of like a file
<text\>
hello
<text>
<font\>
green
<font>
<size\>
12
<size>

From here Notepad only support the text portion of this file so it simply grabs the text portion and ignore everything else.
In other apps like word it will read all the other portions and try and play nice with them.
Another quick shortcut if you didnt know is ctrl+shift+v will paste the stuff in clipboard but only pasting text (or merging the text formats) , this shortcut works in most applications besides microsoft mail or microsoft word

Link to comment
Share on other sites

Link to post
Share on other sites

On 7/31/2022 at 11:52 AM, MyName13 said:

What I am interested in is how does preserving the font and background work?I don't remember this happening on Windows 7.

Does Linux do this too?

Yes, it happens on all desktop OSs.

The program provides information to the clipboard, the program that you paste the text too, chooses if it cares or not about it.

 

Windows Clipboard supports out of the box:

  • Text (obviously)
  • Rich Text (that is Text with formatting)
  • Image
  • Audio
  • File path list (several files selected and copied)
  • Binary (Generic, can be used for anything)

A program can also issue multiple information on the same clipboard item.

You can also pass to the clipboard combination, like image + text... so a program like Word, can display both. And one like Notepad, will only display the text without any formatting.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/1/2022 at 3:52 AM, MyName13 said:

Does Linux do this too?

Yes. I often drop the text into Text Editor to remove the font information it will have from a website and then paste to where ever needed, especially when dropping text into a discussion forum.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×