Prevent modification of (first) line of text in Scintilla

162 views
Skip to first unread message

Gunnar Adams

unread,
Jun 6, 2017, 5:21:18 PM6/6/17
to scintilla-interest
Hi,
we are using Scintilla as a source code editor in a proprietary development environment.
Due to a new requirement, I am looking for a way to prevent users from making any modification to the first line of code (which, in our case, always contains the declarative part of a code segment).

I was thinking about the following stragegies:

1. Use additional styles with the changeable style flag set to false for anything in the first line. ==> I do not like the idea to duplicate all styles and am unsure, if I can prevent ALL possible changes by doing that (will a user be able to select the whole first line and delete it?).

2. Place a second read-only Scintilla window on top of the existing editor. Put the first line in there, the rest in the editor below. ==> Auto-sizing the scintilla window's height (in Wrap-Mode) may be a problem. When not in wrap-mode, how to prevent display of the horizontal scrollbar?

3. Modify the scintilla dll in order to prevent modification of the first line or line ranges.
==> because this would require least modification to the containing application, I think this may actually be the best option. Where would I have to start?

Best regards,
Gunnar

Neil Hodgson

unread,
Jun 6, 2017, 6:13:29 PM6/6/17
to Scintilla mailing list
Gunnar Adams:

> 1. Use additional styles with the changeable style flag set to false for anything in the first line. ==> I do not like the idea to duplicate all styles

Yes, this is a problem. There should instead be a (potentially invisible) indicator for protected areas.

> and am unsure, if I can prevent ALL possible changes by doing that (will a user be able to select the whole first line and delete it?).

Whether to allow deletion of whole protected sections is one of the key questions for this function. Currently Scintilla does not allow deleting any of the text which is not changeable. To experiment, try using the notchangeable attribute in SciTE, so, for example with C++ line comments:
style.cpp.2=$(colour.code.comment.box),$(font.code.comment.box),notchangeable,back:#FFDEDE

> 3. Modify the scintilla dll in order to prevent modification of the first line or line ranges.
> ==> because this would require least modification to the containing application, I think this may actually be the best option. Where would I have to start?

Search for RangeContainsProtected in the source.

Have a look at previous discussions like
https://groups.google.com/d/topic/scintilla-interest/649-PGt0bKE/discussion

Neil

Paul K

unread,
Jun 7, 2017, 12:38:31 AM6/7/17
to scintilla-interest
> Due to a new requirement, I am looking for a way to prevent users from making any modification to the first line of code (which, in our case, always contains the declarative part of a code segment). 

I think one other option to consider is to switch the editor to read-only mode depending on the cursor position; this is what I do in the "console" panel I have in the IDE I'm developing that has some areas that shouldn't be modified, but still need to be accessed (like results of previous commands).

There are several cases that complicate this and need to be handled as well, like the selection starting in the "protected" area, but ending outside of it or multiple cursors inside and outside the protected area (and probably few other things), but handling those should be doable too.

In my case I set ReadOnly status in UPDATEUI event based on the result of all the checks I want to apply, but there are probably alternative events that may work in your case.

Paul.
Reply all
Reply to author
Forward
0 new messages