@@ -19,7 +19,7 @@ pub(crate) struct InnerPosition<'a> {
19
19
impl < ' a > InnerPosition < ' a > {
20
20
fn upgrade ( tree_state : & ' a TreeState , weak : WeakPosition ) -> Option < Self > {
21
21
let node = tree_state. node_by_id ( weak. node ) ?;
22
- if node. role ( ) != Role :: InlineTextBox {
22
+ if node. role ( ) != Role :: TextRun {
23
23
return None ;
24
24
}
25
25
let character_index = weak. character_index ;
@@ -34,7 +34,7 @@ impl<'a> InnerPosition<'a> {
34
34
35
35
fn clamped_upgrade ( tree_state : & ' a TreeState , weak : WeakPosition ) -> Option < Self > {
36
36
let node = tree_state. node_by_id ( weak. node ) ?;
37
- if node. role ( ) != Role :: InlineTextBox {
37
+ if node. role ( ) != Role :: TextRun {
38
38
return None ;
39
39
}
40
40
let character_index = weak
@@ -57,47 +57,37 @@ impl<'a> InnerPosition<'a> {
57
57
false
58
58
}
59
59
60
- fn is_box_start ( & self ) -> bool {
60
+ fn is_run_start ( & self ) -> bool {
61
61
self . character_index == 0
62
62
}
63
63
64
64
fn is_line_start ( & self ) -> bool {
65
- self . is_box_start ( ) && self . node . data ( ) . previous_on_line ( ) . is_none ( )
65
+ self . is_run_start ( ) && self . node . data ( ) . previous_on_line ( ) . is_none ( )
66
66
}
67
67
68
- fn is_box_end ( & self ) -> bool {
68
+ fn is_run_end ( & self ) -> bool {
69
69
self . character_index == self . node . data ( ) . character_lengths ( ) . len ( )
70
70
}
71
71
72
72
fn is_line_end ( & self ) -> bool {
73
- self . is_box_end ( ) && self . node . data ( ) . next_on_line ( ) . is_none ( )
73
+ self . is_run_end ( ) && self . node . data ( ) . next_on_line ( ) . is_none ( )
74
74
}
75
75
76
76
fn is_paragraph_end ( & self ) -> bool {
77
77
self . is_line_end ( ) && self . node . data ( ) . value ( ) . unwrap ( ) . ends_with ( '\n' )
78
78
}
79
79
80
80
fn is_document_start ( & self , root_node : & Node ) -> bool {
81
- self . is_box_start ( )
82
- && self
83
- . node
84
- . preceding_inline_text_boxes ( root_node)
85
- . next ( )
86
- . is_none ( )
81
+ self . is_run_start ( ) && self . node . preceding_text_runs ( root_node) . next ( ) . is_none ( )
87
82
}
88
83
89
84
fn is_document_end ( & self , root_node : & Node ) -> bool {
90
- self . is_box_end ( )
91
- && self
92
- . node
93
- . following_inline_text_boxes ( root_node)
94
- . next ( )
95
- . is_none ( )
85
+ self . is_run_end ( ) && self . node . following_text_runs ( root_node) . next ( ) . is_none ( )
96
86
}
97
87
98
88
fn biased_to_start ( & self , root_node : & Node ) -> Self {
99
- if self . is_box_end ( ) {
100
- if let Some ( node) = self . node . following_inline_text_boxes ( root_node) . next ( ) {
89
+ if self . is_run_end ( ) {
90
+ if let Some ( node) = self . node . following_text_runs ( root_node) . next ( ) {
101
91
return Self {
102
92
node,
103
93
character_index : 0 ,
@@ -108,8 +98,8 @@ impl<'a> InnerPosition<'a> {
108
98
}
109
99
110
100
fn biased_to_end ( & self , root_node : & Node ) -> Self {
111
- if self . is_box_start ( ) {
112
- if let Some ( node) = self . node . preceding_inline_text_boxes ( root_node) . next ( ) {
101
+ if self . is_run_start ( ) {
102
+ if let Some ( node) = self . node . preceding_text_runs ( root_node) . next ( ) {
113
103
return Self {
114
104
node,
115
105
character_index : node. data ( ) . character_lengths ( ) . len ( ) ,
@@ -250,7 +240,7 @@ impl<'a> Position<'a> {
250
240
251
241
pub fn to_global_usv_index ( & self ) -> usize {
252
242
let mut total_length = 0usize ;
253
- for node in self . root_node . inline_text_boxes ( ) {
243
+ for node in self . root_node . text_runs ( ) {
254
244
let node_text = node. data ( ) . value ( ) . unwrap ( ) ;
255
245
if node. id ( ) == self . inner . node . id ( ) {
256
246
let character_lengths = node. data ( ) . character_lengths ( ) ;
@@ -268,7 +258,7 @@ impl<'a> Position<'a> {
268
258
269
259
pub fn to_global_utf16_index ( & self ) -> usize {
270
260
let mut total_length = 0usize ;
271
- for node in self . root_node . inline_text_boxes ( ) {
261
+ for node in self . root_node . text_runs ( ) {
272
262
let node_text = node. data ( ) . value ( ) . unwrap ( ) ;
273
263
if node. id ( ) == self . inner . node . id ( ) {
274
264
let character_lengths = node. data ( ) . character_lengths ( ) ;
@@ -545,7 +535,7 @@ impl<'a> Range<'a> {
545
535
if start. node . id ( ) == end. node . id ( ) {
546
536
return None ;
547
537
}
548
- for node in start. node . following_inline_text_boxes ( & self . node ) {
538
+ for node in start. node . following_text_runs ( & self . node ) {
549
539
if let Some ( result) = f ( & node) {
550
540
return Some ( result) ;
551
541
}
@@ -796,7 +786,7 @@ impl WeakRange {
796
786
}
797
787
798
788
fn text_node_filter ( root_id : NodeId , node : & Node ) -> FilterResult {
799
- if node. id ( ) == root_id || node. role ( ) == Role :: InlineTextBox {
789
+ if node. id ( ) == root_id || node. role ( ) == Role :: TextRun {
800
790
FilterResult :: Include
801
791
} else {
802
792
FilterResult :: ExcludeNode
@@ -844,22 +834,22 @@ fn character_index_at_point(node: &Node, point: Point) -> usize {
844
834
}
845
835
846
836
impl < ' a > Node < ' a > {
847
- fn inline_text_boxes (
837
+ fn text_runs (
848
838
& self ,
849
839
) -> impl DoubleEndedIterator < Item = Node < ' a > > + FusedIterator < Item = Node < ' a > > + ' a {
850
840
let id = self . id ( ) ;
851
841
self . filtered_children ( move |node| text_node_filter ( id, node) )
852
842
}
853
843
854
- fn following_inline_text_boxes (
844
+ fn following_text_runs (
855
845
& self ,
856
846
root_node : & Node ,
857
847
) -> impl DoubleEndedIterator < Item = Node < ' a > > + FusedIterator < Item = Node < ' a > > + ' a {
858
848
let id = root_node. id ( ) ;
859
849
self . following_filtered_siblings ( move |node| text_node_filter ( id, node) )
860
850
}
861
851
862
- fn preceding_inline_text_boxes (
852
+ fn preceding_text_runs (
863
853
& self ,
864
854
root_node : & Node ,
865
855
) -> impl DoubleEndedIterator < Item = Node < ' a > > + FusedIterator < Item = Node < ' a > > + ' a {
@@ -870,19 +860,19 @@ impl<'a> Node<'a> {
870
860
pub fn supports_text_ranges ( & self ) -> bool {
871
861
( self . is_text_input ( )
872
862
|| matches ! ( self . role( ) , Role :: Label | Role :: Document | Role :: Terminal ) )
873
- && self . inline_text_boxes ( ) . next ( ) . is_some ( )
863
+ && self . text_runs ( ) . next ( ) . is_some ( )
874
864
}
875
865
876
866
fn document_start ( & self ) -> InnerPosition < ' a > {
877
- let node = self . inline_text_boxes ( ) . next ( ) . unwrap ( ) ;
867
+ let node = self . text_runs ( ) . next ( ) . unwrap ( ) ;
878
868
InnerPosition {
879
869
node,
880
870
character_index : 0 ,
881
871
}
882
872
}
883
873
884
874
fn document_end ( & self ) -> InnerPosition < ' a > {
885
- let node = self . inline_text_boxes ( ) . next_back ( ) . unwrap ( ) ;
875
+ let node = self . text_runs ( ) . next_back ( ) . unwrap ( ) ;
886
876
InnerPosition {
887
877
node,
888
878
character_index : node. data ( ) . character_lengths ( ) . len ( ) ,
@@ -922,7 +912,7 @@ impl<'a> Node<'a> {
922
912
pub fn text_position_at_point ( & self , point : Point ) -> Position {
923
913
let id = self . id ( ) ;
924
914
if let Some ( ( node, point) ) = self . hit_test ( point, & move |node| text_node_filter ( id, node) ) {
925
- if node. role ( ) == Role :: InlineTextBox {
915
+ if node. role ( ) == Role :: TextRun {
926
916
let pos = InnerPosition {
927
917
node,
928
918
character_index : character_index_at_point ( & node, point) ,
@@ -935,9 +925,9 @@ impl<'a> Node<'a> {
935
925
}
936
926
937
927
// The following tests can assume that the point is not within
938
- // any inline text box .
928
+ // any text run .
939
929
940
- if let Some ( node) = self . inline_text_boxes ( ) . next ( ) {
930
+ if let Some ( node) = self . text_runs ( ) . next ( ) {
941
931
if let Some ( rect) = node. bounding_box_in_coordinate_space ( self ) {
942
932
let origin = rect. origin ( ) ;
943
933
if point. x < origin. x || point. y < origin. y {
@@ -949,7 +939,7 @@ impl<'a> Node<'a> {
949
939
}
950
940
}
951
941
952
- for node in self . inline_text_boxes ( ) . rev ( ) {
942
+ for node in self . text_runs ( ) . rev ( ) {
953
943
if let Some ( rect) = node. bounding_box_in_coordinate_space ( self ) {
954
944
if let Some ( direction) = node. data ( ) . text_direction ( ) {
955
945
let is_past_end = match direction {
@@ -1013,7 +1003,7 @@ impl<'a> Node<'a> {
1013
1003
1014
1004
pub fn text_position_from_global_usv_index ( & self , index : usize ) -> Option < Position > {
1015
1005
let mut total_length = 0usize ;
1016
- for node in self . inline_text_boxes ( ) {
1006
+ for node in self . text_runs ( ) {
1017
1007
let node_text = node. data ( ) . value ( ) . unwrap ( ) ;
1018
1008
let node_text_length = node_text. chars ( ) . count ( ) ;
1019
1009
let new_total_length = total_length + node_text_length;
@@ -1055,7 +1045,7 @@ impl<'a> Node<'a> {
1055
1045
1056
1046
pub fn text_position_from_global_utf16_index ( & self , index : usize ) -> Option < Position > {
1057
1047
let mut total_length = 0usize ;
1058
- for node in self . inline_text_boxes ( ) {
1048
+ for node in self . text_runs ( ) {
1059
1049
let node_text = node. data ( ) . value ( ) . unwrap ( ) ;
1060
1050
let node_text_length = node_text. chars ( ) . map ( char:: len_utf16) . sum :: < usize > ( ) ;
1061
1051
let new_total_length = total_length + node_text_length;
@@ -1135,7 +1125,7 @@ mod tests {
1135
1125
builder. build( )
1136
1126
} ) ,
1137
1127
( NodeId ( 2 ) , {
1138
- let mut builder = NodeBuilder :: new( Role :: InlineTextBox ) ;
1128
+ let mut builder = NodeBuilder :: new( Role :: TextRun ) ;
1139
1129
builder. set_bounds( Rect {
1140
1130
x0: 12.0 ,
1141
1131
y0: 33.666664123535156 ,
@@ -1170,7 +1160,7 @@ mod tests {
1170
1160
builder. build( )
1171
1161
} ) ,
1172
1162
( NodeId ( 3 ) , {
1173
- let mut builder = NodeBuilder :: new( Role :: InlineTextBox ) ;
1163
+ let mut builder = NodeBuilder :: new( Role :: TextRun ) ;
1174
1164
builder. set_bounds( Rect {
1175
1165
x0: 12.0 ,
1176
1166
y0: 48.33333206176758 ,
@@ -1195,7 +1185,7 @@ mod tests {
1195
1185
builder. build( )
1196
1186
} ) ,
1197
1187
( NodeId ( 4 ) , {
1198
- let mut builder = NodeBuilder :: new( Role :: InlineTextBox ) ;
1188
+ let mut builder = NodeBuilder :: new( Role :: TextRun ) ;
1199
1189
builder. set_bounds( Rect {
1200
1190
x0: 12.0 ,
1201
1191
y0: 63.0 ,
@@ -1221,7 +1211,7 @@ mod tests {
1221
1211
builder. build( )
1222
1212
} ) ,
1223
1213
( NodeId ( 5 ) , {
1224
- let mut builder = NodeBuilder :: new( Role :: InlineTextBox ) ;
1214
+ let mut builder = NodeBuilder :: new( Role :: TextRun ) ;
1225
1215
builder. set_bounds( Rect {
1226
1216
x0: 12.0 ,
1227
1217
y0: 77.66666412353516 ,
@@ -1237,7 +1227,7 @@ mod tests {
1237
1227
builder. build( )
1238
1228
} ) ,
1239
1229
( NodeId ( 6 ) , {
1240
- let mut builder = NodeBuilder :: new( Role :: InlineTextBox ) ;
1230
+ let mut builder = NodeBuilder :: new( Role :: TextRun ) ;
1241
1231
builder. set_bounds( Rect {
1242
1232
x0: 12.0 ,
1243
1233
y0: 92.33332824707031 ,
@@ -1267,7 +1257,7 @@ mod tests {
1267
1257
builder. build( )
1268
1258
} ) ,
1269
1259
( NodeId ( 7 ) , {
1270
- let mut builder = NodeBuilder :: new( Role :: InlineTextBox ) ;
1260
+ let mut builder = NodeBuilder :: new( Role :: TextRun ) ;
1271
1261
builder. set_bounds( Rect {
1272
1262
x0: 12.0 ,
1273
1263
y0: 107.0 ,
0 commit comments