prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Points layer allows panning when in Add mode
  ## 🐛 Bug
  When in the `Add Points` mode on a points layer panning is not prevented. This can make it tricky to label a point as you have to hold the mouse perfectly still.
  
  ![Peek 2021-03-08 13-26](https://user-images.githubusercontent.com/10111092/110364681-111fde80-8012-11eb-8a22-65e5451c87fd.gif)
  
  In contrast the `pick` mode of a labels layer prevents panning.
  
  ## To Reproduce
  1. Open napari
  2. Add a points layer
  3. Move mouse around and then click
  
  Alternatively:
  `python examples/nD_points.py`
  
  ## Expected behavior
  Clicking when in `Add Points` mode will not allow panning, the same as when when in `Pick` mode for a labels layer.
  
  
  ## Environment
  
  ```
  napari: 0.4.7.dev14+gc473058
  Platform: Linux-5.8.0-7630-generic-x86_64-with-glibc2.31
  System: Pop!_OS 20.04 LTS
  Python: 3.9.1 | packaged by conda-forge | (default, Jan 26 2021, 01:34:10) [GCC 9.3.0]
  Qt: 5.15.2
  PyQt5: 5.15.2
  NumPy: 1.19.5
  SciPy: 1.6.0
  Dask: 2021.01.1
  VisPy: 0.6.6
  
  OpenGL:
  - GL version: 4.6 (Compatibility Profile) Mesa 20.2.6
  - MAX_TEXTURE_SIZE: 16384
  
  Screens:
  - screen 1: resolution 1920x1080, scale 1.0
  
  Plugins:
  - console: 0.0.3
  - svg: 0.1.4
  ```
  
  ## Additional context
  
  <!-- Add any other context about the problem here. -->
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `napari/layers/points/_points_mouse_bindings.py`
  Content:
  ```
  1 import numpy as np
  2 
  3 from ._points_utils import points_in_box
  4 
  5 
  6 def select(layer, event):
  7     """Select points.
  8 
  9     Clicking on a point will select that point. If holding shift while clicking
  10     that point will be added to or removed from the existing selection
  11     depending on whether it is selected or not.
  12 
  13     Clicking and dragging a point that is already selected will drag all the
  14     currently selected points.
  15 
  16     Clicking and dragging on an empty part of the canvas (i.e. not on a point)
  17     will create a drag box that will select all points inside it when finished.
  18     Holding shift throughout the entirety of this process will add those points
  19     to any existing selection, otherwise these will become the only selected
  20     points.
  21     """
  22     # on press
  23     modify_selection = (
  24         'Shift' in event.modifiers or 'Control' in event.modifiers
  25     )
  26 
  27     # Get value under the cursor, for points, this is the index of the highlighted
  28     # if any, or None.
  29     value = layer.get_value(event.position, world=True)
  30     # if modifying selection add / remove any from existing selection
  31     if modify_selection:
  32         if value is not None:
  33             layer.selected_data = _toggle_selected(layer.selected_data, value)
  34     else:
  35         if value is not None:
  36             # If the current index is not in the current list make it the only
  37             # index selected, otherwise don't change the selection so that
  38             # the current selection can be dragged together.
  39             if value not in layer.selected_data:
  40                 layer.selected_data = {value}
  41         else:
  42             layer.selected_data = set()
  43     layer._set_highlight()
  44 
  45     yield
  46 
  47     # on move
  48     while event.type == 'mouse_move':
  49         coordinates = layer.world_to_data(event.position)
  50         # If not holding modifying selection and points selected then drag them
  51         if not modify_selection and len(layer.selected_data) > 0:
  52             layer._move(layer.selected_data, coordinates)
  53         else:
  54             coord = [coordinates[i] for i in layer._dims_displayed]
  55             layer._is_selecting = True
  56             if layer._drag_start is None:
  57                 layer._drag_start = coord
  58             layer._drag_box = np.array([layer._drag_start, coord])
  59             layer._set_highlight()
  60         yield
  61 
  62     # on release
  63     layer._drag_start = None
  64     if layer._is_selecting:
  65         layer._is_selecting = False
  66         if len(layer._view_data) > 0:
  67             selection = points_in_box(
  68                 layer._drag_box, layer._view_data, layer._view_size
  69             )
  70             # If shift combine drag selection with existing selected ones
  71             if modify_selection:
  72                 new_selected = layer._indices_view[selection]
  73                 target = set(layer.selected_data).symmetric_difference(
  74                     set(new_selected)
  75                 )
  76                 layer.selected_data = list(target)
  77             else:
  78                 layer.selected_data = layer._indices_view[selection]
  79         else:
  80             layer.selected_data = set()
  81     layer._set_highlight(force=True)
  82 
  83 
  84 def add(layer, event):
  85     """Add a new point at the clicked position."""
  86     # on press
  87     dragged = False
  88     yield
  89 
  90     # on move
  91     while event.type == 'mouse_move':
  92         dragged = True
  93         yield
  94 
  95     # on release
  96     if not dragged:
  97         coordinates = layer.world_to_data(event.position)
  98         layer.add(coordinates)
  99 
  100 
  101 def highlight(layer, event):
  102     """Highlight hovered points."""
  103     layer._set_highlight()
  104 
  105 
  106 def _toggle_selected(selected_data, value):
  107     """Add or remove value from the selected data set.
  108 
  109     Parameters
  110     ----------
  111     selected_data : set
  112         Set of selected data points to be modified.
  113     value : int
  114         Index of point to add or remove from selected data set.
  115 
  116     Returns
  117     -------
  118     set
  119         Modified selected_data set.
  120     """
  121     if value in selected_data:
  122         selected_data.remove(value)
  123     else:
  124         selected_data.add(value)
  125 
  126     return selected_data
  127
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/napari/layers/points/_points_mouse_bindings.py b/napari/layers/points/_points_mouse_bindings.py
  --- a/napari/layers/points/_points_mouse_bindings.py
  +++ b/napari/layers/points/_points_mouse_bindings.py
  @@ -81,19 +81,20 @@
       layer._set_highlight(force=True)
   
   
  +DRAG_DIST_THRESHOLD = 5
  +
  +
   def add(layer, event):
       """Add a new point at the clicked position."""
  -    # on press
  -    dragged = False
  -    yield
   
  -    # on move
  -    while event.type == 'mouse_move':
  -        dragged = True
  +    if event.type == 'mouse_press':
  +        start_pos = event.pos
  +
  +    while event.type != 'mouse_release':
           yield
   
  -    # on release
  -    if not dragged:
  +    dist = np.linalg.norm(start_pos - event.pos)
  +    if dist < DRAG_DIST_THRESHOLD:
           coordinates = layer.world_to_data(event.position)
           layer.add(coordinates)
  
verification_info: {"golden_diff": "diff --git a/napari/layers/points/_points_mouse_bindings.py b/napari/layers/points/_points_mouse_bindings.py\n--- a/napari/layers/points/_points_mouse_bindings.py\n+++ b/napari/layers/points/_points_mouse_bindings.py\n@@ -81,19 +81,20 @@\n     layer._set_highlight(force=True)\n \n \n+DRAG_DIST_THRESHOLD = 5\n+\n+\n def add(layer, event):\n     \"\"\"Add a new point at the clicked position.\"\"\"\n-    # on press\n-    dragged = False\n-    yield\n \n-    # on move\n-    while event.type == 'mouse_move':\n-        dragged = True\n+    if event.type == 'mouse_press':\n+        start_pos = event.pos\n+\n+    while event.type != 'mouse_release':\n         yield\n \n-    # on release\n-    if not dragged:\n+    dist = np.linalg.norm(start_pos - event.pos)\n+    if dist < DRAG_DIST_THRESHOLD:\n         coordinates = layer.world_to_data(event.position)\n         layer.add(coordinates)\n", "issue": "Points layer allows panning when in Add mode\n## \ud83d\udc1b Bug\r\nWhen in the `Add Points` mode on a points layer panning is not prevented. This can make it tricky to label a point as you have to hold the mouse perfectly still.\r\n\r\n![Peek 2021-03-08 13-26](https://user-images.githubusercontent.com/10111092/110364681-111fde80-8012-11eb-8a22-65e5451c87fd.gif)\r\n\r\nIn contrast the `pick` mode of a labels layer prevents panning.\r\n\r\n## To Reproduce\r\n1. Open napari\r\n2. Add a points layer\r\n3. Move mouse around and then click\r\n\r\nAlternatively:\r\n`python examples/nD_points.py`\r\n\r\n## Expected behavior\r\nClicking when in `Add Points` mode will not allow panning, the same as when when in `Pick` mode for a labels layer.\r\n\r\n\r\n## Environment\r\n\r\n```\r\nnapari: 0.4.7.dev14+gc473058\r\nPlatform: Linux-5.8.0-7630-generic-x86_64-with-glibc2.31\r\nSystem: Pop!_OS 20.04 LTS\r\nPython: 3.9.1 | packaged by conda-forge | (default, Jan 26 2021, 01:34:10) [GCC 9.3.0]\r\nQt: 5.15.2\r\nPyQt5: 5.15.2\r\nNumPy: 1.19.5\r\nSciPy: 1.6.0\r\nDask: 2021.01.1\r\nVisPy: 0.6.6\r\n\r\nOpenGL:\r\n- GL version: 4.6 (Compatibility Profile) Mesa 20.2.6\r\n- MAX_TEXTURE_SIZE: 16384\r\n\r\nScreens:\r\n- screen 1: resolution 1920x1080, scale 1.0\r\n\r\nPlugins:\r\n- console: 0.0.3\r\n- svg: 0.1.4\r\n```\r\n\r\n## Additional context\r\n\r\n<!-- Add any other context about the problem here. -->\r\n\n", "before_files": [{"content": "import numpy as np\n\nfrom ._points_utils import points_in_box\n\n\ndef select(layer, event):\n    \"\"\"Select points.\n\n    Clicking on a point will select that point. If holding shift while clicking\n    that point will be added to or removed from the existing selection\n    depending on whether it is selected or not.\n\n    Clicking and dragging a point that is already selected will drag all the\n    currently selected points.\n\n    Clicking and dragging on an empty part of the canvas (i.e. not on a point)\n    will create a drag box that will select all points inside it when finished.\n    Holding shift throughout the entirety of this process will add those points\n    to any existing selection, otherwise these will become the only selected\n    points.\n    \"\"\"\n    # on press\n    modify_selection = (\n        'Shift' in event.modifiers or 'Control' in event.modifiers\n    )\n\n    # Get value under the cursor, for points, this is the index of the highlighted\n    # if any, or None.\n    value = layer.get_value(event.position, world=True)\n    # if modifying selection add / remove any from existing selection\n    if modify_selection:\n        if value is not None:\n            layer.selected_data = _toggle_selected(layer.selected_data, value)\n    else:\n        if value is not None:\n            # If the current index is not in the current list make it the only\n            # index selected, otherwise don't change the selection so that\n            # the current selection can be dragged together.\n            if value not in layer.selected_data:\n                layer.selected_data = {value}\n        else:\n            layer.selected_data = set()\n    layer._set_highlight()\n\n    yield\n\n    # on move\n    while event.type == 'mouse_move':\n        coordinates = layer.world_to_data(event.position)\n        # If not holding modifying selection and points selected then drag them\n        if not modify_selection and len(layer.selected_data) > 0:\n            layer._move(layer.selected_data, coordinates)\n        else:\n            coord = [coordinates[i] for i in layer._dims_displayed]\n            layer._is_selecting = True\n            if layer._drag_start is None:\n                layer._drag_start = coord\n            layer._drag_box = np.array([layer._drag_start, coord])\n            layer._set_highlight()\n        yield\n\n    # on release\n    layer._drag_start = None\n    if layer._is_selecting:\n        layer._is_selecting = False\n        if len(layer._view_data) > 0:\n            selection = points_in_box(\n                layer._drag_box, layer._view_data, layer._view_size\n            )\n            # If shift combine drag selection with existing selected ones\n            if modify_selection:\n                new_selected = layer._indices_view[selection]\n                target = set(layer.selected_data).symmetric_difference(\n                    set(new_selected)\n                )\n                layer.selected_data = list(target)\n            else:\n                layer.selected_data = layer._indices_view[selection]\n        else:\n            layer.selected_data = set()\n    layer._set_highlight(force=True)\n\n\ndef add(layer, event):\n    \"\"\"Add a new point at the clicked position.\"\"\"\n    # on press\n    dragged = False\n    yield\n\n    # on move\n    while event.type == 'mouse_move':\n        dragged = True\n        yield\n\n    # on release\n    if not dragged:\n        coordinates = layer.world_to_data(event.position)\n        layer.add(coordinates)\n\n\ndef highlight(layer, event):\n    \"\"\"Highlight hovered points.\"\"\"\n    layer._set_highlight()\n\n\ndef _toggle_selected(selected_data, value):\n    \"\"\"Add or remove value from the selected data set.\n\n    Parameters\n    ----------\n    selected_data : set\n        Set of selected data points to be modified.\n    value : int\n        Index of point to add or remove from selected data set.\n\n    Returns\n    -------\n    set\n        Modified selected_data set.\n    \"\"\"\n    if value in selected_data:\n        selected_data.remove(value)\n    else:\n        selected_data.add(value)\n\n    return selected_data\n", "path": "napari/layers/points/_points_mouse_bindings.py"}], "after_files": [{"content": "import numpy as np\n\nfrom ._points_utils import points_in_box\n\n\ndef select(layer, event):\n    \"\"\"Select points.\n\n    Clicking on a point will select that point. If holding shift while clicking\n    that point will be added to or removed from the existing selection\n    depending on whether it is selected or not.\n\n    Clicking and dragging a point that is already selected will drag all the\n    currently selected points.\n\n    Clicking and dragging on an empty part of the canvas (i.e. not on a point)\n    will create a drag box that will select all points inside it when finished.\n    Holding shift throughout the entirety of this process will add those points\n    to any existing selection, otherwise these will become the only selected\n    points.\n    \"\"\"\n    # on press\n    modify_selection = (\n        'Shift' in event.modifiers or 'Control' in event.modifiers\n    )\n\n    # Get value under the cursor, for points, this is the index of the highlighted\n    # if any, or None.\n    value = layer.get_value(event.position, world=True)\n    # if modifying selection add / remove any from existing selection\n    if modify_selection:\n        if value is not None:\n            layer.selected_data = _toggle_selected(layer.selected_data, value)\n    else:\n        if value is not None:\n            # If the current index is not in the current list make it the only\n            # index selected, otherwise don't change the selection so that\n            # the current selection can be dragged together.\n            if value not in layer.selected_data:\n                layer.selected_data = {value}\n        else:\n            layer.selected_data = set()\n    layer._set_highlight()\n\n    yield\n\n    # on move\n    while event.type == 'mouse_move':\n        coordinates = layer.world_to_data(event.position)\n        # If not holding modifying selection and points selected then drag them\n        if not modify_selection and len(layer.selected_data) > 0:\n            layer._move(layer.selected_data, coordinates)\n        else:\n            coord = [coordinates[i] for i in layer._dims_displayed]\n            layer._is_selecting = True\n            if layer._drag_start is None:\n                layer._drag_start = coord\n            layer._drag_box = np.array([layer._drag_start, coord])\n            layer._set_highlight()\n        yield\n\n    # on release\n    layer._drag_start = None\n    if layer._is_selecting:\n        layer._is_selecting = False\n        if len(layer._view_data) > 0:\n            selection = points_in_box(\n                layer._drag_box, layer._view_data, layer._view_size\n            )\n            # If shift combine drag selection with existing selected ones\n            if modify_selection:\n                new_selected = layer._indices_view[selection]\n                target = set(layer.selected_data).symmetric_difference(\n                    set(new_selected)\n                )\n                layer.selected_data = list(target)\n            else:\n                layer.selected_data = layer._indices_view[selection]\n        else:\n            layer.selected_data = set()\n    layer._set_highlight(force=True)\n\n\nDRAG_DIST_THRESHOLD = 5\n\n\ndef add(layer, event):\n    \"\"\"Add a new point at the clicked position.\"\"\"\n\n    if event.type == 'mouse_press':\n        start_pos = event.pos\n\n    while event.type != 'mouse_release':\n        yield\n\n    dist = np.linalg.norm(start_pos - event.pos)\n    if dist < DRAG_DIST_THRESHOLD:\n        coordinates = layer.world_to_data(event.position)\n        layer.add(coordinates)\n\n\ndef highlight(layer, event):\n    \"\"\"Highlight hovered points.\"\"\"\n    layer._set_highlight()\n\n\ndef _toggle_selected(selected_data, value):\n    \"\"\"Add or remove value from the selected data set.\n\n    Parameters\n    ----------\n    selected_data : set\n        Set of selected data points to be modified.\n    value : int\n        Index of point to add or remove from selected data set.\n\n    Returns\n    -------\n    set\n        Modified selected_data set.\n    \"\"\"\n    if value in selected_data:\n        selected_data.remove(value)\n    else:\n        selected_data.add(value)\n\n    return selected_data\n", "path": "napari/layers/points/_points_mouse_bindings.py"}]}