[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
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.
; "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 [
in system/view/focal-face 'on-unfocus
; 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 [
on-unfocus: func [face] [
button "Insert" [
if csr: any [
csr: insert csr "<inserted>"
a/dirty?: true ; indicate modifications
a/line-list: none ; if lots of text changed.
if system/view/caret [