How does a File System handle an internal edit to a file?
Filesystems typically don't handle internal edits to files as you describe them.  When you edit a program file, a text editor will pull the whole file into memory, allow you to make modifications to a buffer and then write the whole thing back out to disk.  Actual file I/O operations are usually quite limited by the operating system, e.g. overwrite existing file contents, truncate the file to a smaller size discarding what's beyond EOF, and appending to the file.

Text editors manage the business of allowing arbitrary insertion and deletion of lines and blocks of text.  These programs use an assortment of data structures, from arrays of lines to gap buffers to more elaborate structures, depending on the editor.  An old Blogspot article describes how a few popular text editors work internally; I commend you to it and to the source code of the many open-source text editors available if you wish to learn more.