OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import '../fn.dart'; | 5 import '../fn2.dart'; |
6 import '../theme/colors.dart'; | 6 import '../theme/colors.dart'; |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'editable_string.dart'; | 8 import 'editable_string.dart'; |
9 | 9 |
10 class EditableText extends Component { | 10 class EditableText extends Component { |
11 | 11 |
12 static final Style _cursorStyle = new Style(''' | 12 // static final Style _cursorStyle = new Style(''' |
13 width: 2px; | 13 // width: 2px; |
14 height: 1.2em; | 14 // height: 1.2em; |
15 vertical-align: top; | 15 // vertical-align: top; |
16 background-color: ${Blue[500]};''' | 16 // background-color: ${Blue[500]};''' |
17 ); | 17 // ); |
18 | 18 |
19 static final Style _composingStyle = new Style(''' | 19 // static final Style _composingStyle = new Style(''' |
20 text-decoration: underline;''' | 20 // text-decoration: underline;''' |
21 ); | 21 // ); |
22 | 22 |
23 EditableString value; | 23 EditableString value; |
24 bool focused; | 24 bool focused; |
25 Timer _cursorTimer; | 25 Timer _cursorTimer; |
26 bool _showCursor = false; | 26 bool _showCursor = false; |
27 | 27 |
28 EditableText({Object key, this.value, this.focused}) | 28 EditableText({Object key, this.value, this.focused}) |
29 : super(key: key, stateful: true) { | 29 : super(key: key, stateful: true) { |
30 onDidUnmount(() { | 30 onDidUnmount(() { |
31 if (_cursorTimer != null) | 31 if (_cursorTimer != null) |
(...skipping 18 matching lines...) Expand all Loading... |
50 _cursorTimer = null; | 50 _cursorTimer = null; |
51 _showCursor = false; | 51 _showCursor = false; |
52 } | 52 } |
53 | 53 |
54 UINode build() { | 54 UINode build() { |
55 if (focused && _cursorTimer == null) | 55 if (focused && _cursorTimer == null) |
56 _startCursorTimer(); | 56 _startCursorTimer(); |
57 else if (!focused && _cursorTimer != null) | 57 else if (!focused && _cursorTimer != null) |
58 _stopCursorTimer(); | 58 _stopCursorTimer(); |
59 | 59 |
60 List<UINode> children = new List<UINode>(); | 60 //List<UINode> children = new List<UINode>(); |
| 61 String hack = ""; |
61 | 62 |
62 if (!value.composing.isValid) { | 63 if (!value.composing.isValid) { |
63 children.add(new TextFragment(value.text)); | 64 // children.add(new TextFragment(value.text)); |
| 65 hack += value.text; |
64 } else { | 66 } else { |
65 String beforeComposing = value.textBefore(value.composing); | 67 String beforeComposing = value.textBefore(value.composing); |
66 if (!beforeComposing.isEmpty) | 68 if (!beforeComposing.isEmpty) { |
67 children.add(new TextFragment(beforeComposing)); | 69 // children.add(new TextFragment(beforeComposing)); |
| 70 hack += value.beforeComposing; |
| 71 } |
68 | 72 |
69 String composing = value.textInside(value.composing); | 73 String composing = value.textInside(value.composing); |
70 if (!composing.isEmpty) { | 74 hack += value.composing; |
71 children.add(new TextFragment( | 75 hack += value.afterComposing; |
72 composing, | 76 // if (!composing.isEmpty) { |
73 key: 'composing', | 77 // children.add(new TextFragment( |
74 style: _composingStyle | 78 // composing, |
75 )); | 79 // key: 'composing', |
76 } | 80 // style: _composingStyle |
| 81 // )); |
| 82 // } |
77 | 83 |
78 String afterComposing = value.textAfter(value.composing); | 84 // String afterComposing = value.textAfter(value.composing); |
79 if (!afterComposing.isEmpty) | 85 // if (!afterComposing.isEmpty) |
80 children.add(new TextFragment(afterComposing)); | 86 // children.add(new TextFragment(afterComposing)); |
81 } | 87 } |
82 | 88 |
83 if (_showCursor) | 89 // if (_showCursor) |
84 children.add(new Container(key: 'cursor', style: _cursorStyle)); | 90 // children.add(new Container( |
| 91 // key: 'cursor', |
| 92 // // style: _cursorStyle |
| 93 // )); |
85 | 94 |
86 return new Paragraph( | 95 return new Paragraph( |
87 children: children | 96 text: hack |
88 ); | 97 ); |
89 } | 98 } |
90 } | 99 } |
OLD | NEW |