反叛者在插入位置获得该区域的线

时间:2013-04-06 14:59:37

标签: rebol

如何在卡雷尔定位区域获得线路? 例如,通过将插入符号放在0816行(在线上的任何位置),我如何获得“0816 LEANYER NT DARWIN DELIVERY CENTER”这一行? 感谢

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

2 个答案:

答案 0 :(得分:2)

当您单击文本或区域面时,文本中的索引将被放入system / view / caret。因此,一旦光标在您的区域面中可见,您就可以获取此插入符号索引,然后计算它所在的行。

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

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

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  
        ]
    ]
]

答案 1 :(得分: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
        ]
    ]
]

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