Index: dart/site/try/src/interaction_manager.dart |
diff --git a/dart/site/try/src/interaction_manager.dart b/dart/site/try/src/interaction_manager.dart |
index 88986cc35024fe143562b74fc9f58fb2f86cf8c1..b2c22ddb9a5a392df31b2679322ce8f2a53c3e9a 100644 |
--- a/dart/site/try/src/interaction_manager.dart |
+++ b/dart/site/try/src/interaction_manager.dart |
@@ -243,7 +243,15 @@ class InitialState extends InteractionState { |
int offset = 0; |
List<Node> nodes = <Node>[]; |
- tokenizeAndHighlight(currentText, offset, trySelection, nodes); |
+ int lineNumber = 1; |
kasperl
2014/04/07 04:54:25
If you have to keep an index anyway, maybe it woul
ahe
2014/04/07 09:38:29
Variable not needed. Line numbers implemented usin
|
+ for (String line in currentText.split('\n')) { |
+ List<Node> lineNodes = <Node>[]; |
+ tokenizeAndHighlight(line, offset, trySelection, lineNodes); |
+ offset += line.length + 1; // + 1 for newline. |
+ nodes.add(new SpanElement() |
+ ..nodes.addAll(lineNodes) |
+ ..classes.add('lineNumber')); |
+ } |
mainEditorPane |
..nodes.clear() |
@@ -670,9 +678,10 @@ bool computeHasModifier(KeyboardEvent event) { |
} |
void tokenizeAndHighlight(String currentText, |
- int offset, |
+ int start, |
TrySelection trySelection, |
List<Node> nodes) { |
+ int offset = 0; |
// + offset + charOffset + globalOffset + (charOffset + charCount) |
// v v v v |
// do identifier_abcdefghijklmnopqrst |
@@ -688,17 +697,17 @@ void tokenizeAndHighlight(String currentText, |
if (decoration == null) continue; |
// Add a node for text before current token. |
- trySelection.addNodeFromSubstring(offset, charOffset, nodes); |
+ trySelection.addNodeFromSubstring(start + offset, start + charOffset, nodes); |
kasperl
2014/04/07 04:54:25
Long line.
ahe
2014/04/07 09:38:29
Done.
|
// Add a node for current token. |
trySelection.addNodeFromSubstring( |
- charOffset, charOffset + charCount, nodes, decoration); |
+ start + charOffset, start + charOffset + charCount, nodes, decoration); |
offset = charOffset + charCount; |
} |
// Add a node for anything after the last (decorated) token. |
- trySelection.addNodeFromSubstring(offset, currentText.length, nodes); |
+ trySelection.addNodeFromSubstring(start + offset, start + currentText.length, nodes); |
kasperl
2014/04/07 04:54:25
Long line.
ahe
2014/04/07 09:38:29
Done.
|
// Ensure text always ends with a newline. |
if (!currentText.endsWith('\n')) { |