Jump to content

Notepad word wrap bug


Recommended Posts

Guest Robert Hart
Posted

I recently investigated and documented strange behaviors in Notepad that

have been bothering me for a while.

 

Basically, if word wrap is on, and you save a file, Notepad inserts CR CR LF

characters at the wrap points. (These characters are only in Notepad's

display window, the file is saved without extra characters at the wrap

points.) This can cause problems if you copy and and paste from Notepad into

other windows.

 

You can read more details here:

 

Notepad bug: Saving with word wrap on inserts CR CR LF characters

http://bavih.blogspot.com/2008/07/notepad-bug.html

 

 

I tried searching online to see if anyone else had already documented this

problem. I found the threads below from this newsgroup discussing this

strange Notepad behavior, so I thought I'd share the results of my

investigation in case any one is interested, or if it comes up again.

 

Notepad bug makes it unusable

news:017E7847-3DBC-424E-807C-AD3BF8642B50@microsoft.com

http://groups.google.com/group/microsoft.public.windowsxp.general/browse_thread/thread/febcff2875b1462c/5beb9dca58ce8b99

 

An observation re Notepad

news:eoOi5XghIHA.6092@TK2MSFTNGP06.phx.gbl

http://groups.google.com/group/microsoft.public.windowsxp.general/browse_thread/thread/70bc0add6983642/4df9c749d6c0c3b0

 

 

Robert

  • Replies 9
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

Re: Notepad word wrap bug

 

 

"Robert Hart" <noone@nowhere.invalid> wrote in message

news:uNQkk.3141$zv7.2047@flpi143.ffdc.sbc.com...

>

> I recently investigated and documented strange behaviors in Notepad that

> have been bothering me for a while.

>

> Basically, if word wrap is on, and you save a file, Notepad inserts CR CR

> LF

> characters at the wrap points. (These characters are only in Notepad's

> display window, the file is saved without extra characters at the wrap

> points.) This can cause problems if you copy and and paste from Notepad

> into

> other windows.

>

> You can read more details here:

>

> Notepad bug: Saving with word wrap on inserts CR CR LF characters

> http://bavih.blogspot.com/2008/07/notepad-bug.html

>

>

> I tried searching online to see if anyone else had already documented this

> problem. I found the threads below from this newsgroup discussing this

> strange Notepad behavior, so I thought I'd share the results of my

> investigation in case any one is interested, or if it comes up again.

>

> Notepad bug makes it unusable

> news:017E7847-3DBC-424E-807C-AD3BF8642B50@microsoft.com

> http://groups.google.com/group/microsoft.public.windowsxp.general/browse_thread/thread/febcff2875b1462c/5beb9dca58ce8b99

>

> An observation re Notepad

> news:eoOi5XghIHA.6092@TK2MSFTNGP06.phx.gbl

> http://groups.google.com/group/microsoft.public.windowsxp.general/browse_thread/thread/70bc0add6983642/4df9c749d6c0c3b0

>

>

> Robert

 

This old potato keeps coming up in newsgroups. It is basically the result

of superficial observation. A thorough investigation reveals this:

- CRLFs are inserted in notepad documents only when the user

presses the Enter key.

- Enabling word wrap will cause the lines on the screen to be broken

up so that they fit into the available screen width.

- Enabling word wrap, then saving the file, will NOT cause any

extra CRLFs to be inserted in the saved file. A comparison of

the saved files - one with word wrap, the other without - will

immediately confirm this.

- When you copy a word-wrapped text (e.g. with Ctrl+C) then

the text does not contain any extra CRLFs. The copied text from

a word-wrapped document is indistinguishable from the text of

a non-wrapped document.

 

Run this little experiment to confirm the last point:

1. Open notepad and type a few lines. Do not press Enter at any time.

2. Turn off Word Wrap.

3. Press Ctrl+A, then Ctrl+C.

4. Launch MS Word.

5. Press Ctrl+V, then press Enter.

6. Go back to the Notepad.

7. Turn on Word Wrap.

8. Make sure that Notepad is "windowed" (i.e. not full screen), then

make it a fairly narrow frame. You will now have lots of short lines.

According to your theory, each should have a "hidden" CRLF at

the end.

9. Press Ctrl+A, then Ctrl+C.

10. Go back to MS Word.

11. Press Ctrl+v.

Where are the extra CRLFs?

 

If you disagree then I invite you to propose a detailed step-by-step

procedure that demonstrates the presence of those hidden CRLFs.

