Hi, gonna be honest, didn't check, but my friend recommended it. I'll just attach the code:
// code that implements it
vscode.workspace.onDidChangeTextDocument(({ document, contentChanges }) => {
const activeEditor = vscode.window.activeTextEditor
if (activeEditor.document !== document || contentChanges.length === 0) return
vscode.commands.executeCommand('undo')
vscode.commands.executeCommand('editor.action.goToLocations', document.uri, new vscode.Position(0, 0), [], '', 'File is read-only')
})

Hi, gonna be honest, didn't check, but my friend recommended it. I'll just attach the code: