Windows 11 Notepad

Murray Sargent

The new Windows 11 Notepad uses RichEdit and runs on up-to-date Windows 11 installations. In addition to a Windows 11 look with rounded corners and a dark-theme option, the new Notepad includes several standard RichEdit editing enhancements, such as Alt+x for entering Unicode characters, Ctrl+} for toggling between matching brackets/parentheses, multilevel undo, drag & drop, color emoji, and autoURL detection. You might guess that using a RichEdit plain-text control in Notepad would be a slam dunk. RichEdit has had plain-text controls ever since Office 97 (last century!) and they’ve been used myriad times. But those plain-text controls have been small and typically exist in dialog boxes. Notepad is often used to view large files, so high performance is important, and lines can be crazy long. And classic Notepad has been improved in various ways, such as better performance, line-ending detection (CR, LF, CRLF), and a “Show Unicode control characters” context-menu option. Accordingly, it’s taken significant effort to use RichEdit as the new Notepad’s editing engine. This post describes some additions and implementation details.

Additions to RichEdit

The classic Notepad has two handy features that weren’t implemented in RichEdit: line-ending detection (CR, LF, CRLF) and the “Show Unicode control characters” mode (discussed next). For years Notepad didn’t break Unix-convention lines that terminated with a LF (U+000A) instead of a CRLF (U+000D U+000A). I used to open the Unicode Character Data files, which contain LF-terminated lines, with WordPad and save them to convert the LF’s to CRLF’s so that Notepad would display them correctly. To fix this problem, Notepad went one better: it checked to see which line ending came first and then made that line ending the default for the file. So, a file with LF- terminated lines remains LF terminated and displayed correctly. Internally RichEdit follows the lead of Word and the Mac in terminating paragraphs with a CR and converting LF’s and CRLF’s to CR when reading in a file or storing text via an API like WM_SETTEXT or ITextRange2::SetText2. This is still the case, but you can tell RichEdit to recognize the kind of line termination in a file and use that choice for saving/copying the file by sending the EM_SETENDOFLINE message with wparam = EC_ENDOFLINE_DETECTFROMCONTENT.

Show Unicode control characters mode and emoji

Notepad has had a “Show Unicode control characters” option in its context menu for many years. This mode displays Bidi zero-width control characters using distinctive “zero-width” glyphs. This is very valuable, for example, in revealing the Bidi RLO (U+202E) and LRO (U+202D) codes that override the usual character directionalities and are sometimes used to spoof files for nefarious purposes. It also displays the zero-width joiner (ZWJ—U+200D) with a “zero-width” vertical line topped by an x. But inside emoji ZWJ sequences, such as family emojis, the mode doesn’t break the sequence apart at the ZWJ’s and doesn’t reveal the ZWJ’s by the zero-width ZWJ glyph. And classic Notepad doesn’t display ZWJ sequences and emoji in general in color.

In the new Notepad “Show Unicode control characters” mode, ZWJ sequences are broken apart at the ZWJ’s and the ZWJ’s are displayed by the ZWJ zero-width glyph. You can navigate inside the ZWJ sequence using the ← and → keys and type Alt+x to see the codes of the characters comprising the ZWJ sequence. This lets you figure out how a ZWJ sequence is constructed. For example, the new mode displays the family emoji ZWJ sequence👨‍❤️‍👩given by the codes U+1F468 ZWJ U+2764 U+FE0F ZWJ U+1F469 as

Image FamilyEmoji

Find/Replace dialog drop down

Visual Studio Code has a nifty Find/Replace dialog that drops down into the upper right of the text area. In case the dialog overlaps the starting text, the user can drag the text down just under the bottom of the dialog. The new Notepad mimics this behavior. It was a bit tricky to get RichEdit to provide the associated functionality. In rich-text formatting, the paragraph space-before and space-after properties are used to add spacing between paragraphs. Since RichEdit is a rich-text editor, it supports these properties, and it was natural to implement the drop-down space as “document space before”. The space-before value is included in the ascent of the first line in the document. The tricks came in dealing with deleting or replacing the first line and in scrolling the display correctly with a nonzero document-space-before value.

Plain-text UI improvements

We decided to match the Visual-Studio UI for selecting and not selecting the EOP character at the end of a line. This differs from Word’s UI, which tends to auto select the EOP character if you navigate next to it. Specifically, in plain-text controls, we don’t let the mouse extend the selection to include the EOP on a line or let Shift+End select the EOP. This corresponds to what gets deleted if you hit the Delete key after selecting the text. You can still select the EOP character by using Shift+→ and by extending the selection to the next line. Also, if word wrap is turned off, the insertion-point caret now follows any spaces you enter instead of ignoring the spaces.

Some implementation details

The Windows 11 Notepad uses a window for its editing canvas and windows generally use GDI for displaying text and images. GDI doesn’t have functions to display color fonts in color, whereas DirectWrite does. To be able to use DirectWrite for color emoji and other enhancements, the new Notepad therefore creates a RichEDitD2DPT window, which uses DirectWrite for text and GDI for OLE objects (Notepad doesn’t insert OLE objects).

