@@ -12,11 +12,12 @@ import {
12
12
} from '../utils.js'
13
13
import { GlyphGroupManager , InstancedGlyphGroup } from './instanced-glyph-group.js'
14
14
import { GlyphLayout , GlyphLayoutProperties , buildGlyphLayout , computedCustomLayouting } from '../layout.js'
15
- import { SelectionBoxes } from '../../selection.js'
15
+ import { SelectionTransformation } from '../../selection.js'
16
16
import { OrderInfo } from '../../order.js'
17
17
import { Font } from '../font.js'
18
18
import { MergedProperties , computedInheritableProperty } from '../../properties/index.js'
19
19
import { FlexNode , FlexNodeState } from '../../flex/index.js'
20
+ import { CaretTransformation } from '../../caret.js'
20
21
21
22
export type TextAlignProperties = {
22
23
textAlign ?: keyof typeof alignmentXMap | 'block'
@@ -43,8 +44,8 @@ export function createInstancedText(
43
44
fontSignal : Signal < Font | undefined > ,
44
45
glyphGroupManager : GlyphGroupManager ,
45
46
selectionRange : Signal < Vector2Tuple | undefined > | undefined ,
46
- selectionBoxes : Signal < SelectionBoxes > | undefined ,
47
- caretPosition : Signal < Vector3Tuple | undefined > | undefined ,
47
+ selectionTransformations : Signal < Array < SelectionTransformation > > | undefined ,
48
+ caretTransformation : Signal < CaretTransformation | undefined > | undefined ,
48
49
instancedTextRef : { current ?: InstancedText } | undefined ,
49
50
initializers : Initializers ,
50
51
defaultWordBreak : GlyphLayoutProperties [ 'wordBreak' ] ,
@@ -108,8 +109,8 @@ export function createInstancedText(
108
109
isVisible ,
109
110
parentClippingRect ,
110
111
selectionRange ,
111
- selectionBoxes ,
112
- caretPosition ,
112
+ selectionTransformations ,
113
+ caretTransformation ,
113
114
)
114
115
if ( instancedTextRef != null ) {
115
116
instancedTextRef . current = instancedText
@@ -121,7 +122,7 @@ export function createInstancedText(
121
122
return customLayouting
122
123
}
123
124
124
- const noSelectionBoxes : SelectionBoxes = [ ]
125
+ const noSelectionTransformations : Array < SelectionTransformation > = [ ]
125
126
126
127
export class InstancedText {
127
128
private glyphLines : Array < Array < InstancedGlyph | number > > = [ ]
@@ -142,8 +143,8 @@ export class InstancedText {
142
143
isVisible : Signal < boolean > ,
143
144
private parentClippingRect : Signal < ClippingRect | undefined > | undefined ,
144
145
private selectionRange : Signal < Vector2Tuple | undefined > | undefined ,
145
- private selectionBoxes : Signal < SelectionBoxes > | undefined ,
146
- private caretPosition : Signal < Vector3Tuple | undefined > | undefined ,
146
+ private selectionTransformations : Signal < Array < SelectionTransformation > > | undefined ,
147
+ private caretTransformation : Signal < CaretTransformation | undefined > | undefined ,
147
148
) {
148
149
this . unsubscribeInitialList = [
149
150
effect ( ( ) => {
@@ -194,12 +195,12 @@ export class InstancedText {
194
195
verticalAlign : keyof typeof alignmentYMap ,
195
196
textAlign : keyof typeof alignmentXMap | 'block' ,
196
197
) : void {
197
- if ( this . caretPosition == null || this . selectionBoxes == null ) {
198
+ if ( this . caretTransformation == null || this . selectionTransformations == null ) {
198
199
return
199
200
}
200
201
if ( range == null || layout == null || layout . lines . length === 0 ) {
201
- this . caretPosition . value = undefined
202
- this . selectionBoxes . value = noSelectionBoxes
202
+ this . caretTransformation . value = undefined
203
+ this . selectionTransformations . value = noSelectionTransformations
203
204
return
204
205
}
205
206
const whitespaceWidth = layout . font . getGlyphInfo ( ' ' ) . xadvance * layout . fontSize
@@ -212,39 +213,41 @@ export class InstancedText {
212
213
lineIndex * getOffsetToNextLine ( layout . lineHeight , layout . fontSize ) +
213
214
getGlyphOffsetY ( layout . fontSize , layout . lineHeight )
214
215
)
215
- this . caretPosition . value = [ x , y - layout . fontSize / 2 , layout . fontSize ]
216
- this . selectionBoxes . value = [ ]
216
+ this . caretTransformation . value = { position : [ x , y - layout . fontSize / 2 ] , height : layout . fontSize }
217
+ this . selectionTransformations . value = [ ]
217
218
return
218
219
}
219
- this . caretPosition . value = undefined
220
+ this . caretTransformation . value = undefined
220
221
const start = this . getGlyphLineAndX ( layout , startCharIndexIncl , true , whitespaceWidth , textAlign )
221
222
const end = this . getGlyphLineAndX ( layout , endCharIndexExcl - 1 , false , whitespaceWidth , textAlign )
222
223
if ( start . lineIndex === end . lineIndex ) {
223
- this . selectionBoxes . value = [
224
- this . computeSelectionBox ( start . lineIndex , start . x , end . x , layout , verticalAlign , whitespaceWidth ) ,
224
+ this . selectionTransformations . value = [
225
+ this . computeSelectionTransformation ( start . lineIndex , start . x , end . x , layout , verticalAlign , whitespaceWidth ) ,
225
226
]
226
227
return
227
228
}
228
- const newSelectionBoxes : SelectionBoxes = [
229
- this . computeSelectionBox ( start . lineIndex , start . x , undefined , layout , verticalAlign , whitespaceWidth ) ,
229
+ const newSelectionTransformations : Array < SelectionTransformation > = [
230
+ this . computeSelectionTransformation ( start . lineIndex , start . x , undefined , layout , verticalAlign , whitespaceWidth ) ,
230
231
]
231
232
for ( let i = start . lineIndex + 1 ; i < end . lineIndex ; i ++ ) {
232
- newSelectionBoxes . push ( this . computeSelectionBox ( i , undefined , undefined , layout , verticalAlign , whitespaceWidth ) )
233
+ newSelectionTransformations . push (
234
+ this . computeSelectionTransformation ( i , undefined , undefined , layout , verticalAlign , whitespaceWidth ) ,
235
+ )
233
236
}
234
- newSelectionBoxes . push (
235
- this . computeSelectionBox ( end . lineIndex , undefined , end . x , layout , verticalAlign , whitespaceWidth ) ,
237
+ newSelectionTransformations . push (
238
+ this . computeSelectionTransformation ( end . lineIndex , undefined , end . x , layout , verticalAlign , whitespaceWidth ) ,
236
239
)
237
- this . selectionBoxes . value = newSelectionBoxes
240
+ this . selectionTransformations . value = newSelectionTransformations
238
241
}
239
242
240
- private computeSelectionBox (
243
+ private computeSelectionTransformation (
241
244
lineIndex : number ,
242
245
startX : number | undefined ,
243
246
endX : number | undefined ,
244
247
layout : GlyphLayout ,
245
248
verticalAlign : keyof typeof alignmentYMap ,
246
249
whitespaceWidth : number ,
247
- ) : SelectionBoxes [ number ] {
250
+ ) : SelectionTransformation {
248
251
const lineGlyphs = this . glyphLines [ lineIndex ]
249
252
if ( startX == null ) {
250
253
startX = this . getGlyphX ( lineGlyphs [ 0 ] , 0 , whitespaceWidth )
0 commit comments