Live data from Hacker News

Text Editor Data Structures

cdacamar.github.io

1–10 of 81 posts

Re: Text Editor Data Structures

#2
Apple's MPW was Apple's programming environment for a long time.

It's been a while, but I believe that it represented everything in a tree of n-character chunks (n = 6?). It was probably the first editor that I used that could open files of pretty much any length.

Re: Text Editor Data Structures

#4
post #2

Apple's MPW was Apple's programming environment for a long time. It's been a while, but I believe that it represented everything in a tree of n-character chunks (n = 6?). It was probably the first editor that I used that could open files of pretty much any length.

I do miss the 'select and execute', and 'everything is a shell' model of MPW. Definitely one of my favorite development environments.

Re: Text Editor Data Structures

#5
There are tons of articles about plain text editor data structures, but what about rich text editor data structures? Let's say i want to implement a text editor that can have bold, italic, underline, etc text but also be able to do automatic word breaking, align paragraph text to left/middle/right, insert images and/or other objects, have floating images and/or other objects around which the other (non floating) text/images/objects wrap, etc.

What would be the data structures for that? I can only think of trying to replicate something like the HTML DOM but i have a feeling something like Write for Windows 3.1 used a simpler data structure.

Re: Text Editor Data Structures

#6

There are tons of articles about plain text editor data structures, but what about rich text editor data structures? Let's say i want to implement a text editor that can have bold, italic, underline, etc text but also be able to do automatic word breaking, align paragraph text to left/middle/right, insert images and/or other objects, have floating images and/or other objects around which the other (non floating) text…

It's not actually that different or complicated if you're already doing proportional plaintext rendering -- you need to store style attributes for a range of text, and you need to support different heights per line.

The real complexity is rendering all of unicode properly, and supporting international fonts, bidi layout, vertical text, etc.

Re: Text Editor Data Structures

#7
post #2

Apple's MPW was Apple's programming environment for a long time. It's been a while, but I believe that it represented everything in a tree of n-character chunks (n = 6?). It was probably the first editor that I used that could open files of pretty much any length.

I do miss the 'select and execute', and 'everything is a shell' model of MPW. Definitely one of my favorite development environments.

sounds like plan9's acme

Re: Text Editor Data Structures

#8

There are tons of articles about plain text editor data structures, but what about rich text editor data structures? Let's say i want to implement a text editor that can have bold, italic, underline, etc text but also be able to do automatic word breaking, align paragraph text to left/middle/right, insert images and/or other objects, have floating images and/or other objects around which the other (non floating) text…

Yes, I think your instinct to look at win32 APIs is a good one. Many structures in riched are public in headers, and of course you could reference Wine's implementation[1].

[1] https://source.winehq.org/git/wine.git/tree/HEAD:/dlls/riche...

Re: Text Editor Data Structures

#9
post #6

There are tons of articles about plain text editor data structures, but what about rich text editor data structures? Let's say i want to implement a text editor that can have bold, italic, underline, etc text but also be able to do automatic word breaking, align paragraph text to left/middle/right, insert images and/or other objects, have floating images and/or other objects around which the other (non floating) text…

It's not actually that different or complicated if you're already doing proportional plaintext rendering -- you need to store style attributes for a range of text, and you need to support different heights per line. The real complexity is rendering all of unicode properly, and supporting international fonts, bidi layout, vertical text, etc.

Indeed, you could even use a piece tree just like in the blog but you store additional information in each piece which tell the renderer how to layout the associated text. My understanding is that most rich text editors represent the text as a node-based tree anyway.

Re: Text Editor Data Structures

#10

There are tons of articles about plain text editor data structures, but what about rich text editor data structures? Let's say i want to implement a text editor that can have bold, italic, underline, etc text but also be able to do automatic word breaking, align paragraph text to left/middle/right, insert images and/or other objects, have floating images and/or other objects around which the other (non floating) text…

its probably instructive to look at elisp text properties. not so much that its a great system - but it raises some messy questions about how to operate on substrings that have different sets of properties
Post reply on HN