From f4b16f136774cf2d939b4966c26c5c1d67f4e713 Mon Sep 17 00:00:00 2001
From: cschen <camillo.schenone@gmail.com>
Date: Sat, 22 Feb 2025 19:34:57 +0100
Subject: [PATCH] fix whole buffer selection upon attach.

---
 main.py         | 1 +
 plugin/utils.py | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/main.py b/main.py
index 2b6cdcf..9681296 100644
--- a/main.py
+++ b/main.py
@@ -181,6 +181,7 @@ class CodempClientViewEventListener(sublime_plugin.ViewEventListener):
         if self.view == sublime.active_window().active_view():
             logger.debug("closing active view")
             safe_listener_detach(TEXT_LISTENER)  # pyright: ignore
+
         try:
             bid = buffid_from_view(self.view)
             some(self.view.window()).run_command(
diff --git a/plugin/utils.py b/plugin/utils.py
index f767ca5..f1dab6c 100644
--- a/plugin/utils.py
+++ b/plugin/utils.py
@@ -85,6 +85,7 @@ def get_contents(view):
 
 
 def populate_view(view, content):
+    cursorpos = view.sel()[0]
     view.run_command(
         "codemp_replace_text",
         {
@@ -94,6 +95,8 @@ def populate_view(view, content):
             "change_id": None,
         },
     )
+    view.sel().clear()
+    view.sel().add(cursorpos)
 
 
 def view_from_local_path(path):