Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library trydart.interaction_manager; | 5 library trydart.interaction_manager; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'dart:convert' show | 9 import 'dart:convert' show |
| 10 JSON; | 10 JSON; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 trySelection.updateText(currentText); | 236 trySelection.updateText(currentText); |
| 237 | 237 |
| 238 context.currentCompilationUnit.content = currentText; | 238 context.currentCompilationUnit.content = currentText; |
| 239 | 239 |
| 240 editor.seenIdentifiers = new Set<String>.from(mock.identifiers); | 240 editor.seenIdentifiers = new Set<String>.from(mock.identifiers); |
| 241 | 241 |
| 242 editor.isMalformedInput = false; | 242 editor.isMalformedInput = false; |
| 243 int offset = 0; | 243 int offset = 0; |
| 244 List<Node> nodes = <Node>[]; | 244 List<Node> nodes = <Node>[]; |
| 245 | 245 |
| 246 tokenizeAndHighlight(currentText, offset, trySelection, nodes); | 246 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
| |
| 247 for (String line in currentText.split('\n')) { | |
| 248 List<Node> lineNodes = <Node>[]; | |
| 249 tokenizeAndHighlight(line, offset, trySelection, lineNodes); | |
| 250 offset += line.length + 1; // + 1 for newline. | |
| 251 nodes.add(new SpanElement() | |
| 252 ..nodes.addAll(lineNodes) | |
| 253 ..classes.add('lineNumber')); | |
| 254 } | |
| 247 | 255 |
| 248 mainEditorPane | 256 mainEditorPane |
| 249 ..nodes.clear() | 257 ..nodes.clear() |
| 250 ..nodes.addAll(nodes); | 258 ..nodes.addAll(nodes); |
| 251 trySelection.adjust(selection); | 259 trySelection.adjust(selection); |
| 252 | 260 |
| 253 // Discard highlighting mutations. | 261 // Discard highlighting mutations. |
| 254 observer.takeRecords(); | 262 observer.takeRecords(); |
| 255 } | 263 } |
| 256 | 264 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 event.getModifierState("NumLock") || | 671 event.getModifierState("NumLock") || |
| 664 event.getModifierState("ScrollLock") || | 672 event.getModifierState("ScrollLock") || |
| 665 event.getModifierState("Scroll") || | 673 event.getModifierState("Scroll") || |
| 666 event.getModifierState("Win") || | 674 event.getModifierState("Win") || |
| 667 event.getModifierState("Shift") || | 675 event.getModifierState("Shift") || |
| 668 event.getModifierState("SymbolLock") || | 676 event.getModifierState("SymbolLock") || |
| 669 event.getModifierState("OS"); | 677 event.getModifierState("OS"); |
| 670 } | 678 } |
| 671 | 679 |
| 672 void tokenizeAndHighlight(String currentText, | 680 void tokenizeAndHighlight(String currentText, |
| 673 int offset, | 681 int start, |
| 674 TrySelection trySelection, | 682 TrySelection trySelection, |
| 675 List<Node> nodes) { | 683 List<Node> nodes) { |
| 684 int offset = 0; | |
| 676 // + offset + charOffset + globalOffset + (charOffset + charCount) | 685 // + offset + charOffset + globalOffset + (charOffset + charCount) |
| 677 // v v v v | 686 // v v v v |
| 678 // do identifier_abcdefghijklmnopqrst | 687 // do identifier_abcdefghijklmnopqrst |
| 679 for (Token token = tokenize(currentText); | 688 for (Token token = tokenize(currentText); |
| 680 token.kind != EOF_TOKEN; | 689 token.kind != EOF_TOKEN; |
| 681 token = token.next) { | 690 token = token.next) { |
| 682 int charOffset = token.charOffset; | 691 int charOffset = token.charOffset; |
| 683 int charCount = token.charCount; | 692 int charCount = token.charCount; |
| 684 | 693 |
| 685 if (charOffset < offset) continue; // Happens for scanner errors. | 694 if (charOffset < offset) continue; // Happens for scanner errors. |
| 686 | 695 |
| 687 Decoration decoration = editor.getDecoration(token); | 696 Decoration decoration = editor.getDecoration(token); |
| 688 if (decoration == null) continue; | 697 if (decoration == null) continue; |
| 689 | 698 |
| 690 // Add a node for text before current token. | 699 // Add a node for text before current token. |
| 691 trySelection.addNodeFromSubstring(offset, charOffset, nodes); | 700 trySelection.addNodeFromSubstring(start + offset, start + charOffset, nodes) ; |
|
kasperl
2014/04/07 04:54:25
Long line.
ahe
2014/04/07 09:38:29
Done.
| |
| 692 | 701 |
| 693 // Add a node for current token. | 702 // Add a node for current token. |
| 694 trySelection.addNodeFromSubstring( | 703 trySelection.addNodeFromSubstring( |
| 695 charOffset, charOffset + charCount, nodes, decoration); | 704 start + charOffset, start + charOffset + charCount, nodes, decoration); |
| 696 | 705 |
| 697 offset = charOffset + charCount; | 706 offset = charOffset + charCount; |
| 698 } | 707 } |
| 699 | 708 |
| 700 // Add a node for anything after the last (decorated) token. | 709 // Add a node for anything after the last (decorated) token. |
| 701 trySelection.addNodeFromSubstring(offset, currentText.length, nodes); | 710 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.
| |
| 702 | 711 |
| 703 // Ensure text always ends with a newline. | 712 // Ensure text always ends with a newline. |
| 704 if (!currentText.endsWith('\n')) { | 713 if (!currentText.endsWith('\n')) { |
| 705 nodes.add(new Text('\n')); | 714 nodes.add(new Text('\n')); |
| 706 } | 715 } |
| 707 } | 716 } |
| 708 | 717 |
| 709 void normalizeMutationRecord(MutationRecord record, TrySelection selection) { | 718 void normalizeMutationRecord(MutationRecord record, TrySelection selection) { |
| 710 if (record.addedNodes.isEmpty) return; | 719 if (record.addedNodes.isEmpty) return; |
| 711 for (Node node in record.addedNodes) { | 720 for (Node node in record.addedNodes) { |
| 712 if (node.parent == null) continue; | 721 if (node.parent == null) continue; |
| 713 StringBuffer buffer = new StringBuffer(); | 722 StringBuffer buffer = new StringBuffer(); |
| 714 int selectionOffset = htmlToText(node, buffer, selection); | 723 int selectionOffset = htmlToText(node, buffer, selection); |
| 715 Text newNode = new Text('$buffer'); | 724 Text newNode = new Text('$buffer'); |
| 716 node.replaceWith(newNode); | 725 node.replaceWith(newNode); |
| 717 if (selectionOffset != -1) { | 726 if (selectionOffset != -1) { |
| 718 selection.anchorNode = newNode; | 727 selection.anchorNode = newNode; |
| 719 selection.anchorOffset = selectionOffset; | 728 selection.anchorOffset = selectionOffset; |
| 720 } | 729 } |
| 721 } | 730 } |
| 722 } | 731 } |
| OLD | NEW |