This might be solved for all comint-derived modes in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62958