Reorienting Thoughts Towards Virtuous Object
You might want to consult Vitakkasanthana Sutta: The Removal of Distracting Thoughts
https://www.accesstoinsight.org/tipitaka/mn/mn.020.soma.html

It explains how one deals with unwholesome thoughts in several ways and 'Reorienting Thoughts Towards Virtuous Object' is one of those ways.