Open RobertMcCoy opened 6 years ago
Currently this code is doing a lot of character checking. This should probably be setup to find the first point of change and last point in change in the code from the previous version to the latest version, and if the users cursor is ahead of that point just increment it by the amount of characters changed (to cover pasting and single character movements). Otherwise shift the caret to the end or the beginning if it is in that range. If none of these conditions are met, it was added after the change and the user doesn't need to have their caret moved anywhere except the previous position it was in (cursorPosition for start/end in this case).
Currently this is a very hacky workaround that can break easily, specifically on same-caret modifications and large text modification (full line deletes, pasting, etc.). This entire code should probably be converted over to something else that is easier to keep a cursor in the same location across edits (maybe there is a node package that can help with this?).