Rewrite text extraction algorithm to fix inconsistencies when typing from candidate window.