How do I know how to implement the binding function of the text line in the editor

My project has the function of comments, which is currently bound to the text line. However, if the corresponding relationship between comments and lines is confused after deleting some text, I want to know that there is no better way