fixes to getTextPosition, replaceCodeBlock