I’m attempting to highlight DNA codons, which are bunches of three letters (A, G, C, or T) aligned from the beginning of the sequence. For example:
- raw sequence:
- split by codon:
GAC|TAG|ACA|T...(note the shift here)
Since it’s important to make sure codons are lined up correctly, I’d like to highlight them in alternating colors (likely shades of gray), depending upon whether they’re an “odd” or “even” codon (first odd, second even, and so on). The first thing I thought of to do that would be to have an
onDidStopChanging callback which would destroy all marks, remark the entire buffer, then redecorate the marks sequentially. For buffers of any size, obviously, that would take a while and not really be an enjoyable editing experience.
So the second thing I thought of would involve making some sort of grammar for this, but I’m not certain a regex would be able to perform this exact task: counting whether a set of 3 letters in a string is an “even” or “odd” codon and then highlighting (of course, regexes can do anything, but I’m not sure where I’d start with that).
Is there an easier way to use markers to accomplish this? Since the lines demarcating codons keep shifting upon text inserted, I don’t think there’s a way to keep the same markers, but I’d really like to know a more performant way to accomplish this task.