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

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

Issue 261413002: Use ShadowRoot to hide non-user content (for example, diagnostics). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Kasper's comments. Created 6 years, 7 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/src/html_to_text.dart ('k') | dart/site/try/src/shadow_root.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 277b2a813d9e6905b2389661eeea99a566b51edc..970a60f64e84fd134d426901a174f22b5a2076a3 100644
--- a/dart/site/try/src/interaction_manager.dart
+++ b/dart/site/try/src/interaction_manager.dart
@@ -64,6 +64,11 @@ import 'mock.dart' as mock;
import 'settings.dart' as settings;
+import 'shadow_root.dart' show
+ getShadowRoot,
+ removeShadowRootPolyfill,
+ setShadowRoot;
+
const String TRY_DART_NEW_DEFECT =
'https://code.google.com/p/dart/issues/entry'
'?template=Try+Dart+Internal+Error';
@@ -257,8 +262,6 @@ class InitialState extends InteractionState {
}
}
- // editor.scheduleRemoveCodeCompletion();
-
// This is a hack to get Safari (iOS) to send mutation events on
// contenteditable.
// TODO(ahe): Move to onInput?
@@ -270,11 +273,7 @@ class InitialState extends InteractionState {
void onMutation(List<MutationRecord> mutations, MutationObserver observer) {
print('onMutation');
- List<Node> highlighting = mainEditorPane.querySelectorAll(
- 'a.diagnostic>span, .dart-code-completion, .hazed-suggestion');
- for (Element element in highlighting) {
- element.remove();
- }
+ removeCodeCompletion();
Selection selection = window.getSelection();
TrySelection trySelection = new TrySelection(mainEditorPane, selection);
@@ -289,6 +288,8 @@ class InitialState extends InteractionState {
if (node is Element && node.classes.contains('lineNumber')) {
print('Single line change: ${node.outerHtml}');
+ removeShadowRootPolyfill(node);
+
String currentText = node.text;
trySelection = new TrySelection(node, selection);
@@ -321,6 +322,8 @@ class InitialState extends InteractionState {
}
}
+ removeShadowRootPolyfill(mainEditorPane);
+
String currentText = mainEditorPane.text;
trySelection.updateText(currentText);
@@ -535,7 +538,7 @@ class CodeCompletionState extends InitialState {
}
void move(int direction) {
- Element element = editor.moveActive(direction);
+ Element element = editor.moveActive(direction, ui);
if (element == null) return;
var text = activeCompletion.firstChild;
String prefix = "";
@@ -601,7 +604,7 @@ class CodeCompletionState extends InitialState {
num height = activeCompletion.getBoundingClientRect().height;
activeCompletion.classes.add('active');
- ui.nodes.clear();
+ Node root = getShadowRoot(ui);
inline = new SpanElement()
..classes.add('hazed-suggestion');
@@ -615,7 +618,7 @@ class CodeCompletionState extends InitialState {
serverResults = new DivElement()
..style.display = 'none'
..classes.add('dart-server');
- ui.nodes.addAll([staticResults, serverResults]);
+ root.nodes.addAll([staticResults, serverResults]);
ui.style.top = '${height}px';
staticResults.nodes.add(buildCompletionEntry(prefix));
@@ -632,10 +635,8 @@ class CodeCompletionState extends InitialState {
..display = 'inline-block'
..minWidth = '${minWidth}px';
- inline
- ..nodes.clear()
- ..appendText(suggestion.substring(prefix.length))
- ..style.display = '';
+ setShadowRoot(inline, suggestion.substring(prefix.length));
+ inline.style.display = '';
observer.takeRecords(); // Discard mutations.
}
@@ -666,9 +667,7 @@ class CodeCompletionState extends InitialState {
serverResults.nodes.clear();
if (inlineSuggestion != null && inlineSuggestion.startsWith(prefix)) {
- inline
- ..nodes.clear()
- ..appendText(inlineSuggestion.substring(prefix.length));
+ setShadowRoot(inline, inlineSuggestion.substring(prefix.length));
}
List<String> results = editor.seenIdentifiers.where(
@@ -697,13 +696,14 @@ class CodeCompletionState extends InitialState {
if (!serverSuggestions.isEmpty) {
updateInlineSuggestion(prefix, serverSuggestions.first);
}
+ var root = getShadowRoot(ui);
for (int i = 1; i < serverSuggestions.length; i++) {
String completion = serverSuggestions[i];
DivElement where = staticResults;
int index = results.indexOf(completion);
if (index != -1) {
- List<Element> entries =
- document.querySelectorAll('.dart-static>.dart-entry');
+ List<Element> entries = root.querySelectorAll(
+ '.dart-static>.dart-entry');
entries[index].classes.add('doubleplusgood');
} else {
if (results.length > 3) {
@@ -890,3 +890,11 @@ bool isAtEndOfFile(Text text, int offset) {
List<String> splitLines(String text) {
return text.split(new RegExp('^', multiLine: true));
}
+
+void removeCodeCompletion() {
+ List<Node> highlighting =
+ mainEditorPane.querySelectorAll('.dart-code-completion');
+ for (Element element in highlighting) {
+ element.remove();
+ }
+}
« no previous file with comments | « dart/site/try/src/html_to_text.dart ('k') | dart/site/try/src/shadow_root.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698