FG
🛠️ Developer ToolsMicrosoft

Add read-only mode

Freshabout 19 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

- VSCode Version: 0.10.11 - OS Version: Fedora 23, 64bit Details: - Please add read-only mode and its keyboard shortcut. - It should be a switch. When turned on, opening new files will be in read-only mode. - It should be persistent across restarts. This feature should be very useful for code reviewing. And I think it's not hard to implement. Thank you,

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Implement Read-Only Mode in VSCode

Medium Risk

The current version of VSCode lacks a built-in feature to toggle read-only mode for files, which is essential for scenarios like code reviews. The absence of this feature means that users can inadvertently modify files during reviews, leading to potential errors and confusion.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Add Read-Only Mode Toggle

    Implement a toggle switch in the settings menu that allows users to enable or disable read-only mode. This should be stored in the user settings to ensure persistence across sessions.

    typescript
    const readOnlyMode = vscode.workspace.getConfiguration('editor').get('readOnlyMode');
    vscode.workspace.getConfiguration('editor').update('readOnlyMode', !readOnlyMode, true);
  2. 2

    Set Keyboard Shortcut for Read-Only Mode

    Define a keyboard shortcut in the keybindings.json file to quickly toggle the read-only mode. This enhances user experience by providing quick access.

    json
    { "key": "ctrl+r", "command": "editor.toggleReadOnlyMode" }
  3. 3

    Modify File Opening Behavior

    Adjust the file opening logic to check if read-only mode is enabled. If it is, open files in a read-only state, preventing any modifications.

    typescript
    if (readOnlyMode) {
      editor.setReadOnly(true);
    }
  4. 4

    Persist Read-Only Setting Across Sessions

    Ensure that the read-only mode setting is saved in the user settings file, so it remains active even after restarting VSCode.

    typescript
    vscode.workspace.getConfiguration('editor').update('readOnlyMode', readOnlyMode, true);

Validation

To confirm the fix, enable read-only mode using the toggle or keyboard shortcut, then open a file. Attempt to edit the file; modifications should not be allowed. Restart VSCode and verify that the read-only mode remains enabled.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

vscodeideeditorfeature-requestplan-itemon-testplanworkbench-editors