Skip to content

Commit

Permalink
Fix #39 - "Buffer with this name already exists"
Browse files Browse the repository at this point in the history
This usually happens when you try to open the Merginal buffer from
another tab.
  • Loading branch information
idanarye committed Jan 30, 2020
1 parent 02ac69b commit 13e8f28
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Support separate Meginal buffers on multiple tabs.

### Changed
- Calling `Merginal` or `MerginalToggle` when the merginal buffer is open but not in the main mode (branch list by default, or changes if in special Git status) will:
- Jump to it, if the user is in another window.
- Change it to the main mode, if the user is in it.

## [2.1.2] - 2020-01-29
### Fixed
Expand Down
7 changes: 6 additions & 1 deletion autoload/merginal.vim
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,10 @@ function! merginal#openMerginalBuffer() abort
if empty(l:mode)
let l:mode = 'branchList'
endif
call merginal#modulelib#createObject(l:mode).openTuiBuffer(-1)
if exists('b:merginal')
let l:targetWindow = winnr()
else
let l:targetWindow = -1
endif
call merginal#modulelib#createObject(l:mode).openTuiBuffer(l:targetWindow)
endfunction
14 changes: 11 additions & 3 deletions autoload/merginal/buffers/base.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ function! s:f.generateBody() dict abort
throw 'generateBody() Not implemented for '.self.name
endfunction

function! s:bufferNameFor(role) abort
if !exists('t:merginal_tabpageUniqueIdentifier')
let t:merginal_tabpageUniqueIdentifier = reltimestr(reltime())
endif
return printf('Merginal:%s:%s', a:role, t:merginal_tabpageUniqueIdentifier)
endfunction

function! s:f.bufferName() dict abort
return 'Merginal:'.self.name
return s:bufferNameFor(self.name)
endfunction

function! s:f.existingWindowNumber() dict abort
return bufwinnr(bufnr(self.bufferName()))
" return bufwinnr(bufnr(self.bufferName()))
" return bufwinnr(bufnr(s:bufferNameFor('*')))
return bufwinnr('Merginal:')
endfunction

function! s:f.gitRun(...) dict abort
Expand Down Expand Up @@ -77,7 +86,6 @@ function! s:f.gitBang(...) dict abort
endtry
endfunction


"Returns 1 if a new window was opened, 0 if it already existed
function! s:f.openTuiBuffer(targetWindow) dict abort
let self.repo = fugitive#repo()
Expand Down
2 changes: 1 addition & 1 deletion doc/merginal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author: Idan Arye <https://github.com/idanarye/>
License: Same terms as Vim itself (see |license|)

Version: 2.1.2
Version: 2.1.2+

INTRODUCTION *merginal*

Expand Down
4 changes: 3 additions & 1 deletion plugin/merginal.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ function! s:toggleBasedOnMergeMode() abort
if l:bufferObject.name == l:mode
call merginal#closeMerginalBuffer()
return
else
elseif l:merginalWindowNumber == winnr()
call l:bufferObject.gotoBuffer(l:mode)
else
execute l:merginalWindowNumber.'wincmd w'
endif
else
call merginal#openMerginalBuffer()
Expand Down

0 comments on commit 13e8f28

Please sign in to comment.