From c9d1b852b55e41a166c73251da2e9a8be09842f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D1=80=D0=B0=D0=B3=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=9B?= Date: Thu, 25 Jan 2024 22:35:18 +0100 Subject: [PATCH] handle paste_and_indent as well if lsp_format_on_paste is enabled --- plugin/documents.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/documents.py b/plugin/documents.py index 72ce043f3..16ddfb181 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -520,12 +520,18 @@ def _on_hover_gutter_async(self, point: int) -> None: on_navigate=lambda href: self._on_navigate(href, point)) def on_text_command(self, command_name: str, args: Optional[dict]) -> Optional[Tuple[str, dict]]: + format_on_paste = self.view.settings().get('lsp_format_on_paste', userprefs().lsp_format_on_paste) if command_name == "auto_complete": self._auto_complete_triggered_manually = True elif command_name == "show_scope_name" and userprefs().semantic_highlighting: session = self.session_async("semanticTokensProvider") if session: return ("lsp_show_scope_name", {}) + elif command_name == 'paste_and_indent' and format_on_paste: + # if `lsp_format_on_paste` is enabled and paste_and_indent is run, + # it is easier to find the region to format when `paste` is invoked, + # so we intercept the `paste_and_indent` and replace it with the `paste` command. + return ('paste', {}) return None def on_post_text_command(self, command_name: str, args: Optional[Dict[str, Any]]) -> None: