Handwritten text lines are prominent structures in freeform digital ink notes and their reliable detection is the foundation to a natural and intelligent interface for note editing and repurposing. This paper presents an optimization method for text line grouping. The global cost function is designed to find the simplest stroke partitioning to maximize the likelihood of the resulting lines and the consistency of their configuration. A dynamic programming algorithm provides an initial segmentation of the time-ordered stroke sequence. Then a local gradient-descent algorithm iteratively evaluates splitting and merging hypotheses to minimize the global cost function. On average, the proposed technique processes each note page in less than a second at a 90% accuracy.