@@ -673,6 +673,13 @@ exports.textLinesMutator = function (lines) {
673673 inSplice = false ;
674674 }
675675
676+ /**
677+ * Indicates if curLine is already in the splice. This is necessary because the last element
678+ * in curSplice is curLine when this line is currently worked on (e.g. when skipping are inserting)
679+ *
680+ * TODO(doc) why aren't removals considered?
681+ * @returns {Boolean } true if curLine is in splice
682+ */
676683 function isCurLineInSplice ( ) {
677684 return ( curLine - curSplice [ 0 ] < ( curSplice . length - 2 ) ) ;
678685 }
@@ -681,20 +688,32 @@ exports.textLinesMutator = function (lines) {
681688 print ( typ + ": " + curSplice . toSource ( ) + " / " + curLine + "," + curCol + " / " + lines_toSource ( ) ) ;
682689 }
683690
691+ /**
692+ * Incorporates current line into the splice
693+ * and marks its old position to be deleted.
694+ *
695+ * @returns {Number } the index of the added line in curSplice
696+ */
684697 function putCurLineInSplice ( ) {
685698 if ( ! isCurLineInSplice ( ) ) {
686699 curSplice . push ( lines_get ( curSplice [ 0 ] + curSplice [ 1 ] ) ) ;
687700 curSplice [ 1 ] ++ ;
688701 }
689- return 2 + curLine - curSplice [ 0 ] ;
702+ return 2 + curLine - curSplice [ 0 ] ; // TODO should be the same as curSplice.length - 1
690703 }
691704
705+ /**
706+ * It will skip some newlines by putting them into the splice.
707+ *
708+ * @param {Boolean } includeInSplice indicates if attributes are present
709+ */
692710 function skipLines ( L , includeInSplice ) {
693711 if ( L ) {
694712 if ( includeInSplice ) {
695713 if ( ! inSplice ) {
696714 enterSplice ( ) ;
697715 }
716+ // TODO(doc) should this count the number of characters that are skipped to check?
698717 for ( var i = 0 ; i < L ; i ++ ) {
699718 curCol = 0 ;
700719 putCurLineInSplice ( ) ;
@@ -703,6 +722,7 @@ exports.textLinesMutator = function (lines) {
703722 } else {
704723 if ( inSplice ) {
705724 if ( L > 1 ) {
725+ // TODO(doc) figure out why single lines are incorporated into splice instead of ignored
706726 leaveSplice ( ) ;
707727 } else {
708728 putCurLineInSplice ( ) ;
@@ -721,6 +741,13 @@ exports.textLinesMutator = function (lines) {
721741 //debugPrint("skip");
722742 }
723743
744+ /**
745+ * Skip some characters. Can contain newlines.
746+ *
747+ * @param {Number } N number of characters to skip
748+ * @param {Number } L number of newlines to skip
749+ * @param {Boolean } includeInSplice indicates if attributes are present
750+ */
724751 function skip ( N , L , includeInSplice ) {
725752 if ( N ) {
726753 if ( L ) {
@@ -730,6 +757,8 @@ exports.textLinesMutator = function (lines) {
730757 enterSplice ( ) ;
731758 }
732759 if ( inSplice ) {
760+ // although the line is put into splice curLine is not increased, because
761+ // only some chars are skipped, not the whole line
733762 putCurLineInSplice ( ) ;
734763 }
735764 curCol += N ;
@@ -738,13 +767,24 @@ exports.textLinesMutator = function (lines) {
738767 }
739768 }
740769
770+ /**
771+ * Remove whole lines from lines array
772+ *
773+ * @param {Number } L number of lines to be removed
774+ */
741775 function removeLines ( L ) {
742776 var removed = '' ;
743777 if ( L ) {
744778 if ( ! inSplice ) {
745779 enterSplice ( ) ;
746780 }
747781
782+ /**
783+ * Gets a string of joined lines after the end of the splice
784+ *
785+ * @param k {Number} number of lines
786+ * @returns {String } joined lines
787+ */
748788 function nextKLinesText ( k ) {
749789 var m = curSplice [ 0 ] + curSplice [ 1 ] ;
750790 return lines_slice ( m , m + k ) . join ( '' ) ;
@@ -774,6 +814,12 @@ exports.textLinesMutator = function (lines) {
774814 return removed ;
775815 }
776816
817+ /**
818+ * Remove text from lines array
819+ *
820+ * @param N {Number} characters to delete
821+ * @param L {Number} lines to delete
822+ */
777823 function remove ( N , L ) {
778824 var removed = '' ;
779825 if ( N ) {
@@ -783,6 +829,8 @@ exports.textLinesMutator = function (lines) {
783829 if ( ! inSplice ) {
784830 enterSplice ( ) ;
785831 }
832+ // although the line is put into splice, curLine is not increased, because
833+ // only some chars are removed not the whole line
786834 var sline = putCurLineInSplice ( ) ;
787835 removed = curSplice [ sline ] . substring ( curCol , curCol + N ) ;
788836 curSplice [ sline ] = curSplice [ sline ] . substring ( 0 , curCol ) + curSplice [ sline ] . substring ( curCol + N ) ;
@@ -792,6 +840,12 @@ exports.textLinesMutator = function (lines) {
792840 return removed ;
793841 }
794842
843+ /**
844+ * Inserts text into lines array.
845+ *
846+ * @param text {String} the text to insert
847+ * @param L {Number} number of newlines in text
848+ */
795849 function insert ( text , L ) {
796850 if ( text ) {
797851 if ( ! inSplice ) {
@@ -831,6 +885,12 @@ exports.textLinesMutator = function (lines) {
831885 }
832886 }
833887
888+ /**
889+ * Checks if curLine (the line we are in when curSplice is applied) is the last line
890+ * in lines.
891+ *
892+ * @return {Boolean } indicates if there are lines left
893+ */
834894 function hasMore ( ) {
835895 //print(lines.length+" / "+inSplice+" / "+(curSplice.length - 2)+" / "+curSplice[1]);
836896 var docLines = lines_length ( ) ;
@@ -840,6 +900,9 @@ exports.textLinesMutator = function (lines) {
840900 return curLine < docLines ;
841901 }
842902
903+ /**
904+ * Closes the splice
905+ */
843906 function close ( ) {
844907 if ( inSplice ) {
845908 leaveSplice ( ) ;
0 commit comments