The heart-desire to be well-pleasing to the Lord is something God sees. I believe this is what David had and hence God’s declaration, despite many heinous shortcomings, that David was a man after His own heart (Psalms 32 and 51 are examples of why God thought this way of David).