Odd Notepad bug

Notepad–the text editor that ships with Windows–is an incredibly useful program.  Sure, many users never see it, but I’m continually editing or viewing text files, batch scripts, .ini files (yes, there still are a few of those around), miscellaneous configuration files, log files, and all manner of program output that I direct to files.

Users, especially programmers, look upon Notepad with scorn, and for good reason.  It’s been around for years (at least since Windows 3.1), and it’s just a basic text editor:  nothing fancy and no advanced features.  As a programmer’s text editor it leaves a lot to be desired compared to modern tools, but it’s as good as WordStar’s non-document mode that I used before I got Turbo Pascal.

In any case, today I was editing a file with word wrap turned on.  I saved the file and continued typing without really looking at the screen.  When I looked up, the stuff that I’d typed ended up in the middle of a line somewhere, several lines above where I thought the cursor was when I pressed Ctrl+S to save.  I’d run into this a few times previously but always assumed that I’d moved the cursor inadvertently.  Today I thought I’d investigate.

I opened a new document in Notepad and resized the window.  Then I typed the text you see here:

The blue mark is under the cursor–right at the end of the line.

Then I pressed Ctrl+S to save the file.  The effect is the same if you select Save from the file menu.  I named the file “xxx.txt”.  For reasons unknown, Notepad moved the cursor three spaces back, as you can see here:

I know, a lot of you are wondering why I use Notepad at all when I have so many other editors to pick from.  As I’ve said before, I do have TextPad installed and I use it for most serious editing.  But Notepad is very useful for two primary reasons:  it’s small and loads very quickly; and it’s installed on every Windows system.  I don’t have TextPad on my lab machines or on the build machine–it’s Notepad all the way.  Same for other machines (like Debra’s or friends’) that I’m asked to look at from time to time.

This is not, by any stretch of the imagination, the only bug to be found in Notepad.  There are many bugs that involve word wrap (the bug I illustrated above only happens when word wrap is turned on), including the interesting limitation that you can’t display the status bar if word wrap is enabled.  Take a look at Craig Andera’s “Interesting” Notepad Bug entry and associated comments for more information.  Or just search Google for “notepad word wrap bug”.

It’s really too bad that Microsoft won’t address these bugs.  Notepad is incredibly useful, but the existence of these defects forces me to be extra careful when I’m editing a file.  As it stands, Notepad almost doesn’t suck.  It wouldn’t take but a week, tops, for a marginally competent programmer to fix those problems.  I realize that there is no direct economic payoff, but it would be a huge public relations win at very little cost.