Skip to content

Commit 7be1773

Browse files
committed
tests: Add avm2/edittext_mouse_selection test
This test verifies the behavior of selecting text using mouse. It takes into account normal, word, and line selection. Example use cases covered by this test: 1. selecting characters, 2. selecting words by double-clicking, 3. selecting multiple words by double-clicking and dragging, 4. selecting lines by triple-clicking, 5. selecting multiple lines by triple-clicking and dragging, 6. double-clicking at word boundaries, 7. double-clicking between spaces, 8. changing the underlying text while clicking and dragging, 9. trying to select while the text field is not selectable.
1 parent 7804857 commit 7be1773

File tree

6 files changed

+771
-0
lines changed

6 files changed

+771
-0
lines changed
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package {
2+
import flash.display.Sprite;
3+
import flash.events.KeyboardEvent;
4+
import flash.events.MouseEvent;
5+
import flash.events.TextEvent;
6+
import flash.text.TextField;
7+
import flash.text.TextFormat;
8+
import flash.ui.Keyboard;
9+
10+
[SWF(width="400", height="200")]
11+
public class Test extends Sprite {
12+
[Embed(source="NotoSans.ttf", fontName="Noto Sans", embedAsCFF="false", unicodeRange="U+0020-U+007E")]
13+
private var notoSans:Class;
14+
15+
private var text:TextField;
16+
17+
public function Test() {
18+
text = new TextField();
19+
text.border = true;
20+
text.width = 400;
21+
text.height = 200;
22+
text.type = "input";
23+
text.wordWrap = true;
24+
text.multiline = true;
25+
var tf = new TextFormat();
26+
tf.font = "Noto Sans";
27+
tf.size = 24;
28+
text.defaultTextFormat = tf;
29+
addChild(text);
30+
31+
stage.focus = text;
32+
stage.addEventListener(TextEvent.TEXT_INPUT, textInput);
33+
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
34+
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
35+
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
36+
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
37+
}
38+
39+
private function keyPressedDown(event:KeyboardEvent):void {
40+
if (event.keyCode == Keyboard.ESCAPE) {
41+
trace("Selected: " + text.selectedText.replace(/\r/g, "\\n").replace(/\n/g, "\\n"));
42+
text.setSelection(0, 0);
43+
} else if (event.keyCode == Keyboard.NUMBER_1) {
44+
text.text = "word1_word2_word3";
45+
} else if (event.keyCode == Keyboard.NUMBER_2) {
46+
text.text = "word1 word2 word3";
47+
} else if (event.keyCode == Keyboard.NUMBER_3) {
48+
text.text = "word1 word2 word3 word4 word5 word6 word7 word8 word9\nword10 word11 word12";
49+
} else if (event.keyCode == Keyboard.NUMBER_4) {
50+
text.selectable = false;
51+
} else if (event.keyCode == Keyboard.NUMBER_5) {
52+
text.selectable = true;
53+
} else if (event.keyCode == Keyboard.NUMBER_6) {
54+
text.text = "word1 word2";
55+
}
56+
trace("{ \"type\": \"KeyDown\", \"key_code\": " + event.keyCode + " },")
57+
}
58+
59+
private function mouseDown(event:MouseEvent):void {
60+
trace("{ \"type\": \"MouseDown\", \"pos\": [" + event.stageX + ", " + event.stageY + "], \"btn\": \"Left\" },");
61+
}
62+
63+
private function mouseUp(event:MouseEvent):void {
64+
trace("{ \"type\": \"MouseUp\", \"pos\": [" + event.stageX + ", " + event.stageY + "], \"btn\": \"Left\" },");
65+
}
66+
67+
private function mouseMove(event:MouseEvent):void {
68+
trace("{ \"type\": \"MouseMove\", \"pos\": [" + event.stageX + ", " + event.stageY + "] },");
69+
}
70+
71+
private function textInput(event:TextEvent):void {
72+
if (event.text.search(/[0-9]/g) != -1) {
73+
event.preventDefault();
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)