Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7954881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:34:02+00:00 2026-06-04T03:34:02+00:00

For those who haven’t worked with the Google Docs editor here’s a short explanation

  • 0

For those who haven’t worked with the Google Docs editor here’s a short explanation of how it works:

  • Google Docs has no visible editable textarea or contentEditable elements.
  • Google Docs listens for keydown/press/up in a separate iFrame where they place the OS cursor for event listening.
  • When the iFrame catches an event Google handles it by performing the equivalent operations on the visible document.
  • The “caret” in Google Docs is a DIV that is styled and scripted to look and act like an OS cursor.

With that out of the way, here’s my request:

I’m working on a plugin that interacts with the Google Doc and I need to be able to do two things:

  • Highlight words with an opaque overlay DIV.
  • Determine cursor position inside a word.

I’ve been exhausting a lot of ideas about just how to handle this, but so far I’ve only manage to get a buggy solution for the latter problem (I perform a backspace, determine where the text changed and undo the backspace).

I’m looking for all the best ideas you can come up with to solve these problems. They don’t need to be cross browser, but they do need to be able to be turned into something robust that will also handle things such as font size changed mid line.

A little bit of extra info explaining what a Google Doc looks like in HTML:

<wrapper> // Simplified wrapper containing margins, pagination and similar
  <div class="kix-paragraphrenderer"> // single DIV per page wrapping all content
    // Multiple paragraphs separated by linebreak created by Enter key:
    <div class="kix-paragraphrendeder">...</div>
    <div class="kix-paragraphrendeder">...</div>
    <div class="kix-paragraphrendeder">
      // Multiple wrapper divs created by Google's word wrapping:
      <div class="kix-lineview">...</div>
      <div class="kix-lineview">...</div>
      <div class="kix-lineview">
        // Single inner wrapper, still full width of first wrapper paragraph:
        <div class="kix-lineview-content">
          // Single wrapper SPAN containing full text of the line, but not display:block
          <span class="kix-lineview-text-block">
            // Multiple spans, one per new font change such as normal/bold text,
              // change in font size, indentation and similar:
            <span>This is normal text</span>
            <span style="font-size:40px; padding-left:4px;">This larger text.</span>
            <span style="font-weight:bold; padding-left:10px;">This is bold text</span>
            <span style="padding-left:4px;">More normal text</span>
          </span>
        </div>
      </div>
    </div>
  </div>
</wrapper>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:34:03+00:00Added an answer on June 4, 2026 at 3:34 am

    After more tinkering I came to the conclusion that it is extremely troublesome – if not impossible – to try and programmatically determine cursor position with regard to a letter inside a <span>, simply because the <span> is the smallest element that is measurable (correct me if I am wrong).

    So how to solve the problem? Here’s what I ended up doing:

    • I create an offscreen positioned <div>
    • I get the text of the current paragraph (<div class="kix-paragraphrenderer">) – I could get the entire text, but wanted to limit the computational load.
    • I extract each single character of the paragraph by looping through its children in the following way:
      • Loop through linveviews of the paragraph (<div class="kix-lineview">)
      • Get the lineview content (<div class="kix-lineview-content">)
      • Loop through text blocks of the lineview content (<span class="kix-lineview-text-block">)
      • Loop through <span>‘s of the text block
      • Loop through innerText of the <span>
      • I append each character in my offscreen <div> with the currently applied style extracted from style.cssText of the current <span>
      • For each character appended I measure the width of the <div> and save this in an array. I now have a position of each single character.
    • I measure the position of the cursor relative to my widths and voila – I know where the cursor is positioned in the text.

    This is obviously a bit simplied (I left out details about margins and paddings of the different elements), but it covers the idea behind how it’s possible to get the cursor position.

    It works quite well, but there are many pitfalls and a lot of measuring required. On top of that it’s also required to post-parse the text if you want to use it for anything, since tabs, spaces and linebreaks aren’t always included in innerText (depending on where these are in the text, Google may or may not make them through positioning of new elements).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(For those who haven't heard of it, Pivotal Tracker is a simple, story-based project
For those of you who haven't been reading my Qt questoins, I am learning
Here is the wiki for those who want to know about Apache CXF. http://en.wikipedia.org/wiki/Apache_CXF
This question will seem obvious to those who haven't encountered the problem themselves. I
I received this code from one of those nice people here who are willing
For those who haven't used DrScheme, window is split in two parts: one part
I am trying to use a forum with my website. Those who haven't registered
For those veterans who haven't tried Hpple, it's great. It uses Xpath for searching
For those of you who have ever used Microsoft Excel in a manner that
Those who invented Android and Java didn't invented for themselves. Since I started developing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.