I'm using IDE 2.1.0 under Win10 and am working on a project with over 20 files. Somehow I managed to get the popup dialog:
Cannot edit in read-only editor
when I was working on a specific file. I've seen the other threads with similar issues, but it seems that most of those were caused by the file being outside the project directory. That's not the case here. It is in the project's directory.
The problem occurred when I was doing a global search-and-replace of an old function name and replace it with a more descriptive name. When I do such searches, the Source Window splits vertically into two panes and I edit the name in the one pane. I'm wondering what happens if I edited the wrong pane? I may have done that.
I've found a work-around that might provide some clues to a real solution.
First, check the directory for your sketch's source code and look at the Properties (right-click, select Properties). If the file attributes are marked Read-Only, uncheck the box. This might fix the problem. If not, then continue below.
Next, follow these steps:
Follow the path to .arduinoIDE. For me, the path is: c:/Users/User
Delete the .arduinoIDE directory
Restart the IDE. This will restart with the minimum sketch frame work.
Select the Board and Port to reflect your system.
Reload your sketch.
Check to see if the read-only file is "double listed". That is, when I did the above, the file that was giving me the Read-only error was duplicated in the project. One copy was read-only, the other was not. I deleted the read-only file (touch its 'X' in the Tab) and all was right with the world.
I should have checked the project attributes first, as mentioned above, but when I saw that the File menu options were missing, I remembered that deleting the .arduinoIDE directory restored that, so I did that before I thought to check the project's Properties.
I'm not sure what I did to trigger this, but what's presented here is a work-around, not really a solution, because I don't know what caused the problem.
You will be prevented from editing and the "Cannot edit in read-only editor" tooltip will appear if you attempt to manually edit the right hand pane in the split editor when you have it in this "replace preview" mode that is accessed by clicking one of the items in the search and replace results in the Search view.
You can only edit the content in the left pane of the split editor. The reason editing the right hand pane is prevented is because that pane is only a preview of what the content would look like if you performed the "Replace" operation. Allowing the user to manually edit the content in that pane might cause them to lose data if they didn't realize that the data is only staged in memory and not actually the file on disk. It would also open up a can of worms regarding how to handle things like a save being done when that pane is selected and what to do if the user made different changes in each pane.