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

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

Issue 345553008: Fix issues that broke editing on browsers without Shadow DOM support. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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
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 dba6d5547423d4dea912623aea08ed0853c566a6..bccc995ad88f9b26d7cb3132c250015a8ebecefd 100644
--- a/dart/site/try/src/interaction_manager.dart
+++ b/dart/site/try/src/interaction_manager.dart
@@ -228,6 +228,7 @@ class InteractionContext extends InteractionManager {
void onKeyUp(KeyboardEvent event) => state.onKeyUp(event);
void onMutation(List<MutationRecord> mutations, MutationObserver observer) {
+ workAroundFirefoxBug();
try {
try {
return state.onMutation(mutations, observer);
@@ -305,7 +306,6 @@ abstract class InteractionState implements InteractionManager {
void set state(InteractionState newState);
void onStateChanged(InteractionState previous) {
- print('State change ${previous.runtimeType} -> ${runtimeType}.');
}
void transitionToInitialState() {
@@ -333,10 +333,8 @@ class InitialState extends InteractionState {
void onKeyUp(KeyboardEvent event) {
if (computeHasModifier(event)) {
- print('onKeyUp (modified)');
onModifiedKeyUp(event);
} else {
- print('onKeyUp (unmodified)');
onUnmodifiedKeyUp(event);
}
}
@@ -383,8 +381,6 @@ class InitialState extends InteractionState {
}
void onMutation(List<MutationRecord> mutations, MutationObserver observer) {
- print('onMutation');
-
removeCodeCompletion();
Selection selection = window.getSelection();
@@ -426,7 +422,9 @@ class InitialState extends InteractionState {
node.parent.insertAllBefore(nodes, node);
node.remove();
- trySelection.adjust(selection);
+ if (mainEditorPane.contains(trySelection.anchorNode)) {
ahe 2014/06/27 11:23:28 This sometimes happens on Firefox. It is related t
Johnni Winther 2014/07/02 08:40:54 Put this in a comment.
ahe 2014/07/04 13:52:00 Done.
+ trySelection.adjust(selection);
+ }
// TODO(ahe): We know almost exactly what has changed. It could be
// more efficient to only communicate what changed.
@@ -1150,7 +1148,7 @@ void normalizeMutationRecord(MutationRecord record,
if (!record.removedNodes.isEmpty) {
normalizedNodes.add(findLine(record.target));
}
- if (record.type == "characterData") {
+ if (record.type == "characterData" && record.target.parent != null) {
ahe 2014/06/27 11:23:28 Firefox sends two records when the last character
Johnni Winther 2014/07/02 08:40:54 Put this in a comment.
ahe 2014/07/04 13:52:00 Done.
normalizedNodes.add(findLine(record.target));
}
}
@@ -1203,3 +1201,17 @@ bool isCompilerStageMarker(String message) {
message == "Compiling..." ||
message.startsWith('Compiled ');
}
+
+void workAroundFirefoxBug() {
+ Selection selection = window.getSelection();
+ if (!isCollapsed(selection)) return;
+ Node node = selection.anchorNode;
+ int offset = selection.anchorOffset;
+ if (selection.anchorNode is Element && selection.anchorOffset != 0) {
ahe 2014/06/27 11:23:28 In some cases, Firefox reports the wrong anchorOff
Johnni Winther 2014/07/02 08:40:54 Again, put this in a comment.
ahe 2014/07/04 13:52:00 Done.
+ selection
+ ..modify('move', 'backward', 'character')
+ ..modify('move', 'forward', 'character');
+ print('Worked around Firefox selection bug $node@$offset -> '
+ '${selection.anchorNode}@${selection.anchorOffset}.');
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698