Please do not rely on various threads on this subject - just because

someone published his pet theory on the net does not make it a fact.

Guest Robert Hart
Posted

Re: Notepad word wrap bug

 

"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

news:%23ZVea5H9IHA.4468@TK2MSFTNGP06.phx.gbl...

> Where are the extra CRLFs?

>

> If you disagree then I invite you to propose a detailed step-by-step

> procedure that demonstrates the presence of those hidden CRLFs.

> Please do not rely on various threads on this subject - just because

> someone published his pet theory on the net does not make it a fact.

 

 

There is a detailed step-by-step example in my blog post:

 

http://bavih.blogspot.com/2008/07/notepad-bug.html

 

 

The extra CR CR LF characters are only inserted into the Notepad display

window after you save a file when the word wrap option is turned on. There

are no extra characters in the saved file.

 

You can verify the extra CR CR LF characters are there by using a program

that examines the clipboard. At the bottom of my blog post, I've provided an

AutoHotkey script that examines the clipboard and decodes control

characters.

 

In your steps, the file is never saved (the window remains an Untitled

window), so Notepad had not yet inserted any extra characters.

 

Robert

Guest HeyBub
Posted

Re: Notepad word wrap bug

 

Robert Hart wrote:

> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

> news:%23ZVea5H9IHA.4468@TK2MSFTNGP06.phx.gbl...

>> Where are the extra CRLFs?

>>

>> If you disagree then I invite you to propose a detailed step-by-step

>> procedure that demonstrates the presence of those hidden CRLFs.

>> Please do not rely on various threads on this subject - just because

>> someone published his pet theory on the net does not make it a fact.

>

>

> There is a detailed step-by-step example in my blog post:

>

> http://bavih.blogspot.com/2008/07/notepad-bug.html

>

>

> The extra CR CR LF characters are only inserted into the Notepad

> display window after you save a file when the word wrap option is

> turned on. There are no extra characters in the saved file.

>

> You can verify the extra CR CR LF characters are there by using a

> program that examines the clipboard. At the bottom of my blog post,

> I've provided an AutoHotkey script that examines the clipboard and

> decodes control characters.

>

> In your steps, the file is never saved (the window remains an Untitled

> window), so Notepad had not yet inserted any extra characters.

 

Saving a file created with word wrap on (and taking up several lines on the

screen) results in NO CR/LFs of any kind or in any quantity within the file

as confirmed by viewing the saved file with a hex editor.

Guest Robert Hart
Posted

Re: Notepad word wrap bug

 

"HeyBub" <heybub@gmail.com> wrote in message

news:O5hiP1L9IHA.4140@TK2MSFTNGP02.phx.gbl...

> Saving a file created with word wrap on (and taking up several lines on

> the screen) results in NO CR/LFs of any kind or in any quantity within the

> file as confirmed by viewing the saved file with a hex editor.

 

Correct. Notepad only inserts extra CR CR LF characters at the wrap points

in the display window. The file is saved without the extra characters.

 

You can confirm what characters are in the display window by copying them to

the clipboard, then using a program that examines the clipboard.

 

Robert

Guest dadiOH
Posted

Re: Notepad word wrap bug

 

Robert Hart wrote:

> "HeyBub" <heybub@gmail.com> wrote in message

> news:O5hiP1L9IHA.4140@TK2MSFTNGP02.phx.gbl...

>> Saving a file created with word wrap on (and taking up several lines

>> on the screen) results in NO CR/LFs of any kind or in any quantity

>> within the file as confirmed by viewing the saved file with a hex

>> editor.

>

> Correct. Notepad only inserts extra CR CR LF characters at the wrap

> points in the display window. The file is saved without the extra

> characters.

> You can confirm what characters are in the display window by copying

> them to the clipboard, then using a program that examines the

> clipboard.

 

I see what you mean. Probably. I didn't do all you did but my saved file

has spaces at the wrap points.

 

 

 

--

 

dadiOH

____________________________

 

dadiOH's dandies v3.06...

....a help file of info about MP3s, recording from

LP/cassette and tips & tricks on this and that.

Get it at http://mysite.verizon.net/xico

Guest Robert Hart
Posted

Re: Notepad word wrap bug

 

"dadiOH" <dadiOH@invalid.com> wrote in message

news:%234HC3JM9IHA.3368@TK2MSFTNGP03.phx.gbl...

> I didn't do all you did but my saved file has spaces at the wrap points.

 

Correct. There are no problems with the saved file, so it will contain only

