prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  side_by_side should preview files in a side view
  **Describe the bug**
  When using `side_by_side: true` option for commands that support it, if the command opens a quick panel with multiple items, the items open in the main view on changing selection and only on pressing Enter to select an item it opens in the side view. I suppose that it should also show previews in side view like native ST functionality does (for example `shift+primary+f12`).
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Set up keybinding like:
  ```
      {
          "command": "lsp_symbol_type_definition",
          "keys": ["f13"],
          "args": {"side_by_side": true},
          "context": [
              {
                  "key": "lsp.session_with_capability",
                  "operator": "equal",
                  "operand": "typeDefinitionProvider"
              },
              {
                  "key": "auto_complete_visible",
                  "operator": "equal",
                  "operand": false
              }
          ]
      },
  ```
  3. Press F13 on some symbol that is referenced from multiple places
  
  **Expected behavior**
  Changing selection in quick panel should preview the file in a side by side view.
  
  **Environment (please complete the following information):**
  - OS: macOS
  - Sublime Text version: 4134
  
  
  </issue>
  <code>
  [start of plugin/locationpicker.py]
  1 from .core.logging import debug
  2 from .core.protocol import DocumentUri, Location, Position
  3 from .core.protocol import LocationLink
  4 from .core.sessions import Session
  5 from .core.typing import Union, List, Optional, Tuple
  6 from .core.views import get_uri_and_position_from_location
  7 from .core.views import location_to_human_readable
  8 from .core.views import to_encoded_filename
  9 import functools
  10 import sublime
  11 import weakref
  12 
  13 
  14 def open_location_async(session: Session, location: Union[Location, LocationLink], side_by_side: bool) -> None:
  15     flags = sublime.ENCODED_POSITION
  16     if side_by_side:
  17         flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
  18 
  19     def check_success_async(view: Optional[sublime.View]) -> None:
  20         if not view:
  21             sublime.error_message("Unable to open URI")
  22 
  23     session.open_location_async(location, flags).then(check_success_async)
  24 
  25 
  26 def open_basic_file(
  27     session: Session,
  28     uri: str,
  29     position: Position,
  30     flags: int = 0,
  31     group: Optional[int] = None
  32 ) -> None:
  33     filename = session.config.map_server_uri_to_client_path(uri)
  34     if group is None:
  35         group = session.window.active_group()
  36     session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)
  37 
  38 
  39 class LocationPicker:
  40 
  41     def __init__(
  42         self,
  43         view: sublime.View,
  44         session: Session,
  45         locations: Union[List[Location], List[LocationLink]],
  46         side_by_side: bool
  47     ) -> None:
  48         self._view = view
  49         window = view.window()
  50         if not window:
  51             raise ValueError("missing window")
  52         self._window = window
  53         self._weaksession = weakref.ref(session)
  54         self._side_by_side = side_by_side
  55         self._items = locations
  56         manager = session.manager()
  57         base_dir = manager.get_project_path(view.file_name() or "") if manager else None
  58         self._window.show_quick_panel(
  59             items=[location_to_human_readable(session.config, base_dir, location) for location in locations],
  60             on_select=self._select_entry,
  61             on_highlight=self._highlight_entry,
  62             flags=sublime.KEEP_OPEN_ON_FOCUS_LOST
  63         )
  64 
  65     def _unpack(self, index: int) -> Tuple[Optional[Session], Union[Location, LocationLink], DocumentUri, Position]:
  66         location = self._items[index]
  67         uri, position = get_uri_and_position_from_location(location)
  68         return self._weaksession(), location, uri, position
  69 
  70     def _select_entry(self, index: int) -> None:
  71         if index >= 0 and self._view.is_valid():
  72             session, location, uri, position = self._unpack(index)
  73             if not session:
  74                 return
  75             # Note: this has to run on the main thread (and not via open_location_async)
  76             # otherwise the bevior feels weird. It's the only reason why open_basic_file exists.
  77             if uri.startswith("file:"):
  78                 flags = sublime.ENCODED_POSITION
  79                 if self._side_by_side:
  80                     flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
  81                 open_basic_file(session, uri, position, flags)
  82             else:
  83                 sublime.set_timeout_async(functools.partial(open_location_async, session, location, self._side_by_side))
  84         else:
  85             self._window.focus_view(self._view)
  86 
  87     def _highlight_entry(self, index: int) -> None:
  88         session, _, uri, position = self._unpack(index)
  89         if not session:
  90             return
  91         if uri.startswith("file:"):
  92             open_basic_file(session, uri, position, sublime.TRANSIENT | sublime.ENCODED_POSITION)
  93         else:
  94             # TODO: Preview non-file uris?
  95             debug("no preview for", uri)
  96
  [end of plugin/locationpicker.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py
  --- a/plugin/locationpicker.py
  +++ b/plugin/locationpicker.py
  @@ -29,11 +29,11 @@
       position: Position,
       flags: int = 0,
       group: Optional[int] = None
  -) -> None:
  +) -> sublime.View:
       filename = session.config.map_server_uri_to_client_path(uri)
       if group is None:
           group = session.window.active_group()
  -    session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)
  +    return session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)
   
   
   class LocationPicker:
  @@ -53,6 +53,7 @@
           self._weaksession = weakref.ref(session)
           self._side_by_side = side_by_side
           self._items = locations
  +        self._highlighted_view = None  # type: Optional[sublime.View]
           manager = session.manager()
           base_dir = manager.get_project_path(view.file_name() or "") if manager else None
           self._window.show_quick_panel(
  @@ -76,20 +77,35 @@
               # otherwise the bevior feels weird. It's the only reason why open_basic_file exists.
               if uri.startswith("file:"):
                   flags = sublime.ENCODED_POSITION
  -                if self._side_by_side:
  -                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
  -                open_basic_file(session, uri, position, flags)
  +                if not self._side_by_side:
  +                    open_basic_file(session, uri, position, flags)
               else:
                   sublime.set_timeout_async(functools.partial(open_location_async, session, location, self._side_by_side))
           else:
               self._window.focus_view(self._view)
  +            # When in side-by-side mode close the current highlighted
  +            # sheet upon canceling if the sheet is semi-transient
  +            if self._side_by_side and self._highlighted_view:
  +                sheet = self._highlighted_view.sheet()
  +                if sheet and sheet.is_semi_transient():
  +                    self._highlighted_view.close()
   
       def _highlight_entry(self, index: int) -> None:
           session, _, uri, position = self._unpack(index)
           if not session:
               return
           if uri.startswith("file:"):
  -            open_basic_file(session, uri, position, sublime.TRANSIENT | sublime.ENCODED_POSITION)
  +            flags = sublime.ENCODED_POSITION | sublime.FORCE_GROUP
  +            if self._side_by_side:
  +                if self._highlighted_view and self._highlighted_view.is_valid():
  +                    # Replacing the MRU is done relative to the current highlighted sheet
  +                    self._window.focus_view(self._highlighted_view)
  +                    flags |= sublime.REPLACE_MRU | sublime.SEMI_TRANSIENT
  +                else:
  +                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
  +            else:
  +                flags |= sublime.TRANSIENT
  +            self._highlighted_view = open_basic_file(session, uri, position, flags, self._window.active_group())
           else:
               # TODO: Preview non-file uris?
               debug("no preview for", uri)
  
verification_info: {"golden_diff": "diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py\n--- a/plugin/locationpicker.py\n+++ b/plugin/locationpicker.py\n@@ -29,11 +29,11 @@\n     position: Position,\n     flags: int = 0,\n     group: Optional[int] = None\n-) -> None:\n+) -> sublime.View:\n     filename = session.config.map_server_uri_to_client_path(uri)\n     if group is None:\n         group = session.window.active_group()\n-    session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)\n+    return session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)\n \n \n class LocationPicker:\n@@ -53,6 +53,7 @@\n         self._weaksession = weakref.ref(session)\n         self._side_by_side = side_by_side\n         self._items = locations\n+        self._highlighted_view = None  # type: Optional[sublime.View]\n         manager = session.manager()\n         base_dir = manager.get_project_path(view.file_name() or \"\") if manager else None\n         self._window.show_quick_panel(\n@@ -76,20 +77,35 @@\n             # otherwise the bevior feels weird. It's the only reason why open_basic_file exists.\n             if uri.startswith(\"file:\"):\n                 flags = sublime.ENCODED_POSITION\n-                if self._side_by_side:\n-                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT\n-                open_basic_file(session, uri, position, flags)\n+                if not self._side_by_side:\n+                    open_basic_file(session, uri, position, flags)\n             else:\n                 sublime.set_timeout_async(functools.partial(open_location_async, session, location, self._side_by_side))\n         else:\n             self._window.focus_view(self._view)\n+            # When in side-by-side mode close the current highlighted\n+            # sheet upon canceling if the sheet is semi-transient\n+            if self._side_by_side and self._highlighted_view:\n+                sheet = self._highlighted_view.sheet()\n+                if sheet and sheet.is_semi_transient():\n+                    self._highlighted_view.close()\n \n     def _highlight_entry(self, index: int) -> None:\n         session, _, uri, position = self._unpack(index)\n         if not session:\n             return\n         if uri.startswith(\"file:\"):\n-            open_basic_file(session, uri, position, sublime.TRANSIENT | sublime.ENCODED_POSITION)\n+            flags = sublime.ENCODED_POSITION | sublime.FORCE_GROUP\n+            if self._side_by_side:\n+                if self._highlighted_view and self._highlighted_view.is_valid():\n+                    # Replacing the MRU is done relative to the current highlighted sheet\n+                    self._window.focus_view(self._highlighted_view)\n+                    flags |= sublime.REPLACE_MRU | sublime.SEMI_TRANSIENT\n+                else:\n+                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT\n+            else:\n+                flags |= sublime.TRANSIENT\n+            self._highlighted_view = open_basic_file(session, uri, position, flags, self._window.active_group())\n         else:\n             # TODO: Preview non-file uris?\n             debug(\"no preview for\", uri)\n", "issue": "side_by_side should preview files in a side view\n**Describe the bug**\r\nWhen using `side_by_side: true` option for commands that support it, if the command opens a quick panel with multiple items, the items open in the main view on changing selection and only on pressing Enter to select an item it opens in the side view. I suppose that it should also show previews in side view like native ST functionality does (for example `shift+primary+f12`).\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Set up keybinding like:\r\n```\r\n    {\r\n        \"command\": \"lsp_symbol_type_definition\",\r\n        \"keys\": [\"f13\"],\r\n        \"args\": {\"side_by_side\": true},\r\n        \"context\": [\r\n            {\r\n                \"key\": \"lsp.session_with_capability\",\r\n                \"operator\": \"equal\",\r\n                \"operand\": \"typeDefinitionProvider\"\r\n            },\r\n            {\r\n                \"key\": \"auto_complete_visible\",\r\n                \"operator\": \"equal\",\r\n                \"operand\": false\r\n            }\r\n        ]\r\n    },\r\n```\r\n3. Press F13 on some symbol that is referenced from multiple places\r\n\r\n**Expected behavior**\r\nChanging selection in quick panel should preview the file in a side by side view.\r\n\r\n**Environment (please complete the following information):**\r\n- OS: macOS\r\n- Sublime Text version: 4134\r\n\n", "before_files": [{"content": "from .core.logging import debug\nfrom .core.protocol import DocumentUri, Location, Position\nfrom .core.protocol import LocationLink\nfrom .core.sessions import Session\nfrom .core.typing import Union, List, Optional, Tuple\nfrom .core.views import get_uri_and_position_from_location\nfrom .core.views import location_to_human_readable\nfrom .core.views import to_encoded_filename\nimport functools\nimport sublime\nimport weakref\n\n\ndef open_location_async(session: Session, location: Union[Location, LocationLink], side_by_side: bool) -> None:\n    flags = sublime.ENCODED_POSITION\n    if side_by_side:\n        flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT\n\n    def check_success_async(view: Optional[sublime.View]) -> None:\n        if not view:\n            sublime.error_message(\"Unable to open URI\")\n\n    session.open_location_async(location, flags).then(check_success_async)\n\n\ndef open_basic_file(\n    session: Session,\n    uri: str,\n    position: Position,\n    flags: int = 0,\n    group: Optional[int] = None\n) -> None:\n    filename = session.config.map_server_uri_to_client_path(uri)\n    if group is None:\n        group = session.window.active_group()\n    session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)\n\n\nclass LocationPicker:\n\n    def __init__(\n        self,\n        view: sublime.View,\n        session: Session,\n        locations: Union[List[Location], List[LocationLink]],\n        side_by_side: bool\n    ) -> None:\n        self._view = view\n        window = view.window()\n        if not window:\n            raise ValueError(\"missing window\")\n        self._window = window\n        self._weaksession = weakref.ref(session)\n        self._side_by_side = side_by_side\n        self._items = locations\n        manager = session.manager()\n        base_dir = manager.get_project_path(view.file_name() or \"\") if manager else None\n        self._window.show_quick_panel(\n            items=[location_to_human_readable(session.config, base_dir, location) for location in locations],\n            on_select=self._select_entry,\n            on_highlight=self._highlight_entry,\n            flags=sublime.KEEP_OPEN_ON_FOCUS_LOST\n        )\n\n    def _unpack(self, index: int) -> Tuple[Optional[Session], Union[Location, LocationLink], DocumentUri, Position]:\n        location = self._items[index]\n        uri, position = get_uri_and_position_from_location(location)\n        return self._weaksession(), location, uri, position\n\n    def _select_entry(self, index: int) -> None:\n        if index >= 0 and self._view.is_valid():\n            session, location, uri, position = self._unpack(index)\n            if not session:\n                return\n            # Note: this has to run on the main thread (and not via open_location_async)\n            # otherwise the bevior feels weird. It's the only reason why open_basic_file exists.\n            if uri.startswith(\"file:\"):\n                flags = sublime.ENCODED_POSITION\n                if self._side_by_side:\n                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT\n                open_basic_file(session, uri, position, flags)\n            else:\n                sublime.set_timeout_async(functools.partial(open_location_async, session, location, self._side_by_side))\n        else:\n            self._window.focus_view(self._view)\n\n    def _highlight_entry(self, index: int) -> None:\n        session, _, uri, position = self._unpack(index)\n        if not session:\n            return\n        if uri.startswith(\"file:\"):\n            open_basic_file(session, uri, position, sublime.TRANSIENT | sublime.ENCODED_POSITION)\n        else:\n            # TODO: Preview non-file uris?\n            debug(\"no preview for\", uri)\n", "path": "plugin/locationpicker.py"}]}