Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cronvel committed Sep 12, 2022
1 parent 250e6bf commit 9fa2a26
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/TextBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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() {
Expand Down

0 comments on commit 9fa2a26

Please sign in to comment.