The Idea in Brief
The comments of Rabbi Shlomo Yitzchaki ("Rashi"), Jewish aggadic midrash (Qohelet Rabbah), the Targum Qohelet (Aramaic translation of the Hebrew Bible), and the structure of the Masoretic Text provide the picture of how Jewish scholars over the millennia had viewed the current passage at hand.
That is, Solomon immersed himself in the pleasures of his flesh while at one and the same time he immersed himself in the study of divine revelation. The result was that he came to view divine revelation as folly.
In other words, Solomon had relied on his own wisdom, which was profound. He therefore assumed that obedience to the mandates of divine revelation was optional, and so he immersed himself in the pleasures of his flesh. So from his perspective, the wisdom of divine revelation appeared to him as folly -- that is, his earthly wisdom had eclipsed heavenly wisdom, which was foolishness to him.
In summary, one cannot undertake the serious study of divine revelation without the purity of the obedient heart and body; otherwise the wisdom found Scripture will appear as foolishness.
Discussion
The following comments below are from Rabbi Shlomo Yitzchaki ("Rashi"), Jewish aggadic midrash (Qohelet Rabbah), the Targum Qohelet (Aramaic translation of the Hebrew Bible), and the structure of the Masoretic Text. Each in turn will provide the picture of how Jewish scholars over the millennia had viewed the current passage at hand.
Comments of Rashi
Rabbi Shlomo Yitzchaki ("Rashi") lived in 11th Century France. His comments have enabled scholars since to understand not only the Hebrew Scriptures but also Jewish oral tradition as codified in the Talmud. (His writings appear in the margins of modern editions of the Talmud alongside the Gemarah and Tosefta.) Ravi indicates that according to the passage at hand, Solomon immersed himself in the pleasures of his flesh while at one and the same time he immersed himself in the study of divine revelation. His comments in late Aramaic appear in the Chabad translations below.
ולבי נוהג בחכמה. - Even if my body is being indulged with wine, my heart is being conducted with wisdom, to hold on to Torah.
Ravi then continues. He compares King Solomon to King Saul, who viewed the commandments of divine revelation as foolishness. That is, there are specific commandments in Scripture relating to purity of heart and body.
ולאחוז בסכלות . - to things that appear to me as folly, concerning which I said, (Prov. 30:1): “God is with me; yea, God is with me, and I will be able,” for example, the wearing of shaatnez and mingled species in a vineyard, which Satan and the nations of the world dispute, and so he says (below 7:18): “It is good that you should take hold of this,” and also, concerning Saul, to whom it appeared folly to slay both man and woman, both infant and suckling, but it was the commandment of the Omnipresent, and he called it folly.
The commandments of separation and purity (shaatnez and mingled species in a vineyard) come from Lev 19:19 and Deut 22:9–11, and Ravi indicates that such commandments appear as foolishness to Satan and the nations of the world. In this regard, Ravi mentions King Saul, who considered the divine revelation from the Prophet Samuel as folly, and therefore he spared King Agag and the Amalekite spoils from destruction (1 Sam 15:1-11), which cost King Saul both his throne and legacy. Like King Saul, King Solomon also ignored the purity of heart and body for approaching divine revelation, which then appears as folly.
Aggadic Midrash (Qoholet Rabbah)
The Qoholet Rabbah is the non-legalistic exegetical commentary on the Book of Ecclesiastes. These commentaries capture the rabbinic interpretations of the Hebrew Bible. The following citation appears as follows.
Please click the image to enlarge (at its source page at Sefaria.org).

Proposed Tentative Translation
Qoholet Rabbah 2:3
“I endeavored with my heart to entertain in wine...”
Comment - Solomon said: I endeavored with my heart to delight in wine, to delight in the wine of Torah.
“...my body, and with my heart conducting in wisdom...”
Comment - ...in the wisdom of Torah.
“...to take hold of folly...”
Comment - Rabbi Juden presents the case before Rabbi Achad: What is this what is written “to take hold of folly (בסכלות)”? He answered him: “to take hold of scholasticism.” (בסכלנות)
The midrash here suggests that Solomon “ingested” the wine of the wisdom of divine revelation, notwithstanding the reference was to folly. In other words, consistent with Rashi's observations, Solomon immersed himself in wine and in the study of divine revelation, which, to him, was folly.
Targum Qohelet
The Targumim are the Jewish translation of the Hebrew Scriptures into Aramaic. They were spoken paraphrases, explanations and expansions of the Jewish scriptures that a Rabbi would give in the common language of the listeners, which during the time of this practice was commonly, but not exclusively, Aramaic. In this respect, the translation provides nuanced meaning based on the understanding of the Hebrew Scriptures by Jewish scholars at the time of translation. For example, the following are the relevant verses from the Targum Qohelet from the Comprehensive Aramaic Lexicon Project (2005).
Please click to enlarge.