spaces at the wrap points.

 

After saving a display window with wrapped lines, the extra CR CR LF

characters are only in Notepad's display window and not in the saved file.

Examining the saved file with a hex editor will show nothing unusual. But

copying the characters in the display window and examining the clipboard

will confirm there are extra CR CR LF characters at the wrap points.

 

Robert

Guest John John (MVP)
Posted

Re: Notepad word wrap bug

 

Robert Hart wrote:

> "dadiOH" <dadiOH@invalid.com> wrote in message

> news:%234HC3JM9IHA.3368@TK2MSFTNGP03.phx.gbl...

>

>>I didn't do all you did but my saved file has spaces at the wrap points.

>

>

> Correct. There are no problems with the saved file, so it will contain only

> spaces at the wrap points.

>

> After saving a display window with wrapped lines, the extra CR CR LF

> characters are only in Notepad's display window and not in the saved file.

> Examining the saved file with a hex editor will show nothing unusual. But

> copying the characters in the display window and examining the clipboard

> will confirm there are extra CR CR LF characters at the wrap points.

 

And what happens if you refresh or rewrap the display window? If I

remember correctly it seems to me that this is nothing more than a

WYSIWYG thing, even after you paste the clipboard.

 

John

Guest Pegasus \(MVP\)
Posted

Re: Notepad word wrap bug

 

 

"Robert Hart" <noone@nowhere.invalid> wrote in message

news:gt%kk.15526$cW3.6342@nlpi064.nbdc.sbc.com...

> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

> news:%23ZVea5H9IHA.4468@TK2MSFTNGP06.phx.gbl...

>> Where are the extra CRLFs?

>>

>> If you disagree then I invite you to propose a detailed step-by-step

>> procedure that demonstrates the presence of those hidden CRLFs.

>> Please do not rely on various threads on this subject - just because

>> someone published his pet theory on the net does not make it a fact.

>

>

> There is a detailed step-by-step example in my blog post:

>

> http://bavih.blogspot.com/2008/07/notepad-bug.html

>

>

> The extra CR CR LF characters are only inserted into the Notepad display

> window after you save a file when the word wrap option is turned on. There

> are no extra characters in the saved file.

>

> You can verify the extra CR CR LF characters are there by using a program

> that examines the clipboard. At the bottom of my blog post, I've provided

> an

> AutoHotkey script that examines the clipboard and decodes control

> characters.

>

> In your steps, the file is never saved (the window remains an Untitled

> window), so Notepad had not yet inserted any extra characters.

>

> Robert

 

OK, you're right, I was able to duplicate your findings. They actually

become apparent very quickly by following this sequence:

1. Open notepad.exe.

2. Turn on Word Wrap.

3. Write some text that spans several lines. Do not press Enter at any time.

4. Save the file.

5. Increase the width of the notepad window. The line lengths should

change. They don't.

6. Reduce the width of the notepad window. Some lines will wrap at the wrong

places.

 

And the remedy? Use notepad2.exe

(http://www.flos-freeware.ch/notepad2.html).

It does not appear to suffer from this problem and it includes line numbers

(which

I often sorely miss from notepad.exe).

Guest Robert Hart
Posted

Re: Notepad word wrap bug

 

"John John (MVP)" <audetweld@nbnet.nb.ca> wrote

in message news:%235q3P9N9IHA.3612@TK2MSFTNGP06.phx.gbl...

> And what happens if you refresh or rewrap the display window? If I

> remember correctly it seems to me that this is nothing more than a

> WYSIWYG thing, even after you paste the clipboard.

 

My blog post is very detailed:

http://bavih.blogspot.com/2008/07/notepad-bug.html

 

To summarize:

 

When you save a file with word wrap on, CR CR LF characters are inserted at

the wrap points in the display window only.

 

The CR CR LF characters remain in the display window if you resize it,

minimize it, maximize it, switch to another window and switch back, etc. The

effect is especially noticeable if you started off with a narrow window and

resize the window wider. The CR CR LF characters prevent the long lines from

re-wrapping properly.

 

If you turn off word wrap, any CR CR LF characters in the display window are

removed. If you turn word wrap back on, the lines are re-wrapped without

inserting any CR CR LF characters.

 

If you save the file again and word wrap is still on, then Notepad removes

any CR CR LF characters in the display window, saves the file, then re-wraps

the long lines and inserts new CR CR LF characters at the wrap points.

 

Robert


×
×
  • Create New...