back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
authorwenzelm
Mon Mar 17 23:16:26 2014 +0100 (2014-03-17 ago)
changeset 56197416f7a00e4cb
parent 56187 2666cd7d380c
child 56198 21dd034523e5
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
discontinued obsolete option jedit_completion_dismiss_delay (see 750561986828);
more explicit shutdown;
src/Tools/jEdit/etc/options
src/Tools/jEdit/src/completion_popup.scala
     1.1 --- a/src/Tools/jEdit/etc/options	Mon Mar 17 21:56:32 2014 +0100
     1.2 +++ b/src/Tools/jEdit/etc/options	Mon Mar 17 23:16:26 2014 +0100
     1.3 @@ -45,9 +45,6 @@
     1.4  public option jedit_completion_delay : real = 0.5
     1.5    -- "delay for completion popup (seconds)"
     1.6  
     1.7 -public option jedit_completion_dismiss_delay : real = 0.0
     1.8 -  -- "delay for dismissing obsolete completion popup (seconds)"
     1.9 -
    1.10  public option jedit_completion_immediate : bool = false
    1.11    -- "insert unique completion immediately into buffer (if delay = 0)"
    1.12  
     2.1 --- a/src/Tools/jEdit/src/completion_popup.scala	Mon Mar 17 21:56:32 2014 +0100
     2.2 +++ b/src/Tools/jEdit/src/completion_popup.scala	Mon Mar 17 23:16:26 2014 +0100
     2.3 @@ -112,7 +112,7 @@
     2.4        completion_popup match {
     2.5          case Some(completion) =>
     2.6            completion.active_range match {
     2.7 -            case Some((range, _)) if completion.isDisplayable => Some(range)
     2.8 +            case Some(range) if completion.isDisplayable => Some(range)
     2.9              case _ => None
    2.10            }
    2.11          case None => None
    2.12 @@ -236,21 +236,35 @@
    2.13  
    2.14            val items = result.items.map(new Item(_))
    2.15            val completion =
    2.16 -            new Completion_Popup(Some((range, invalidate _)), layered, loc2, font, items)
    2.17 +            new Completion_Popup(Some(range), layered, loc2, font, items)
    2.18              {
    2.19                override def complete(item: Completion.Item) {
    2.20                  PIDE.completion_history.update(item)
    2.21                  insert(item)
    2.22                }
    2.23                override def propagate(evt: KeyEvent) {
    2.24 -                JEdit_Lib.propagate_key(view, evt)
    2.25 +                if (view.getKeyEventInterceptor == inner_key_listener) {
    2.26 +                  try {
    2.27 +                    view.setKeyEventInterceptor(null)
    2.28 +                    JEdit_Lib.propagate_key(view, evt)
    2.29 +                  }
    2.30 +                  finally {
    2.31 +                    if (isDisplayable) view.setKeyEventInterceptor(inner_key_listener)
    2.32 +                  }
    2.33 +                }
    2.34                  if (evt.getID == KeyEvent.KEY_TYPED) input(evt)
    2.35                }
    2.36 -              override def refocus() { text_area.requestFocus }
    2.37 +              override def shutdown(focus: Boolean) {
    2.38 +                if (view.getKeyEventInterceptor == inner_key_listener)
    2.39 +                  view.setKeyEventInterceptor(null)
    2.40 +                if (focus) text_area.requestFocus
    2.41 +                invalidate()
    2.42 +              }
    2.43              }
    2.44            completion_popup = Some(completion)
    2.45 +          view.setKeyEventInterceptor(completion.inner_key_listener)
    2.46            invalidate()
    2.47 -          completion.show_popup()
    2.48 +          completion.show_popup(false)
    2.49          }
    2.50        }
    2.51  
    2.52 @@ -448,10 +462,10 @@
    2.53                    override def propagate(evt: KeyEvent) {
    2.54                      if (!evt.isConsumed) text_field.processKeyEvent(evt)
    2.55                    }
    2.56 -                  override def refocus() { text_field.requestFocus }
    2.57 +                  override def shutdown(focus: Boolean) { if (focus) text_field.requestFocus }
    2.58                  }
    2.59                completion_popup = Some(completion)
    2.60 -              completion.show_popup()
    2.61 +              completion.show_popup(true)
    2.62  
    2.63              case None =>
    2.64            }
    2.65 @@ -506,7 +520,7 @@
    2.66  
    2.67  
    2.68  class Completion_Popup private(
    2.69 -  val active_range: Option[(Text.Range, () => Unit)],
    2.70 +  val active_range: Option[Text.Range],
    2.71    layered: JLayeredPane,
    2.72    location: Point,
    2.73    font: Font,
    2.74 @@ -524,7 +538,7 @@
    2.75  
    2.76    def complete(item: Completion.Item) { }
    2.77    def propagate(evt: KeyEvent) { }
    2.78 -  def refocus() { }
    2.79 +  def shutdown(focus: Boolean) { }
    2.80  
    2.81  
    2.82    /* list view */
    2.83 @@ -568,7 +582,7 @@
    2.84  
    2.85    /* event handling */
    2.86  
    2.87 -  private val inner_key_listener =
    2.88 +  val inner_key_listener =
    2.89      JEdit_Lib.key_listener(
    2.90        key_pressed = (e: KeyEvent) =>
    2.91          {
    2.92 @@ -639,27 +653,16 @@
    2.93      new Popup(layered, completion, screen.relative(layered, size), size)
    2.94    }
    2.95  
    2.96 -  private def show_popup()
    2.97 +  private def show_popup(focus: Boolean)
    2.98    {
    2.99      popup.show
   2.100 -    list_view.requestFocus
   2.101 +    if (focus) list_view.requestFocus
   2.102    }
   2.103  
   2.104 -  private val hide_popup_delay =
   2.105 -    Swing_Thread.delay_last(PIDE.options.seconds("jedit_completion_dismiss_delay")) {
   2.106 -      active_range match { case Some((_, invalidate)) => invalidate() case _ => }
   2.107 -      popup.hide
   2.108 -    }
   2.109 -
   2.110    private def hide_popup()
   2.111    {
   2.112 -    if (list_view.peer.isFocusOwner) refocus()
   2.113 -
   2.114 -    if (PIDE.options.seconds("jedit_completion_dismiss_delay").is_zero) {
   2.115 -      active_range match { case Some((_, invalidate)) => invalidate() case _ => }
   2.116 -      popup.hide
   2.117 -    }
   2.118 -    else hide_popup_delay.invoke()
   2.119 +    shutdown(list_view.peer.isFocusOwner)
   2.120 +    popup.hide
   2.121    }
   2.122  }
   2.123