3

The Monaco editor has a way to disable edits via a readOnly setting (https://github.com/Microsoft/monaco-editor/issues/54), which is quite useful in an extension that steps through code, aids code review, etc.

Is there a similar setting for this in VSCode API?

Lh Lee
  • 163
  • 6
  • Isn't that what your version control system is for? If you make accidental edits, you can still revert. I hardly see the use case for this. – maio290 Mar 16 '20 at 00:10
  • https://github.com/microsoft/vscode/issues/4873 – Lh Lee Mar 16 '20 at 00:33
  • files that are semantically 'readonly' should notify/prevent the user from editing them (esp if you are editing the .js derived from a .ts; it wastes your time) See: https://github.com/microsoft/vscode/issues/161715 – Jack Punt Oct 02 '22 at 18:14
  • See https://stackoverflow.com/a/76222660/836330 for an early implementation of the ability to set an editor as read-only. (Thanks @JackPunt) – Mark May 10 '23 at 21:53

1 Answers1

0

See more at Readonly Mode in v1.79 Release Notes

Here are the new commands you are looking for:

  • Set Active Editor Readonly in Session: mark active editor readonly
  • Set Active Editor Writeable in Session: mark active editor writeable
  • Toggle Active Editor Readonly in Session: toggle between readonly and writeable
  • Clear (or may be named Reset) Active Editor Readonly in Session: clear/reset the session state

Demo at https://stackoverflow.com/a/76222660/836330

Mark
  • 143,421
  • 24
  • 428
  • 436