I just want to make sure I’m approaching my problem correctly. I’m setting up an educational application, in which I want much of the code at any given time to be read-only. The various text ranges need to be kept separate as code is updated, even when multiple sequential ranges are read-only.
I’ll be adding lines in code at initialization, and from time to time, however. So, here’s what I’ve found so far:
- Although I’d like to be able to restrict the user from adding or deleting new lines, this doesn’t appear to be possible. I can use keystroke events to prevent the user from removing a line, but especially when typing quickly, they don’t appear to work consistently; and there seems to be no way to prevent the user from pasting multiple-line text. (In fact, there seems to be no reasonable way to restrict use of the clipboard at all).
- When I try to divide up all text between ranges, so that all characters in any given line are in exactly one range, this also appears to be impossible. I’ve tried various combinations of inclusiveLeft and inclusiveRight, but it seems that it’s always possible to enter characters outside of established ranges, especially at the end of the document. So I will have to correct the ranges after the fact.
- When use replaceRange or setValue to add text, I will need to adjust all the existing ranges to conform to the changes. According to this post:
Way to update content covered by text marker and keep text marker attached to document?
…it seems that I will need to recreate all textMark ranges after updating the contents. Since I will be making multiple changes to the text at a time, the easiest way to do this will be to use setValue rather than multiple replaceRanges, since replaceRange will not automatically update existing textMark ranges. - Also, when I run replaceRange rather than setValue to set up the initial text on startup, replaceRange appeared to terminate code execution rather than returning to the calling routine…? I am probably screwing something up, because I assume this isn’t how it normally works?
So in summary, I will use other events to correct user changes to the textMark ranges after the fact, rather than prevent them from messing them up, and I’ll recreate all the ranges every time I add or remove text from the contents. I’ll use setValue rather than replaceRange to update the contents.
Does this sound like the correct approach? Thank you!