4

如何在 carret 所在的区域获得线路?例如,通过将插入符号放在 0816 行(该行的任何位置),我如何获得“0816 LEANYER NT DARWIN DELIVERY CENTRE”行?谢谢

rebol []

sample-data: [
"0810 TIWI NT DARWIN DELIVERY CENTRE"
"0811 WAGAMAN NT DARWIN DELIVERY CENTRE"
"0812 WANGURI NT DARWIN DELIVERY CENTRE"
"0813 CASUARINA NT PO Boxes CASUARINA"
"0814 ANULA NT DARWIN DELIVERY CENTRE"
"0815 KARAMA NT DARWIN DELIVERY CENTRE"
"0816 LEANYER NT DARWIN DELIVERY CENTRE"
"0817 MALAK NT DARWIN DELIVERY CENTRE"
"0818 MARRARA NT DARWIN DELIVERY CENTRE"
"0819 SANDERSON NT DARWIN DELIVERY CENTRE"
"0820 WULAGI NT DARWIN DELIVERY CENTRE"
"0821 SANDERSON NT PO Boxes SANDERSON"
"0822 NIGHTCLIFF NT PO Boxes NIGHTCLIFF"
"0823 NIGHTCLIFF NT PO Boxes NIGHTCLIFF"
"0824 NIGHTCLIFF NT PO Boxes NIGHTCLIFF"
"0825 NIGHTCLIFF NT PO Boxes NIGHTCLIFF"
]


gui: layout [
b1: backcolor yellow
style fld field 300
across
c1: crit1: fld "hello"
return
ab: area 790x300 font-size 18 wrap []
return

button "Start" [       
        for counter 1 16 1 [ 
         append ab/text reduce [sample-data/(counter) newline]
         ]
         show ab
         ]

button "Quit" [quit]
]
view gui
4

2 回答 2

2

当您单击文本或区域面时,文本的索引将放置到系统/视图/插入符号中。因此,一旦光标在您的区域面上可见,您就可以抓住这个插入符号索引,然后计算它在哪一行。

但是,除非您希望用户编辑区域面,否则我会认为使用列表面会更容易使用。

这是一些工作代码 - 添加此按钮

button "Find" [
    use [ before cnt ][
        if all [ 
            system/view/caret 
            find ab/text system/view/caret
            before: copy/part ab/text find ab/text system/view/caret
        ][
            parse/all before [ (cnt: 1 ) some [ thru newline ( cnt: cnt + 1 ) ]]
            alert pick sample-data cnt  
        ]
    ]
]
于 2013-04-08T10:30:27.950 回答
0

所以这是你问的版本;

button "Find" [
    use [ before cnt ][
        if start: system/view/caret [
            ;find the previous newline char (if no this is the first line)
            start: either found? st: find/reverse/tail start newline [st] [head start]
            end: either found? st: find start newline [st] [tail start]
            probe copy/part start end
        ]
    ]
]

请接受格雷厄姆的回答,我只是扩展了他的版本。

于 2013-04-12T11:43:13.607 回答