class Line { public var chars; // needs to come from js, doesn't take html tags into account! public var words; public var forceBreak; public function Line() { this.words = []; this.chars = -1; this.forceBreak = false; } public function toString() { return this.words.join(' '); } public function push(word) { this.words.push(word); word.line = this; this.chars += 1 + word.chars; } public function pushAll(words) { for(var i = 0; i < words.length; i++) this.push(words[i]); } public function pop() { var word = this.words.pop(); this.chars -= 1 + word.chars; return word; } public function unshift(word) { this.words.unshift(word); word.line = this; this.chars += 1 + word.chars; } public function unshiftAll(words) { words.reverse(); // unshifting should happen in reverse order! for(var i = 0; i < words.length; i++) this.unshift(words[i]); } public function shift() { var word = this.words.shift(); this.chars -= 1 + word.chars; return word; } public function spliceEnd(ix) { var words = this.words.splice(ix); for(var i = 0; i < words.length; i++) this.chars -= 1 + words[i].chars; return words; } }