Skip to content

Commit d13582f

Browse files
committed
[run-mode addon] Add hideFirstChars to stand-alone shims
Issue #2054
1 parent 2f266c3 commit d13582f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

addon/runmode/runmode-standalone.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function splitLines(string){ return string.split(/\r?\n|\r/); };
1010
function StringStream(string) {
1111
this.pos = this.start = 0;
1212
this.string = string;
13+
this.lineStart = 0;
1314
}
1415
StringStream.prototype = {
1516
eol: function() {return this.pos >= this.string.length;},
@@ -41,7 +42,7 @@ StringStream.prototype = {
4142
if (found > -1) {this.pos = found; return true;}
4243
},
4344
backUp: function(n) {this.pos -= n;},
44-
column: function() {return this.start;},
45+
column: function() {return this.start - this.lineStart;},
4546
indentation: function() {return 0;},
4647
match: function(pattern, consume, caseInsensitive) {
4748
if (typeof pattern == "string") {
@@ -58,7 +59,12 @@ StringStream.prototype = {
5859
return match;
5960
}
6061
},
61-
current: function(){return this.string.slice(this.start, this.pos);}
62+
current: function(){return this.string.slice(this.start, this.pos);},
63+
hideFirstChars: function(n, inner) {
64+
this.lineStart += n;
65+
try { return inner(); }
66+
finally { this.lineStart -= n; }
67+
}
6268
};
6369
CodeMirror.StringStream = StringStream;
6470

addon/runmode/runmode.node.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function splitLines(string){ return string.split(/\r?\n|\r/); };
55
function StringStream(string) {
66
this.pos = this.start = 0;
77
this.string = string;
8+
this.lineStart = 0;
89
}
910
StringStream.prototype = {
1011
eol: function() {return this.pos >= this.string.length;},
@@ -36,7 +37,7 @@ StringStream.prototype = {
3637
if (found > -1) {this.pos = found; return true;}
3738
},
3839
backUp: function(n) {this.pos -= n;},
39-
column: function() {return this.start;},
40+
column: function() {return this.start - this.lineStart;},
4041
indentation: function() {return 0;},
4142
match: function(pattern, consume, caseInsensitive) {
4243
if (typeof pattern == "string") {
@@ -53,7 +54,12 @@ StringStream.prototype = {
5354
return match;
5455
}
5556
},
56-
current: function(){return this.string.slice(this.start, this.pos);}
57+
current: function(){return this.string.slice(this.start, this.pos);},
58+
hideFirstChars: function(n, inner) {
59+
this.lineStart += n;
60+
try { return inner(); }
61+
finally { this.lineStart -= n; }
62+
}
5763
};
5864
exports.StringStream = StringStream;
5965

0 commit comments

Comments
 (0)