aboutsummaryrefslogtreecommitdiffstats
path: root/bundle/prr-ui/autoload/prr_ui.vim
diff options
context:
space:
mode:
authorTeddy Wing2023-12-12 20:07:42 +0100
committerTeddy Wing2023-12-12 23:42:51 +0100
commitcfeee05bb0c327ea3e54ad9846d9eb5da1b443c8 (patch)
tree251fea231218e540f23e2e5f8fafbdb019eca9f9 /bundle/prr-ui/autoload/prr_ui.vim
parentd342a9fde06ca48e8a0ca6dc75859b9417410406 (diff)
downloaddotvim-cfeee05bb0c327ea3e54ad9846d9eb5da1b443c8.tar.bz2
prr-ui: Allow `PrrApprove` and `PrrReject` to be called outside of *.prr
Sometimes I don't have any line comments to make and can go ahead and accept or reject a change immediately. In those cases, I want `PrrApprove` and `PrrReject` to be available in any file type buffer, not just in *.prr buffers. Additionally, those two commands should automatically do `PrrStart` if it hasn't been executed manually before, like we already do with `PrrComment`.
Diffstat (limited to 'bundle/prr-ui/autoload/prr_ui.vim')
-rw-r--r--bundle/prr-ui/autoload/prr_ui.vim59
1 files changed, 54 insertions, 5 deletions
diff --git a/bundle/prr-ui/autoload/prr_ui.vim b/bundle/prr-ui/autoload/prr_ui.vim
index c4e2afa..7b152b7 100644
--- a/bundle/prr-ui/autoload/prr_ui.vim
+++ b/bundle/prr-ui/autoload/prr_ui.vim
@@ -885,6 +885,55 @@ endfunction
function! prr_ui#Comment()
let current_line = getline('.')
+ call prr_ui#SplitPrrBuffer()
+
+ call search(current_line)
+
+ " Put the cursor in place to add a comment on the line.
+ call append('.', ['', '', ''])
+ call cursor(line('.') + 2, 0)
+
+ startinsert
+endfunction
+
+
+function! prr_ui#Approve()
+ " If current buffer is not prr, then PrrStart.
+ if !prr_ui#IsCurrentBufferPrr()
+ call prr_ui#SplitPrrBuffer()
+ endif
+
+ call append(
+ \ 0,
+ \ [
+ \ 'Looks good ' . prr_ui#RandomEmoji(),
+ \ '',
+ \ '@prr approve',
+ \ ''
+ \ ]
+ \ )
+ call cursor(1, 0)
+endfunction
+
+function! prr_ui#Reject()
+ if !prr_ui#IsCurrentBufferPrr()
+ call prr_ui#SplitPrrBuffer()
+ endif
+
+ call append(
+ \ 0,
+ \ [
+ \ '',
+ \ '',
+ \ '@prr reject',
+ \ ''
+ \ ]
+ \ )
+ call cursor(1, 0)
+endfunction
+
+
+function! prr_ui#SplitPrrBuffer()
try
" Open the existing Prr review file in a new split.
sbuffer prr
@@ -893,11 +942,11 @@ function! prr_ui#Comment()
execute 'split ' . prr_path
endtry
- call search(current_line)
+endfunction
- " Put the cursor in place to add a comment on the line.
- call append('.', ['', '', ''])
- call cursor(line('.') + 2, 0)
+function! prr_ui#IsCurrentBufferPrr()
+ let current_buffer_name = bufname()
+ let pos = match(current_buffer_name, '\.prr$')
- startinsert
+ return pos != -1
endfunction