* Not much

This commit is contained in:
Bryan Ashby 2015-05-31 21:50:49 -06:00
parent c8c7566fd3
commit 40f38d8682
2 changed files with 11 additions and 7 deletions

View File

@ -53,5 +53,5 @@ MultiLineEditTextView2.prototype.redraw = function() {
MultiLineEditTextView2.prototype.setText = function(text) { MultiLineEditTextView2.prototype.setText = function(text) {
this.textBuffer.insertText(0, text); this.textBuffer.insertText(0, text);
console.log(this.textBuffer.getArray()); console.log(this.textBuffer.getArray())
}; };

View File

@ -103,9 +103,12 @@ TextBuffer.prototype.insertFragment = function(index, fragment) {
throw new RangeError('Index must be >= 0'); throw new RangeError('Index must be >= 0');
} }
/*
if(index > this.length) { if(index > this.length) {
console.log(this.gapStart)
console.log(this.gapEnd)
throw new RangeError('Index must be <= length'); throw new RangeError('Index must be <= length');
} }*/
if(this.gapStart === this.gapEnd) { if(this.gapStart === this.gapEnd) {
this.spliceArgs[0] = index; this.spliceArgs[0] = index;
@ -137,7 +140,7 @@ TextBuffer.prototype.insertText = function(index, text) {
return; return;
} }
var re = /\s+|\r\n|\n|\r/g; var re = /\r\n|\n|\r|\t|\s+/g;
var m; var m;
var i = index; var i = index;
var from; var from;
@ -153,7 +156,7 @@ TextBuffer.prototype.insertText = function(index, text) {
switch(m[0].charAt(0)) { switch(m[0].charAt(0)) {
case '\t' : case '\t' :
for(var j = 0; j < m[0].length; ++j) { for(var j = 0; j < m[0].length; ++j) {
this.insertFragment(i++, new TextBuffer({ this.insertFragment(i++, new TextBuferFragment({
text : m[0].charAt(j) text : m[0].charAt(j)
})); }));
} }
@ -163,14 +166,14 @@ TextBuffer.prototype.insertText = function(index, text) {
case '\n' : case '\n' :
var count = m[0].split(/\r\n|\n|\r/g).length; var count = m[0].split(/\r\n|\n|\r/g).length;
for(var j = 0; j < count; ++j) { for(var j = 0; j < count; ++j) {
this.insertFragment(i++, new TextBuffer({ this.insertFragment(i++, new TextBuferFragment({
text : '\n' // always normalized text : '\n' // always normalized
})); }));
} }
break; break;
case ' ' : case ' ' :
this.insertFragment(i++, new TextBuffer({ this.insertFragment(i++, new TextBuferFragment({
text : m[0], text : m[0],
})); }));
break; break;
@ -179,6 +182,7 @@ TextBuffer.prototype.insertText = function(index, text) {
} while(0 !== re.lastIndex); } while(0 !== re.lastIndex);
}; };
// :TODO: getArray() should take range
TextBuffer.prototype.getArray = function() { TextBuffer.prototype.getArray = function() {
return this.buffer.slice(0, this.gapStart).concat(this.buffer.slice(this.gapEnd)); return this.buffer.slice(0, this.gapStart).concat(this.buffer.slice(this.gapEnd));
}; };