Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Limit Field Length

From: carl:cybercraft at: 3-Mar-2003 9:50

On 03-Mar-03, Jim Richards wrote:
> Hi All, > > Is there a quick and easy way to limit the amount of data put into a > View field?
Hi Jim, Not sure if it's quick and easy, but you can do it by using a modified feel/engage. See what a standard engage function looks like by entering the following at the console... layout [f: field] probe f/feel The key block there is where key presses are processed, so you can block them at that point if you wish. So, here's a modified version of engage with an example of how to use it. Hope it helps... rebol [] new-engage: func [face act event][ switch act [ down [ either not-equal? face system/view/focal-face [ focus face system/view/caret: offset-to-caret face event/offset ] [ system/view/highlight-start: system/view/highlight-end: none system/view/caret: offset-to-caret face event/offset ] show face ] over [ if not-equal? system/view/caret offset-to-caret face event/offset [ if not system/view/highlight-start [ system/view/highlight-start: system/view/caret ] system/view/highlight-end: system/view/caret: offset-to-caret face event/offset show face ] ] key [ if any [ ; Alter or add to these conditions to restrict key ; behaviour. 5 > length? face/text event/key = #"^M" ; Return event/key = #"^~" ; Delete event/key = #"^H" ; Backspace event/key = #"^-" ; Tab event/key = 'left event/key = 'right ][ system/words/ctx-text/edit-text face event get in face 'action ] ] ] ] view layout [ across label "Normal Field:" right 120 field return label "Limited Field:" right 120 field feel [engage: :new-engage] ] -- Carl Read