Skip to content

Commit

Permalink
[run-mode addon] Add hideFirstChars to stand-alone shims
Browse files Browse the repository at this point in the history
Issue #2054
  • Loading branch information
marijnh committed Dec 18, 2013
1 parent 2f266c3 commit d13582f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions addon/runmode/runmode-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function splitLines(string){ return string.split(/\r?\n|\r/); };
function StringStream(string) {
this.pos = this.start = 0;
this.string = string;
this.lineStart = 0;
}
StringStream.prototype = {
eol: function() {return this.pos >= this.string.length;},
Expand Down Expand Up @@ -41,7 +42,7 @@ StringStream.prototype = {
if (found > -1) {this.pos = found; return true;}
},
backUp: function(n) {this.pos -= n;},
column: function() {return this.start;},
column: function() {return this.start - this.lineStart;},
indentation: function() {return 0;},
match: function(pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
Expand All @@ -58,7 +59,12 @@ StringStream.prototype = {
return match;
}
},
current: function(){return this.string.slice(this.start, this.pos);}
current: function(){return this.string.slice(this.start, this.pos);},
hideFirstChars: function(n, inner) {
this.lineStart += n;
try { return inner(); }
finally { this.lineStart -= n; }
}
};
CodeMirror.StringStream = StringStream;

Expand Down
10 changes: 8 additions & 2 deletions addon/runmode/runmode.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function splitLines(string){ return string.split(/\r?\n|\r/); };
function StringStream(string) {
this.pos = this.start = 0;
this.string = string;
this.lineStart = 0;
}
StringStream.prototype = {
eol: function() {return this.pos >= this.string.length;},
Expand Down Expand Up @@ -36,7 +37,7 @@ StringStream.prototype = {
if (found > -1) {this.pos = found; return true;}
},
backUp: function(n) {this.pos -= n;},
column: function() {return this.start;},
column: function() {return this.start - this.lineStart;},
indentation: function() {return 0;},
match: function(pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
Expand All @@ -53,7 +54,12 @@ StringStream.prototype = {
return match;
}
},
current: function(){return this.string.slice(this.start, this.pos);}
current: function(){return this.string.slice(this.start, this.pos);},
hideFirstChars: function(n, inner) {
this.lineStart += n;
try { return inner(); }
finally { this.lineStart -= n; }
}
};
exports.StringStream = StringStream;

Expand Down

0 comments on commit d13582f

Please sign in to comment.