Monaco-editor: Provide ability to block editing specific lines

Created on 10 Jul 2018  路  26Comments  路  Source: microsoft/monaco-editor

Monaco is a great editor for providing programmatic interfaces for users to an application.

One feature that'd significantly help with the user experience is to make specific lines read-only, such that user can enter their code within a specific block (e.g., between a function block).

Would it be possible to include this as a core features/API of the editor?

editor-core feature-request

Most helpful comment

Thank you for the reply. I have seen the previous issue, and this request is essentially another plea to reconsider adding back the feature (or providing some sort of native alternative).

Providing editable/read-only ranges is really useful, and the hack suggested is rather dirty/doesn't make for a good experience.

For example, consider an educational software where the following template is created, and the user/student has to enter their code in between:

function foo(arg1, arg2) {
   // your code goes here

}

All 26 comments

@sinaa This is not possible. See #874.

Thank you for the reply. I have seen the previous issue, and this request is essentially another plea to reconsider adding back the feature (or providing some sort of native alternative).

Providing editable/read-only ranges is really useful, and the hack suggested is rather dirty/doesn't make for a good experience.

For example, consider an educational software where the following template is created, and the user/student has to enter their code in between:

function foo(arg1, arg2) {
   // your code goes here

}

This would be very useful for me as well.

Yes, this would be amazingly useful for me as well, I am even considering to switch from Ace editor, if this feature can be implemented in Monaco.

Agree this would be indeed very helpful for a scenario I'm having with a current app. Based on the comment in the first line (which contains meta) additional rules are applied. So having the first line locked down in order to prevent the user from unintentionally deleting it (CTRL+A DEL) would be awesome.

yes please lets make this feature happen!

SetEditableRange Function is really useful i think....

Is this possible?

@virus2016 nope... but if you use monaco editor version 0.4.X ... you can do that...

Yeah, that would be really useful for me as well, I am thinking to use monaco editor for our production

Is there any plan to add this feature in future releases?

@alexandrudima is it something that can be implemented elegantly with the editor's current design? will you accept a PR adding back this functionality, assuming you answered yes on the former question?

I'm not sure from reading these discussions if this is a hopeless cause or simply lacking interest and manpower.

Perhaps this can be solved by a different kind of solution, like adding a before-change event which offers a canceling mechanism for changes... Any alternative which isn't a hack would be a blessing..

Another use case is wrapping code in a function when the context is different from globalThis. E.g. in my game editor, I have fields for editing several functions that are executed by specific classes, and thus I need a code like this to tell the context to Typescript, with "frozen" first and last lines:

function onCreate(this: Copy) {
   // User-written code
}

I would personally appreciate a little more granularity than just 'lines', possibly a character range, with helper methods for doing lines?

Is there any update on this issue? Any possible workarounds for non-js files meanwhile?

@mehulmpt probably... there was no update for this issues for about 2 year... maybe? m.m

Is there any update on this issue?

@alexdima Any updates on this? Or any alternative ?

Still no updates

@rcjsuen How to achive this using existing monaco api?

@rcjsuen How to achive this using existing monaco api?

@GNSubrahmanyam Sorry, I have no idea. This is not something I have ever tried to investigate as I do not have this use case in my own use of the Monaco Editor.

Example
image

from line 14 it should me editable.

Example
image

from line 14 it should me editable.

If you use SetEditableRange function() then you should use previous Version of Monaco Editor.
Probabley... I think you can find previous version in release history in github page..
(0.13.X?... I think)
good luck.

@GNSubrahmanyam, I think this post will be useful for you. I have created a way to restrict editable area in monaco-editor. This basically undos the values typed in the restricted area. You can see the demo here. I am not sure whether it will have good performance ( Try it by yourself in the demo ) , But I thought something is better than nothing. You can refer the complete code here

This is a feature that we need, we have had to hack around it, just wanted to add a +1

up

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NikGovorov picture NikGovorov  路  92Comments

gynet picture gynet  路  22Comments

fdeitelhoff picture fdeitelhoff  路  24Comments

spahnke picture spahnke  路  26Comments

jayspadie picture jayspadie  路  16Comments