IDE Error: "Cannot edit this file:

I was programming in IDE 2.2.1 using the RP Pico board...which works nicely. (Thanks for letting me use C instead of MicroPython.) I'm running the IDE on a Win 11 machine using an Intel I9.

Without realizing it, I opened my IDE which was evidently shut down the night before with the Search-Replace option open. The Replace field was empty, but open. I used F12 to locate a specific function and noticed how the Source Window divided in half and a duplicate of the source appeared in the right-hand half of the Source Window. I then realized I had the Replace option active, so I used the left-hand Search panel to close the Replace textbox. I then tried to edit some code in the function shown in the Source Window and got the "Cannot Edit This File" error dialog above the line I was trying to edit. I tried different things, but nothing allowed me the edit the file.

I then had a "Flat Forehead" moment: You know, those moment when you slap yourself in the forehead and ask how you could be so stupid.

I looked at the tabs and realized that I had two new duplicate tabs for the original source file.

Solution: For me, I started with the right-most tab of the duplicate file tabs and X-ed them closed, figuring the most-recent tabs would be at the end of the tab list. After their deletion, I was then able to edit the "original" source file in the IDE.

This is the expected behavior of the editor.action.revealDefinitionAside command. The default keyboard shortcut for that is Ctrl+K Ctrl+F12. So you shouldn't get this behavior from an F12 keystroke alone unless you customized the keyboard shortcut for the editor.action.revealDefinitionAside command. Did you change that shortcut to F12?

There is an alternative shortcut for the editor.action.revealDefinitionAside command, which is Ctrl+K+<left mouse button click>.

Is it possible you accidentally did a Ctrl+K Ctrl+F12 or Ctrl+K+<left mouse button click> when this happened?

Was the message "Cannot edit in read-only editor"?

Arduino IDE only allows you to edit files that are inside the folder of the currently opened sketch. This is done to prevent users from editing the external code of libraries, cores, or toolchains in the files they access via the IDE's "Go to Definition" feature. If the user makes such edits either accidentally or without realizing the edit will affect all sketches globally rather than only the specific sketch they have open at the time, this could lead to very confusing problems that might be difficult to troubleshoot and support.

So it is normal for this message to appear if you are attempting to edit a file that is located outside the sketch folder. But it is not expected for it to appear if the file is inside the sketch folder.

Were both tabs in the same editor panel, or was one in the left panel and the other in the right panel of the split editor? If the latter, having the same file open in two panels is a fairly common use pattern. It can be useful when you want to be able to refer to content elsewhere in the file without having to scroll back and forth between the content and the place where you are editing in a single panel.

As for multiple tabs for the same file in the same panel, that would be a bug. Historically, Arduino IDE 2.x has been plagued by the appearance of duplicate sketch tabs in the same editor panel under certain conditions. You can see some examples of that in this issue and the issues linked off of it. However, almost every one of the bugs that produced that symptom have been fixed as of Arduino IDE 2.1.0. I'm only aware of one remaining bug that produces this symptom:

Is it possible you changed the name of the sketch file that produced the duplicate tab?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.