From 922a89c06d13542baa1aa7d28281eff359ca240c Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 18 Nov 2023 21:04:54 +0100 Subject: [PATCH] Resolve old TODO, fix attempt to split 1-length item --- autoload/sj/python.vim | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/autoload/sj/python.vim b/autoload/sj/python.vim index 7cb8d428..e5f0c2f9 100644 --- a/autoload/sj/python.vim +++ b/autoload/sj/python.vim @@ -231,19 +231,18 @@ function! sj#python#JoinAssignment() endfunction function! s:SplitList(regex, opening_char, closing_char) - if sj#SearchUnderCursor(a:regex) <= 0 + let [from, to] = sj#LocateBracesAroundCursor(a:opening_char, a:closing_char, ['pythonString']) + if from < 0 && to < 0 return 0 endif call sj#PushCursor() - " TODO (2012-10-24) connect sj#SearchUnderCursor and sj#LocateBracesOnLine - normal! l - let start = col('.') - normal! h%h - let end = col('.') - - let items = sj#ParseJsonObjectBody(start, end) + let items = sj#ParseJsonObjectBody(from + 1, to - 1) + if len(items) <= 1 + call sj#PopCursor() + return 0 + endif if sj#settings#Read('python_brackets_on_separate_lines') if sj#settings#Read('trailing_comma') @@ -256,7 +255,6 @@ function! s:SplitList(regex, opening_char, closing_char) endif call sj#PopCursor() - call sj#ReplaceMotion('va'.a:opening_char, body) return 1 endfunction