Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1706)

Unified Diff: dart/site/try/src/interaction_manager.dart

Issue 225903003: Tokenize one line at a time. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/site/try/index.html ('k') | dart/site/try/src/ui.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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')) {
« no previous file with comments | « dart/site/try/index.html ('k') | dart/site/try/src/ui.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698