[3.0] RichTextEdit onKeyPressed: question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[3.0] RichTextEdit onKeyPressed: question

Dean Powell-3
I posted a similar question many moons ago, but through various
circmstances need to re-post.  I apologise in advance...

I have a RichTextEdit tied to the appropriate RichTextPresenter, with
the necessary model set up.  In createSchematicWiring: I say
<<textPresenter when #keyPressed: send #keyPress: to: self.>>

To test, I  pop up the window and move the cursor using one of the
arrow keys.  If I put a self halt message in the keyPress: method, I
notice that the debug box pops up before the cursor position has been
updated.  It looks like the sequence of events is:
   when a Key is Pressed:
      1) fire the onKeyPress event
      2) update the cursor in the RichTextEdit

I actually need the sequence of events to be reversed, as in:
   when a Key is Pressed:
      1) update the cursor
      2) fire the onKeyPress event

Can anyone point me in the right direction?  This is specific to
Dolphin 3, I'm afraid.  I would upgrade, but I got myself into enough
trouble buying the version I have, so no upgrade is in the cards!

Thanks in advance.

Regards,
Dean Powell
Edmonton, Canada


Reply | Threaded
Open this post in threaded view
|

Re: [3.0] RichTextEdit onKeyPressed: question

Ian Bartholomew-4
Dean,

> I actually need the sequence of events to be reversed, as in:
>    when a Key is Pressed:
>       1) update the cursor
>       2) fire the onKeyPress event

One possibility is to fire the event as normal but defer it's evaluation. As
in

YourPresenter>>keyPress: aKeyEvent
    SessionManager inputState queueDeferredAction: [
        self halt]

which allows Windows to update the view before Dolphin evaluates the code in
the block. Another way is to add something like the following method

RichTextEdit>>wmKeyDown: message wParam: wParam lParam: lParam
    | ans |
    ans := super wmKeyDown: message wParam: wParam lParam: lParam.
    self presenter
        trigger: #myKeyPressedEvent:
        with: (KeyEvent
            message: message
            handle: handle
            wParam: wParam
            lParam: lParam).
    ^ans

which performs the update and then triggers a separate event for your
presenter. You may also want to investigate some of the other key events
(#onKeyTyped, #onKeyReleased) as they might behave differently - NB I
haven't tried them, it's just a thought.

RichTextEdits are strange beasties though and behave differently on
different OS/Dolphin combinations. Both of the above appear to work for me
on D4/Win2K - YMMV.

Ian