2

一个简单的例子:

如果我在样式“area”中键入#“w”,我如何得到#“z”?(例如“qwerty ww”->“qzerty zz”)

4

2 回答 2

2

由于您想要即时转换,您可以在加载之前修改 R3-GUI。因此,将r3-gui.r3加载到您的本地目录。然后将if key == #"w" [key: #"z"]行添加到函数do-text-key,所以它看起来像

do-text-key: funct [
  "Process text face keyboard events."
  face [object!]
  event [event! object!]
  key
] [
  text-key-map/face: face
  text-key-map/shift?: find event/flags 'shift
  if no-edit: not tag-face? face 'edit [
    key: any [select/skip text-key-map/no-edit key 2 key]
  ]
  either char? key [
    if key == #"w" [key: #"z"]
    text-key-map/key: key
    switch/default key bind text-key-map/chars 'event [
      unless no-edit [
          insert-text-face face key
      ]
    ]
  ] [
    if find event/flags 'control [
      key: any [select text-key-map/control key key]
    ]
      text-key-map/key: key
      switch/default key text-key-map/words [return event]
  ]
  none
]

可能官方的方式是在Rebol3上使用on-key

load-gui
view [
  a: area  on-key [ ; arg: event
     if arg/type = 'key [
        if  arg/key == #"w" [arg/key:  #"z"]
     ]
     do-actor/style face 'on-key arg face/style
  ]
]

最后是一种使用 Rebol2 即时执行此操作的方法

key-event: func [face event] [
    if event/type = 'key [ 
        if all [event/key = #"w"   ] [
            append a/text  #"z" 
            focus a
            view w 
           return false
        ]
    ] 
    event 
] 
insert-event-func :key-event        

view w: layout [
    a: area 
]
于 2015-02-17T12:04:12.193 回答
2

在阅读了r3-gui (text-caret.r3, text-cursor.r3, text-edit.r3, text-keys.r3, text.r3) 和编辑器的一些文件后,我找到了一个允许我插入的解决方案不仅是一个字符,还有字符串:

do %r3-gui.r3

insertText-moveCursor-updateFace: func [
    face
    string
    n-move
][
    insert-text-face face string
    move-cursor face 'left n-move false 
    update-text-caret face 
    see-caret face
    show-later face
]   

i-m-u: :insertText-moveCursor-updateFace

view [
    area on-key [
        either arg/type = 'key [
            switch/default  arg/key [
                #"w" [i-m-u face/names/text-box "z" 0]
                #"[" [i-m-u face/names/text-box "[]" 1]
                #"$" [i-m-u face/names/text-box "func [] []" 4]
            ] [
                ;switch/default 
                do-actor/style face 'on-key arg face/style
            ]
        ] [
            ;arg/type != 'key
            do-actor/style face 'on-key arg face/style
        ]   
    ]   
]

区域是一种复合样式。它由一个文本框和一个滚动条组成。它们包含在face/names中。

于 2015-03-02T10:25:51.877 回答