diff --git a/lib/TextBuffer.js b/lib/TextBuffer.js index d36f9ceb..ad3f3293 100644 --- a/lib/TextBuffer.js +++ b/lib/TextBuffer.js @@ -136,6 +136,29 @@ TextBuffer.prototype.getLineText = function( y = this.cy ) { +// TODOC +// Get spaces and tabs at the begining of the line +TextBuffer.prototype.getLineIndent = function( y = this.cy ) { + if ( y >= this.buffer.length ) { return null ; } + if ( ! this.buffer[ y ] ) { this.buffer[ y ] = [] ; } + + var indentStr = '' ; + + for ( let x = 0 , xmax = this.buffer[ y ].length ; x < xmax ; x ++ ) { + let char = this.buffer[ y ][ x ].char ; + if ( char === ' ' || char === '\t' ) { + indentStr += char ; + } + else { + break ; + } + } + + return indentStr ; +} ; + + + // TODOC // Count characters in this line, excluding fillers TextBuffer.prototype.getLineCharCount = function( y = this.cy ) { @@ -159,6 +182,40 @@ TextBuffer.prototype.getCellsCharCount = function( cells ) { +// TODOC +// Remove spaces and tabs at the end of the line +TextBuffer.prototype.removeTrailingSpaces = function( y = this.cy , x = null , dry = false ) { + if ( y >= this.buffer.length ) { return '' ; } + if ( ! this.buffer[ y ] ) { this.buffer[ y ] = [] ; } + + var deletedStr = '' , + x = x ?? this.buffer[ y ].length - 1 , + hasNL = this.buffer[ y ][ x ].char === '\n' ; + + if ( hasNL ) { + x -- ; + } + + for ( ; x >= 0 ; x -- ) { + let char = this.buffer[ y ][ x ].char ; + + if ( char === ' ' || char === '\t' ) { + deletedStr = char + deletedStr ; + } + else { + break ; + } + } + + if ( deletedStr && ! dry ) { + this.buffer[ y ].splice( x + 1 , deletedStr.length ) ; + } + + return deletedStr ; +} ; + + + // TODOC // Get the text, but separate before the cursor and after the cursor TextBuffer.prototype.getCursorSplittedText = function() {