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 6167551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:31:58+00:00 2026-05-23T22:31:58+00:00

I’ve developed my own syntax highlighting library for Android, and it works great, but

  • 0

I’ve developed my own syntax highlighting library for Android, and it works great, but the problem is it slows down the typing.

I’ve tried using an AsyncTask to perform the regular expressions in the background then apply the necassary colours but it still slowed down the typing process.

Currently, it reads the whole EditText, I thought of instead getting the line the text cursor is on, getting that lines CharSequence then performing the regular expressions on that line instead of the whole document, but I really don’t know how I could get the line the user is working on :(.

  • 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-05-23T22:31:59+00:00Added an answer on May 23, 2026 at 10:31 pm

    Unless you’re only doing single-line regexn/highlighting, your proposed strategy may not work. For example, you probably can’t tell if you’re in a multi-line comment without, well, scanning multiple lines. 🙂

    If you have not done so already, use Traceview to identify where the slowdowns are specifically. It may be that you can optimize enough other things. For example, maybe you’re compiling all your Pattern objects on the fly rather than defining them statically.

    Beyond that, I think a typical pattern is to only apply syntax highlighting when the user pauses. One possible way of implementing that would be:

    Step #1: On every text change (which you have presumably already hooked into), postDelayed() a Runnable and save the timestamp retrieved from SystemClock.uptimeMillis() in a data member of your EditText subclass (or wherever you have the syntax coloring logic). For the purposes of this answer, I’ll call your delay period that you use with postDelayed() as DELAY.

    Step #2: The Runnable compares the current time from SystemClock.uptimeMillis() with the time of the last text change. If the time difference is less than DELAY, you know the user typed something in between when this Runnable was scheduled and now, so you just do nothing. If the time difference >= DELAY, though, you run through your syntax coloring logic.

    This way, you skip applying the syntax coloring until the user pauses, thereby not interrupting their typing. You can tweak DELAY, or perhaps make it configurable.

    BTW, you are planning on releasing this as an open source library, right? 🙂

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I

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.