Weird behavior of Sketchup::InputPoint#pick() method

Okay I changed it back.

The changed test code ...
class TestTool

  RED ||= Sketchup::Color.new("Red")

  def activate
    @ip = Sketchup::InputPoint.new
    @ip1 = Sketchup::InputPoint.new
    @mode = 0
    @edge = nil
    @vertex = nil
    Sketchup.status_text= "Pick a edge."
  end

  def deactivate(view)
    view.invalidate
  end

  def draw(view)
    view.tooltip= @ip.tooltip
    @ip.draw(view)
    if @mode > 0
      view.drawing_color= RED
      view.draw2d(GL_LINES, @edge.vertices.map(&:position) )
      view.draw_points(@ip1.position, 10, 1, RED) if @ip1.valid?
    end
  end

  def onCancel(reason, view)
    # Restore the vertex and reset the tool:
    view.model.abort_operation if @mode == 2
    deactivate(view)
    activate()
  end

  def onLButtonDown(flags, x, y, view)
    if @mode == 0
      ph = view.pick_helper
      ph.do_pick(x, y)
      @edge = ph.picked_edge
      if @edge
        @mode = 1
        onMouseMove(flags, x, y, view)
      end
    elsif @mode == 1
      @ip1.pick(view, x, y) # Here is the only place to change @ip1
      vertices = @edge.vertices.sort do |a, b|
        a.position.distance(@ip1.position) <=> b.position.distance(@ip1.position)
      end
      @vertex = vertices.first
      # @vertex = @edge.vertices.find { |vertex|
        # vertex.position == @ip1.position
      # }
      if @vertex
        @mode = 2
        view.model.start_operation('Move Vertex')
        onMouseMove(flags, x, y, view)
      end
    elsif @mode == 2
      # Stop moving the vertex and reset the tool:
      view.model.commit_operation
      deactivate(view)
      activate()
    end
  end

  def onMouseMove(flags, x, y, view)
    @ip.pick(view, x, y)

    if @vertex
      pt = @vertex.position
      vector = pt.vector_to(@ip.position)
      tr = Geom::Transformation.translation(vector)
      view.model.active_entities.transform_entities(tr, @vertex)
    end

    if @mode == 0
      Sketchup.status_text= "#{@ip.position.inspect}: Pick a edge."
    elsif @mode == 1
      if @ip1.valid?
        puts "@ip1: #{@ip1.position}"
      else
        Sketchup.status_text= "#{@ip.position.inspect}: Pick a point."
      end
    elsif @mode == 2
      Sketchup.status_text= "#{@ip.position.inspect}: Drag the vertex."
    end

    view.invalidate
  end

  def onSetCursor()
    UI.set_cursor(633) # 633 is Select cursor
  end

end

Sketchup.active_model.select_tool TestTool.new

I do not see this happening. The closest vertex to @ip1 is chosen correctly.

What I do notice is the after picking @ip1 the mouse needs to move a bit before the tool shows the next @mode. Which shows the vertex being dragged.

So to fix this, I added a internal call to onMouseMove(flags, x, y, view) from within the onLButtonDown(flags, x, y, view) method when @vertex is good.