| 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 // Test that cursor positions are correctly updated after adding new content. | 5 // Test that cursor positions are correctly updated after adding new content. |
| 6 | 6 |
| 7 import 'test_try.dart'; | 7 import 'test_try.dart'; |
| 8 | 8 |
| 9 void main() { | 9 void main() { |
| 10 InteractionManager interaction = mockTryDartInteraction(); | 10 InteractionManager interaction = mockTryDartInteraction(); |
| 11 | 11 |
| 12 TestCase twoLines = | 12 TestCase twoLines = |
| 13 new TestCase('Test adding two lines programmatically.', () { | 13 new TestCase('Test adding two lines programmatically.', () { |
| 14 clearEditorPaneWithoutNotifications(); | 14 clearEditorPaneWithoutNotifications(); |
| 15 mainEditorPane.appendText('\n\n'); | 15 mainEditorPane.appendText('\n\n'); |
| 16 Text text = mainEditorPane.firstChild; | 16 var textOrBr = mainEditorPane.firstChild; |
| 17 window.getSelection().collapse(text, 1); | 17 if (textOrBr is Text) { |
| 18 checkSelectionIsCollapsed(text, 1); | 18 window.getSelection().collapse(textOrBr, 1); |
| 19 checkSelectionIsCollapsed(textOrBr, 1); |
| 20 } else { |
| 21 // This else-branch accomodates IE11, which |
| 22 // puts <BR> instead of '\n' in content-editable Divs. |
| 23 var range = document.createRange()..selectNode(textOrBr); |
| 24 (window.getSelection())..addRange(range) |
| 25 ..collapseToEnd(); |
| 26 checkSelectionIsCollapsed(mainEditorPane, 1); |
| 27 } |
| 19 }, checkAtBeginningOfSecondLine); | 28 }, checkAtBeginningOfSecondLine); |
| 20 | 29 |
| 21 runTests(<TestCase>[ | 30 runTests(<TestCase>[ |
| 22 twoLines, | 31 twoLines, |
| 23 | 32 |
| 24 new TestCase('Test adding a new text node.', () { | 33 new TestCase('Test adding a new text node.', () { |
| 25 // This test relies on the previous test leaving two lines. | 34 // This test relies on the previous test leaving two lines. |
| 26 Text text = new Text('fisk'); | 35 Text text = new Text('fisk'); |
| 27 window.getSelection().getRangeAt(0).insertNode(text); | 36 window.getSelection().getRangeAt(0).insertNode(text); |
| 28 window.getSelection().collapse(text, text.length); | 37 window.getSelection().collapse(text, text.length); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 114 |
| 106 class MockKeyboardEvent extends KeyEvent { | 115 class MockKeyboardEvent extends KeyEvent { |
| 107 final int keyCode; | 116 final int keyCode; |
| 108 | 117 |
| 109 MockKeyboardEvent(String type, {int keyCode}) | 118 MockKeyboardEvent(String type, {int keyCode}) |
| 110 : this.keyCode = keyCode, | 119 : this.keyCode = keyCode, |
| 111 super.wrap(new KeyEvent(type, keyCode: keyCode)); | 120 super.wrap(new KeyEvent(type, keyCode: keyCode)); |
| 112 | 121 |
| 113 bool getModifierState(String keyArgument) => false; | 122 bool getModifierState(String keyArgument) => false; |
| 114 } | 123 } |
| OLD | NEW |