Hi Yew Hong,
The file you are looking for would probably be lib/weblib.php, look for function print_textarea
you may also want to look at lib/javascript.php and lib/editorlib.php
should be easy to make it work superficially with moodle, but to get the complete power would need quite a bit of effort. Do let the community share your success?