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

[REBOL] Re: specifiv position in area

From: brett:codeconscious at: 26-Feb-2002 21:36

Hi Thorsten, Romano & Gabriele, Thanks Romano & Gabriele for the replies. That explains why the insert point is lost after the enter key. 1) UNFOCUS sets system/view/caret to none. 2) The default event function calls UNFOCUS.
> The question is, how can i determine the cursor-position before > refocussing the area to place the cursor at the right position > after the focus?
The trick is finding the right time to do this. I've been thinking it would be nice to have a "leave the field event" anyway. So my strategy is to generate one - that is fire a new ON-UNFOCUS function on the face when UNFOCUS occurs. I prefer not to replace the delivered functionality. Here the "embrace and extend" strategy is useful :) So I save away the existing UNFOCUS function and call it from a new UNFOCUS function that calls the ON-UNFOCUS function. Putting this together yields the code included below. Unfortunately the solution suffers from blinking which dissappears for most inserts if you remove the setting of the "dirty?" flag. I posted this anyway because it is still probably useful. The user guide indicates that line-list should be set to none when there a large changes to the text. The on-unfocus function could be useful for other applications. I'm not sure that this strategy will be useful as part of a more general framework but hey, its a start. Regards, Brett. ; ; "Extend" UNFOCUS. Call a function on the face ; that is losing focus. ; if not value? 'unfocus-now [ set 'unfocus-now get 'unfocus unfocus: func ["Removes the current key event focus."] [ if all [ system/view/focal-face in system/view/focal-face 'on-unfocus ] [ system/view/focal-face/on-unfocus system/view/focal-face ] unfocus-now ] ] ; ; Uses the extended UNFOCUS shown above. ; The area (a) is defined with an ON-UNFOCUS function ; that will record where the caret is before focus is ; lost. The button makes use of this extra information ; when system/view/caret is undefined (the original ; face lost focus). view layout [ style area area with [ last-caret: none on-unfocus: func [face] [ face/last-caret: system/view/caret ] ] a: area button "Insert" [ if csr: any [ system/view/caret a/last-caret ] [ csr: insert csr "<inserted>" a/dirty?: true ; indicate modifications a/line-list: none ; if lots of text changed. ] if system/view/caret [ system/view/caret: csr ] show a ] ]