Proposed Tentative Translation
Ecclesiastes 2:3
3 I searched with my heart to draw my flesh into the house of wine-drinking, and my heart persevered in wisdom; and to embrace the stupidity of youth until I examined and saw if whether the stupidity (lit., that from them) was good for the sons of men, who pass time while they are alive in this world under the heavens the number of days of their lives.
As both Rashi and the Qohelet Rabbah had indicated, Solomon's pursuit of fleshly indulgence and his pursuit of wisdom occur at the same time. However, this Targum defines the folly (stupidity) through the excesses of youth rather than any study of Scripture. In other words, the Targum Qohelet acknowledges Solomon's pursuit of wisdom, but the folly here concerns the unambiguous reference to the foolish excesses of youth.
One more Jewish voice will provide the final perspective to this passage.
Masoretic Text
The Masoretic Text presents the Hebrew Scriptures not only with a system of vowel points, but also with a system of cantillation marks (based on the vowel points). The cantillation marks appear in hierarchical order: the disjunctive accents appear in descending order, and these connect one to another through the conjunctive accents. So, while conjunctive accents appear in the texts, it is the disjunctive accents cause the divisions between phrases within the same verse. This disjunctive accents (connected with conjunctive accents) break the verse into logical hierarchical order. In this regard the 19th Century British Hebraist Dr. William Wickes made the following two observations.
Please click to enlarge

The cantillation marks (accents) provided not only musical guidance, but also the logical breakdown of the verse. In other words, the cantillation marks were not referenced to grammar, but referenced to musical intonation based on the logical divisions of the verses. That is, according to Wickes, this "logic" had preexisted the Masoretic system (of writing the vowel, cantillation and accent marks). That is, the Masoretes only reduced to writing what was already there, which was oral tradition until the time the Masoretes reduced the system (of writing the vowel, cantillation and accent marks). Wickes makes the second observation as follows.
Please click to enlarge

The system of cantillation marks therefore provides not the grammatical, but the musical, and therefore logical, parsing of each verse of the Hebrew Scriptures. In this regard, Bible Software Tools provide us the musical parsing of the following verse, which presents its logical structure.
The following diagram best "explains" what Wickes was describing regarding the divisions and logical structure of the verses of Hebrew Scripture.
Please click to enlarge

PLEASE NOTE THE MAJOR DIVISION OF THE VERSE AT THE BLUE DASHED LINE
This schematic diagram depicts what Wickes was describing: the logical parsing of the verse through cantillation marks, which are driven by the vowels.
In other words, the contribution of the Masoretes was not only in assigning the vowels to the Hebrew Scriptures, but assigning the logical structure of the verses through the system of cantillation and accents based on the vowels. As noted by Wickes, the Masoretes appeared to have captured in writing what was already (by that time) oral tradition -- that is, the Hebrew Scriptures were "sung" according to the oral traditions, and the Masoretes merely captured and codified what was oral tradition.
As noted by Rashi and others in this discussion, the structure of the Masoretic Text appears consistent in this regard. That is, Solomon had complemented his pursuit of carnal pleasures with the "folly" of his pursuit of the wisdom of divine revelation.
Conclusion
What does the author of Ecclesiastes Chapter 2 mean that 'his heart was still guided with wisdom' as he went about doing foolish things?
Answer: As Solomon pursued his fleshly desires, he fathomed divine revelation, and so 'his heart was still guided with wisdom.' However, that wisdom of divine revelation became folly to him, because of his immersion in fleshly pursuits.
In other words, one cannot fathom the wisdom of divine revelation without the purity of the obedient heart and body; that is, without such purity (or repentance), the wisdom found in Scripture will appear as mere foolishness to the seeking heart.
Reference:
Wickes, William (1887). Two Treatises on the Accentuation of the Old Testament. Oxford: Clarendon Press, 2-3 (Vol I) and 29–30 (Vol II).