Index: /trunk/ccl/examples/cocoa-editor.lisp
===================================================================
--- /trunk/ccl/examples/cocoa-editor.lisp	(revision 677)
+++ /trunk/ccl/examples/cocoa-editor.lisp	(revision 678)
@@ -413,12 +413,5 @@
 	(hemlock-ext::make-key-event c bits)))))
 
-;;; Process a key-down NSEvent in a lisp text view by translating it
-;;; into a Hemlock key event and passing it into the Hemlock command
-;;; interpreter.  The underlying buffer becomes Hemlock's current buffer
-;;; and the containing pane becomes Hemlock's current window when the
-;;; command is processed.  Use the frame's command state object.
-
-(define-objc-method ((:void :key-down event)
-		     hemlock-text-view)
+(defun pass-key-down-event-to-hemlock (self event)
   #+debug
   (#_NSLog #@"Key down event = %@" :address event)
@@ -440,8 +433,18 @@
 		     (hi::*echo-area-stream*
 		      (hemlock-frame-echo-area-stream w))
-		     (hi::*echo-area-window* hi::*current-window*)
+		     (hi::*echo-area-window* (slot-value w 'echo-area-view ))
 		     (hi::*echo-area-region*
 		      (hi::buffer-region hi::*echo-area-buffer*)))
 		(hi::interpret-key-event key-event info)))))))))
+  
+;;; Process a key-down NSEvent in a lisp text view by translating it
+;;; into a Hemlock key event and passing it into the Hemlock command
+;;; interpreter.  The underlying buffer becomes Hemlock's current buffer
+;;; and the containing pane becomes Hemlock's current window when the
+;;; command is processed.  Use the frame's command state object.
+
+(define-objc-method ((:void :key-down event)
+		     hemlock-text-view)
+  (pass-key-down-event-to-hemlock self event))
 
 ;;; Update the underlying buffer's point.  Should really set the
@@ -692,7 +695,17 @@
 
 
+(defmethod hi::activate-hemlock-view ((view text-pane))
+  (let* ((hemlock-frame (send view 'window))
+	 (text-view (text-pane-text-view view)))
+    (send hemlock-frame :make-first-responder text-view)))
+
+
 (defclass echo-area-view (ns:ns-text-view)
     ()
   (:metaclass ns:+ns-object))
+
+(defmethod hi::activate-hemlock-view ((view echo-area-view))
+  (let* ((hemlock-frame (send view 'window)))
+    (send hemlock-frame :make-first-responder view)))
 
 ;;; The "document" for an echo-area isn't a real NSDocument.
@@ -704,4 +717,7 @@
   (declare (ignore change)))
 
+(define-objc-method ((:void :key-down event)
+		     echo-area-view)
+  (pass-key-down-event-to-hemlock self event))
 
 
@@ -1221,5 +1237,9 @@
         (send textview :page-up nil)))))
 
-      
+(defun hi::get-key-event (text-view ignore)
+  (declare (ignore ignore))
+  (let* ((event (send (send text-view 'window)
+		      :next-event-matching-mask #$NSKeyDownMask)))
+    (nsevent-to-key-event event)))
 
 (provide "COCOA-EDITOR")
