トリプルクリック時に一段落を全選択するには

◆ご質問◆
トリプルクリックをした場合、TextFieldを使用すると一段落が全選択ができますが、
他のコンポーネント(TextDisplay)でも可能でしょうか?

◆回答◆
TextDisplayは文字表示に用いるAPIですので、選択には対応しておりません。

TextFlowBoxであれば、範囲選択用のイベントハンドラを追加することで実現可能です。

{curl 6.0,7.0,8.0 applet}

{define-proc {create-select-line-handler}:EventHandler
    {return
        {on e:PointerPress at grsc:GuiRangeSelectionContext do
            {if not e.consumed? and e.click-count == 3 then
                {if grsc.range-selection-ui-enabled? then
                    {if-non-null range = grsc.selection.range then
                        def start-mark = range.start-mark
                        def end-mark = range.end-mark

                        {if start-mark.graphic == end-mark.graphic then
                            def graphic = start-mark.graphic
                            def bounds = {graphic.layout.get-bounds}
                            def start-clone = {start-mark.clone}
                            def end-clone = {end-mark.clone}
                           
                            def (graphic-x, graphic-y) =
                                {transform-coordinates e.x, e.y, grsc, graphic}
                           
                            {if
                                {start-clone.move-to-point
                                    bounds.lextent, graphic-y
                                } and
                                {end-clone.move-to-point
                                    bounds.rextent – .01pt, graphic-y
                                }
                             then
                                {grsc.select start-clone, end-clone}
                            }
                        }
                    }
                   
                    {e.consume}
                }
            }
        }
    }
}

{define-proc {find-grsc g:Graphic}:#GuiRangeSelectionContext
    {type-switch g
     case g:GuiRangeSelectionContext do
        {return g}
    }

    {if-non-null parent = g.parent then
        {return {find-grsc parent}}
    }

    {return null}
}

{define-proc {install-handler g:Graphic}:void
    {if-non-null grsc = {find-grsc g} then
        {grsc.add-event-handler {create-select-line-handler}}
    }
}

{value
    def tfb =
        {TextFlowBox background={Color.from-string “#9099ff”},
            width=2in,

            {text First text fragment.},
            {paragraph
                Second text fragment. Quite a bit
                longer than the first. May wrap.},
            “Text in quotes. Here, text is expressed “ &
            “as two concatenated Strings.”
        }
    {after 0s do {install-handler tfb}}
    tfb
}