CodeMirror sometimes loads whitespace at the end of the inputbox in the source editor, which in turn causes the cursor to select text many lines above where is intended. This can be fixed by typing/deleting text anywhere in the inputbox.
This only seems to happen occasionally so it's difficult to reproduce. It did happen a few minutes ago for me in Safari Version 12.0 (14606.1.36.1.9) on MacOS 10.14. I can't actually replicate this for the task :) but perhaps others can.