The RichEdit build used in Notepad comes from the same sources as the RichEdit that’s loaded with Microsoft 365 applications like Word, PowerPoint, Excel, and OneNote. It’s not the Windows RichEdit in msftedit.dll. Consequently, Notepad has the latest RichEdit improvements.

We’ve fixed bugs that didn’t show up for RichEdit plain-text controls over the years partly because before Notepad, the plain-text instances have been small.

Notepad uses RichEdit classic font binding instead of the IProvideFontInfo font binding used in XAML text controls and in RichEdit controls appearing in Microsoft 365 applications. Notepad doesn’t want to load the mso libraries used in the latter since these libraries are quite large. The classic font binding has been improved but needs to add support for more scripts.

We improved RichEdit’s performance for large ASCII files such as those for core dumps. One feature that can slow down reading in a large file is autoURL detection. While reading in plain text, LF and CRLF are translated to CR for internal use and in the process the text is checked for the combination “:/”. If that combination isn’t found and only AURL_ENABLEURL is enabled, autoURL detection is bypassed.

Future

Imagine things that can be added given the power of RichEdit. RichEdit plain-text controls have only one paragraph format, but they can have considerable character formatting. The latter is needed because 1) Unicode has over 144,000 characters and a single font is limited to 65535 glyphs, and 2) input method editors (IMEs) and spell checkers require underlines and/or text coloring. So, although the user interface only exposes one character format, the TOM object model gives access to many more properties (see ITextFont2). Accordingly, it would be possible to offer program code syntax highlighting used, for example, in Visual Studio and Visual Studio Code. But probably that should be the domain of compiler interactive development environments. Another option could be to display HTML, XML, JSON, and RTF files with indentation and toggle between XML/HTML start and end tags like Ctrl+} does for bracketed expressions, e.g., in JSON and RTF files. Large file performance needs more improvement. Please feel free to comment about bugs and wishes!

55 comments

