Backport PR #4060: only strip continuation prompts if regular prompts seen first

should be discussed before merge (ping @takluyver), as it is a significant and sensitive change.

I'm also not sure that it's the right fix, but worth a try.

closes #4059