Skip to content

Commit c59b0cc

Browse files
committed
Add refreshing submission list
1 parent 60c9f07 commit c59b0cc

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Default value is `''`.
7272

7373
- 2019/07/27:
7474
+ Support LeetCode China accounts
75-
+ Refresh the problem list with `r`
75+
+ Support refreshing
7676
- 2019/07/23: Support topics and companies
7777

7878
## FAQ

autoload/leetcode.vim

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -680,18 +680,51 @@ function! s:HandleProblemListS() abort
680680
\ line_nr < b:leetcode_problem_end_line
681681
let problem_nr = line_nr - b:leetcode_problem_start_line
682682
let problem_slug = b:leetcode_problems[problem_nr]['slug']
683-
call s:ListSubmissions(problem_slug)
683+
call s:ListSubmissions(problem_slug, 0)
684684
endif
685685
endfunction
686686

687-
function! s:ListSubmissions(slug) abort
687+
function! s:ListSubmissions(slug, refresh) abort
688688
let buf_name = 'leetcode:///submissions/' . a:slug
689689
if buflisted(buf_name)
690690
execute bufnr(buf_name) . 'buffer'
691-
return
692-
endif
693-
694-
execute 'rightbelow new ' . buf_name
691+
if a:refresh
692+
setlocal modifiable
693+
silent! normal! ggdG
694+
else
695+
return
696+
endif
697+
else
698+
execute 'rightbelow new ' . buf_name
699+
setlocal buftype=nofile
700+
setlocal noswapfile
701+
setlocal nobackup
702+
setlocal bufhidden=hide
703+
setlocal nospell
704+
setlocal nonumber
705+
setlocal norelativenumber
706+
setlocal filetype=markdown
707+
nnoremap <silent> <buffer> <return> :call <SID>HandleSubmissionsCR()<cr>
708+
nnoremap <silent> <buffer> r :call <SID>HandleSubmissionsRefresh()<cr>
709+
710+
syn keyword lcAccepted Accepted
711+
syn match lcFailure /Wrong Answer/
712+
syn match lcFailure /Memory Limit Exceeded/
713+
syn match lcFailure /Output Limit Exceeded/
714+
syn match lcFailure /Time Limit Exceeded/
715+
syn match lcFailure /Runtime Error/
716+
syn match lcFailure /Internal Error/
717+
syn match lcFailure /Compile Error/
718+
syn match lcFailure /Unknown Error/
719+
syn match lcFailure /Unknown State/
720+
syn match lcNA /N\/A/
721+
722+
hi! lcAccepted term=bold gui=bold ctermfg=lightgreen guifg=lightgreen
723+
hi! lcFailure term=bold gui=bold ctermfg=red guifg=red
724+
hi! lcNA ctermfg=gray guifg=gray
725+
endif
726+
727+
let b:leetcode_problem_slug = a:slug
695728

696729
let expr = printf('leetcode.get_submissions("%s")', a:slug)
697730
let submissions = py3eval(expr)
@@ -706,34 +739,6 @@ function! s:ListSubmissions(slug) abort
706739
return
707740
endif
708741

709-
setlocal buftype=nofile
710-
setlocal noswapfile
711-
setlocal nobackup
712-
setlocal bufhidden=hide
713-
setlocal nospell
714-
setlocal nonumber
715-
setlocal norelativenumber
716-
setlocal filetype=markdown
717-
nnoremap <silent> <buffer> <return> :call <SID>HandleSubmissionsCR()<cr>
718-
719-
syn keyword lcAccepted Accepted
720-
syn match lcFailure /Wrong Answer/
721-
syn match lcFailure /Memory Limit Exceeded/
722-
syn match lcFailure /Output Limit Exceeded/
723-
syn match lcFailure /Time Limit Exceeded/
724-
syn match lcFailure /Runtime Error/
725-
syn match lcFailure /Internal Error/
726-
syn match lcFailure /Compile Error/
727-
syn match lcFailure /Unknown Error/
728-
syn match lcFailure /Unknown State/
729-
syn match lcNA /N\/A/
730-
731-
hi! lcAccepted term=bold gui=bold ctermfg=lightgreen guifg=lightgreen
732-
hi! lcFailure term=bold gui=bold ctermfg=red guifg=red
733-
hi! lcNA ctermfg=gray guifg=gray
734-
735-
set modifiable
736-
737742
let time_width = s:MaxWidthOfKey(submissions, 'time', 4)
738743
let id_width = s:MaxWidthOfKey(submissions, 'id', 2)
739744
let runtime_width = s:MaxWidthOfKey(submissions, 'runtime', 7)
@@ -742,7 +747,8 @@ function! s:ListSubmissions(slug) abort
742747
call add(output, '# '.problem['title'])
743748
call add(output, '')
744749
call add(output, '## Submissions')
745-
call add(output, ' - return = view submission')
750+
call add(output, ' - <cr> view submission')
751+
call add(output, ' - r refresh')
746752
call add(output, '')
747753
let format = '| %-' . id_width . 'S | %-' . time_width .
748754
\ 'S | %-21S | %-' . runtime_width . 'S |'
@@ -810,6 +816,10 @@ function! s:HandleSubmissionsCR() abort
810816
silent! normal! ggdd
811817
endfunction
812818

819+
function! s:HandleSubmissionsRefresh() abort
820+
call s:ListSubmissions(b:leetcode_problem_slug, 1)
821+
endfunction
822+
813823
function! s:CloseAnyPreview() abort
814824
try
815825
pclose

0 commit comments

Comments
 (0)