Discussion is closed. Login to edit/delete existing comments.

  • Iacopo Vettori 0

    A while ago, I tried using RTF to share a document with images. I was disappointed to learn that images are automatically converted and saved in two different formats, increasing the file size in an unacceptable way. I tried to force the use of only one image format using Word with the reg key “ExportPictureWithMetafile = 0” (not working for WordPad). The file size decreased but the images in the resulting RTF were not visible in the .NET Framework 4.5 RichTextBox, so I had to use another file format. I hope this will be resolved if RTF is used extensively with the new Notepad.

    • Murray SargentMicrosoft employee 0

      The new Notepad only supports plain-text file formats, although an interesting option would be to allow it to read RTF files distilling out the plain text. For a while, RichEdit only wrote standard image formats (png, jpeg, gif, etc.) for RTF, but with the msftedit.dll some clients wanted bmp. So, we had to add that back thereby increasing files with images enormously :-(. As a plain text editor, Notepad doesn’t support images.

  • John Schroedl 0

    Is there any chance you’ll share more of the code which enables the mixing of GDI and D2D? I am in a similar situation trying to update legacy GDI/GDI+ based gfx code to enable more modern appearance (colored emoji et. al.). We can’t really try to use the RichEdit as described in your posts due to our architecture and mixing of many graphs, text, controls, etc. But, I’d love to see the code which handles the text drawing and measurement into an HDC and mixes that with other GDI content!

    • Murray SargentMicrosoft employee 0

      Some of the code is easy to share, namely getting an ID2D1DCRenderTarget from ID2D1Factory::CreateDCRenderTarget() and using that target with the RichEdit engine. But the harder part is showing how RichEdit is ambidextrous with regards to GDI and D2D. There’s a lot of code that depends on which display technology is used. One interesting detail is that DirectWrite support is available on all end points: Win32, WinRT, iOS, Mac, and Android. But GDI support in RichEdit is only available on Win32. The GDI code paths can use DirectWrite and D2D if need be, but not the reverse. The window classes RichEditD2D and RichEditD2DPT do use both: DirectWrite for text and GDI for OLE objects.

  • Harsh 0

    Following will be a good addition to Notepad.
    (1) It would be nice if notepad allows find and replace using a regular expression.
    (2) Basic code autocomplete much similar to Notepad++
    (3) Allowing to use VS Code shortcuts if possible.
    (4) It would be a good idea to have a “Developer” flag in a setting much similar to the “Calculator” app that only developers can see more advanced options in Notepad.

    • Murray SargentMicrosoft employee 0

      Cool ideas. Added to the wish list

  • Krista J. Sanders 0

    I hope Microsoft could opensource Notepad, which for sure would make it much better. It could be the next Windows Terminal.

    • Murray SargentMicrosoft employee 0

      It’d sure be nice to get some help 😊

  • Hamed 0

    I think Notepad updates were the best changes of this Windows upgrade. ❤️
    Thanks for these great features and please keep the most important feature of Notepad in next updates too: it’s performance and response time!

    • Murray SargentMicrosoft employee 0

      We have to work on performance for large files. There are some promising possibilities.

  • Thomas Boomer 0

    The new notepad does not allow me to select text from the middle of a line. It grabs the whole line every time. This is not consistent but it happens often enough and is very annoying.

    I should be able to swipe a word from the middle of a line and copy it, but sometimes it just keeps selecting the entire line.

    • Murray SargentMicrosoft employee 0

      On the last line? Yes, I fixed that recently. Should show up in an update soon.

  • KOSTAS KONSTANTINOS 0

    I have some problems with the new windows notepad :
    * I cant find “Terminal” font in new windows notepad (is very important)
    * If text ends with a empty new line, cant click with the mouse in the last line with text (caret moved to last line and not to the line where make the click)

    • Murray SargentMicrosoft employee 0

      The Terminal font isn’t a TrueType font and can’t be rendered by DirectWrite. DirectWrite is needed to display color emoji and other typographic enhancements. We could make an option to support Terminal, but that option would use GDI and not have color emoji, etc. So, if you need Terminal, I recommend using the classic Notepad instead of the new Notepad. The second problem is fixed and an update should be installed soon (see previous comment).

      • KOSTAS KONSTANTINOS 0

        How to revert to, or open the clasic Notepad ? New Notepad installed with windows 11 update process.

        • Murray SargentMicrosoft employee 0

          To use the classic Notepad, search for “alias” on the Windows Start menu and run it. Look down the list for “Notepad” and slide the slider icon to “Off”. Then you can run c:\windows\system32\notepad.exe to run the classic Notepad.

          • KOSTAS KONSTANTINOS 0

            Thanks !!!

  • Andreas Rejbrand 0

    Does the new Rich Edit-based Notepad support mathematical auto-correct? I mean, you write \alpha, \int, \deg, \oiint, \partial, \sqrt, \scriptM etc. and get α, ∫, °, ∯, ∂, √, ℳ? This is one of the features I cannot live without in a text editor or word processor! It would be great, of course, if Microsoft Office and Notepad used the same mapping table for these codes. (For instance, if I add \en for an EN DASH in Microsoft Word, it will also work in Notepad.)

    Personally, I use my own text editor (Rejbrand Text Editor) which supports this kind of input, and shares the “autocorrection” table with all my other software applications based on a simple text file in the user’s home directory.

    (Another feature which is sometimes highly convenient is multiple carets, especially on the same column of adjacent rows. But I suspect that feature request will not survive the “minus 100 points” rule.)

    • Murray SargentMicrosoft employee 0

      It would be easy to support math autocorrect since the underlying editor, RichEdit, has built-in math autocorrect. The regular Microsoft 365 autocorrect depends on the mso.dll, which isn’t shipped by Notepad since it’s large and mostly irrelevant for a plain text editor. Have to think about multiple carets. Block selection uses multiple carets. Is this what you’re referring to?

  • mrcat meow 0

    Has anyone else been seeing significantly higher memory usage with the new win32 XAML Islands apps like notepad, task manager and paint? I used to use notepad all the time and now it’s not so light for me and so I’ve been using it less. 36 MB when I type in a few words is ridiculous.

    It is possible to uninstall the MSIX packaged Notepad and to use the built-in Notepad but the file associations are borked. I’d honestly love to see all of the changes EXCEPT for the WinUI stuff.

    Notepad is meant to be simple and fast. And simple accessibility features like drag and release on menus are now gone: https://github.com/microsoft/microsoft-ui-xaml/issues/815. And there is course the padding. Increased padding on the static status bar is funny. Padding’s not the worst of it though and is minor.

    Ah and speaking of accessibility, it’s now hard to tell if the window is active or not! Yay.

    I’m probably one of the few people to say that I like that Notepad isn’t a code editor. I realise that this is a bunch of rather irrelevant stuff when the entire post is about Microsoft 365’s RichEdit, but where else will I hope to get anyone from Microsoft to hear out my issues? *sigh*

  • WORK PC 0

    Beautiful. It will be much more better, if the new notepad has an option to bold, italics, strike, and underline text.

    • Murray SargentMicrosoft employee 0

      Maybe have a mark-down option? There needs to be a way to save lightly marked up text. Since the underlying edit engine is RichEdit, there could be a “preview” mode that works with the usual bold/italic/underline hot keys. Alternatively, you can get English letter bold, italic, and bold italic using the math alphabetics in the Unicode range U+1D400..U+1D49B. Note that math italic h is ℎ (U+210E) since it existed before the math alphabetics were added. But the math alphabetics are only coded for a..z and A..Z, since accented math characters are rendered by a math display engine. OfficeMath uses a math accent object for this.

Feedback usabilla icon