change enter behavior in tabby plugin

change enter behavior in tabby plugin

Hi,
I am new to js and jquery. Usually I try to learn things by fullfilling a certain task and read the docs/manuals as much as possible to do so.
Currently, I try to get a textarea element to behave a little more like a desktop text editor.
It should be able to write a tab in the textarea when pressing tab and when pressing enter it should be able to intend the cursor in the new line if the current line is intendend.

I found the the plugin "tabby" which works fine with TAB and SHIFT+TAB. For the behavior of enter I currently try to modify the tabby plugin but somehow Im not getting to the point after enter was pressed.
So far, it counts the tabs at the beginning of the line where enter is pressed...and since then I try to find point where to proceed with either writing the new line and the tabs and prevent the default behavior of enter or let the default enter behavior happen and write the counted tabs to the new line after enter was pressed

I hope you could help me out here, maybe I missed something while reading the basics or its to advanced, I don't know, but Im stuck. :-)
To make myself more clear I will add the code of the tabby plugin Im modifing, shortend and commented. This should give you the most precise idea of what Im trying to do.

Thanks in advance...

  1. (function($) {
  2.       $.fn.tabby = function(options) {
  3.             var opts = $.extend({}, $.fn.tabby.defaults, options);
  4.             var pressed = $.fn.tabby.pressed; 
  5.        return this.each(function() {
  6.             $this = $(this);
  7.             var options = $.meta ? $.extend({}, opts, $this.data()) : opts;
  8.              var enter = false;
  9.              var intends = 0;
  10.        $this.bind('keydown',function (e) {
  11.              var kc = $.fn.tabby.catch_kc(e);

  12.              if (16 == kc) pressed.shft = true;
  13.              if (17 == kc) {/*...*/}
  14.              if (18 == kc) { /*...*/ }
  15.              if (9 == kc && !pressed.ctrl && !pressed.alt) {/*...*/}
  16.              //enter
  17.              if (13 == kc) {
  18.                    //passes a HTMLTextAreaElement object
  19.                    intends = process_enter ($(e.target).get(0));
  20.                    /*
  21.                    returns the number of intends, now my problem:
  22.                    I assume that I need to write the conuted tabs
  23.                    in the new line right after the keydown event 
  24.                    when the cursor set to the new line
  25.                    ...but where???
  26.                    */
  27.              }
  28.              }).bind('keyup',function (e) {/*...*/
  29.              }).bind('blur',function (e) {/*...*/
  30.              });
  31.        });
  32. };

  33. $.fn.tabby.catch_kc = function(e) { /*...*/ };
  34. $.fn.tabby.pressed = {/*...*/};
  35. function debug($obj) { /*...*/};

  36. function process_enter (o) {
  37.        /*
  38.        counts the tabs at the bginning of the line
  39.        */
  40. };
  41. function process_keypress (o,shft,options) {/*...*/}}
  42. // plugin defaults
  43. $.fn.tabby.defaults = {tabString : String.fromCharCode(9)};
  44. function gecko_tab (o, shft, options) {/*...*/}
  45. function ie_tab (o, shft, options) {/*...*/}

  46. })(jQuery);

I hope it's explained enough and understandable. 
Please let me know if not!

Cheers,
anyrandomusername