Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Google Docs implement rich text editing? [closed]

Tags:

javascript

dom

I just finished reading the section about rich text editing in browsers in Professional JavaScript for Web Developers by Nicholas Zakas. It says there are two ways to go about implementing rich text editing:

  1. iframe with designMode property set to on
  2. or an element with contenteditable attribute

What I concluded from that information is that both techniques have so much cross-browser inconsistencies that neither one is really a reliable solution.

Inspecting Google Doc's mark up, all I see is a bunch of nested divs.

So, I'm curious, what technique has Google determined to be the most suitable for implementing rich text editing?

like image 933
M.K. Safi Avatar asked Oct 27 '13 14:10

M.K. Safi


People also ask

Is Google Docs a rich text editor?

Google Docs is still a rich text editor and this isn't going to magically change once you enable the Markdown feature. Instead, Google Docs will replace common Markdown formatting with rich text. For instance, you can create links with parentheses and brackets like [this](https://techcrunch.com) .

How do you implement rich text?

Create a rich text fieldSelect Click to Add, and then select Long Text from the list. Double click the field header and enter a meaningful name for the new field. Save your changes.

How does rich text editors work?

A rich text editor is an interface or input field for text editing, that includes advanced styling options like heading levels, bold, italic, bullet points, font typefaces, and text size. You can also embed images, hyperlinks, and other rich media (such as videos) into a rich text editor.


1 Answers

Google Docs don't use neither designMode nor contentEditable. It has its own rendering engine written in Javascript. From their blog post on it:

To get around these problems, the new Google document editor doesn’t use the browser to handle editable text. We wrote a brand new editing surface and layout engine, entirely in JavaScript.

and

By far the most difficult thing the editor does is figure out where to draw text. For this, we built a new layout engine. Here’s an example of how the new engine works: say you type the letter ‘a’. We notice you pressed the ‘a’ key and respond by drawing a single ‘a’ off-screen. We then measure the width and height of that ‘a’, combine those measurements with the x and y position of your cursor, and place the ‘a’ at the correct spot on the screen. If you’re in the middle of a word, we push the characters after your cursor over. If you’re at the end of a line, the editor moves your word to the next line and pushes any overflow to the lines after it.

like image 61
kol Avatar answered Sep 23 '22 18:09

kol