In Windows 7, WordPad has undergone many improvements even though it uses RichEdit 4.1+ for editing and display. Time and time again, the excellent Hyderabad team responsible for enhancing the Windows 7 WordPad requested very reasonable extensions to RichEdit 4.1, extensions that have been included in later versions of RichEdit. They’ve also requested features that aren’t in the latest RichEdit (7.0) which ships with Office 2010, but that’s another story. One of their many requests has to do with limiting numbered paragraphs to a maximum number of 255. Why not 1000 or 10000? The reason for the small numbering maximum is that RichEdit 4.1 doesn’t cache paragraph number offsets and calculating the offsets on the fly can require substantial execution time. Without the limit, the RichEdit team had bugs claiming that RichEdit was literally hanging. Interestingly enough, later versions of RichEdit don't have this limit. Let's see why.


When the original OneNote was created in the Office 2003 time frame, it used RichEdit 5.0 and needed some special Page/Table Services (PTS) features.  PTS is a component library complementing LineServices. PTS is responsible for laying out pages and tables, whereas LineServices is responsible for laying out individual lines. PTS requires “names” for each paragraph (soft or hard), so Sasha Gil of the RichEdit team added special “NMP” runs for the purpose. Fortuitously, this run infrastructure provides a convenient place to cache paragraph number offsets and allowed us to remove RichEdit’s numbering maximum of 255.


Ironically OneNote has always handled paragraph numbering itself, but nevertheless RichEdit numbering has benefitted by OneNote’s need for PTS. Bidirectional (BiDi) layout involving Hebrew and/or Arabic text and math processing also benefit since the NMP runs greatly speed up paragraph boundary navigation. In fact RichEdit 6.0 and later versions automatically enable NMP runs whenever numbered paragraphs, BiDi and/or math are present in a document even if PTS itself isn’t enabled.


A footnote to this saga is some sage advice given to me by Eliyezer Kohen, the leader of the original teams that developed Microsoft’s TrueType implementation, the OpenType specification, LineServices, and PTS. I was designing and implementing RichEdit’s binary format for, you guessed it, the first version of OneNote (OneNote 2010 has switched to a different format). Eliyezer strongly recommended that RichEdit’s binary format tag paragraph boundaries explicitly, even though RichEdit didn’t formally need such tagging. He was absolutely right. From both structural and performance standpoints, knowledge of paragraph boundaries is very valuable in text editing and display.