Fix buffer overrun
Convert needed functions in text.c to use pure scintilla

Other minor tweaks