-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Highlighting for Blocks #4520
base: master
Are you sure you want to change the base?
Changes from all commits
bb116df
1966c45
fb38713
e4750cc
a2c07ab
0ad0e15
ee0de9d
c4ae734
1619c24
df3669b
cfada4e
ea3b111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ CodeMirror.defineMode('smalltalk', function(config) { | |
|
||
var specialChars = /[+\-\/\\*~<>=@%|&?!.,:;^]/; | ||
var keywords = /true|false|nil|self|super|thisContext/; | ||
var variables = /Smalltalk/; | ||
|
||
var Context = function(tokenizer, parent) { | ||
this.next = tokenizer; | ||
|
@@ -91,6 +92,7 @@ CodeMirror.defineMode('smalltalk', function(config) { | |
} else if (/[\w_]/.test(aChar)) { | ||
stream.eatWhile(/[\w\d_]/); | ||
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null; | ||
token.name = state.expectVariable ? (variables.test(stream.current()) ? 'variable-2' : 'variable') : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you assigning to the same property twice here? This effectively disables the previous statement, which doesn't look like it is right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably be better represented like, |
||
|
||
} else { | ||
token.eos = state.expectVariable; | ||
|
@@ -120,6 +122,17 @@ CodeMirror.defineMode('smalltalk', function(config) { | |
|
||
if (aChar === '|') { | ||
token.context = context.parent; | ||
var str = stream.string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could whatever you're trying to do here be expressed by matching a regexp on the stream at this point? Munging the whole line without regard for where in the line we currently are doesn't seem like a good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a JS developer by trade, but I am learning. I'll give the RegEx a shot. Basically I'm trying to find whether or not there are additional variables in a block, so [:var1 | |var2 var3| ...] |
||
var arr = str.split('|'); | ||
arr.length == 3 ? str = arr[1] : str = arr[2]; | ||
if(!str){ str = '' }; | ||
var arr2 = str.split(' '); | ||
for(var i=0;i<arr2.length;i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also please put spaces around operators.) |
||
var aVar = arr2[i].replace(/\s/g, ''); | ||
if(aVar.length != 0){ | ||
if(!variables.test(aVar)){ variables = new RegExp(variables.source + (new RegExp('|^'+aVar+'$').source))}; | ||
} | ||
} | ||
token.eos = true; | ||
|
||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use a mode-global variable to keep state -- modes can be restarted and resumed at different points at any time, and thus state should go into the state object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I'm in a lecture! heh. I will make a note of this and a) fix and b) not do it again!