From 1580477615c3d14b029fc40904a10dfd31cc99a6 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 7 Mar 2019 05:34:17 +0200 Subject: [PATCH] Put cursor in last line if old position is invalid (#641) --- plugin/black.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/black.vim b/plugin/black.vim index 34f30c5..f0b55b2 100644 --- a/plugin/black.vim +++ b/plugin/black.vim @@ -114,7 +114,10 @@ def Black(): else: cursor = vim.current.window.cursor vim.current.buffer[:] = new_buffer_str.split('\n')[:-1] - vim.current.window.cursor = cursor + try: + vim.current.window.cursor = cursor + except vim.error: + vim.current.window.cursor = (len(vim.current.buffer), 0) print(f'Reformatted in {time.time() - start:.4f}s.') def BlackUpgrade(): -- 2.39.5