What happens in your case is that probably the configuration contains the option always_set_home which switches the home directory and thus the configuration to /root.
Solutions:
- You can use
sudoedit for this purpose, which will preserve your environment.
- You can check your sudo configuration using
sudo visudo and comment out the always_set_home option
- You can use
sudo -E gedit file to preserve the environment
I'm not aware of any security implications, but of course nasty things will happen if someone replaces the gedit configuration file with a symlink to a system file. But if you use sudo gedit it is assumed that you know what is going on on your system.