Skip to content

Commit

Permalink
Reuse exisiting buffer to solve double buffer problem da-h#25
Browse files Browse the repository at this point in the history
  • Loading branch information
dmadisetti committed May 6, 2023
1 parent d3f621b commit 40e6849
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 17 additions & 6 deletions rplugin/python3/airlatex/documentbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,37 @@ def __init__(self, path, nvim):
self.buffer_mutex = RLock()
self.saved_buffer = None

def getName(self):
return "/".join([p["name"] for p in self.path])
def getExt(self):
return self.document["name"].split(".")[-1]
@staticmethod
def getName(path):
return "/".join([p["name"] for p in path])

@staticmethod
def getExt(document):
return document["name"].split(".")[-1]

@property
def name(self):
return DocumentBuffer.getName(self.path)

@property
def ext(self):
return DocumentBuffer.getExt(self.document)

def initDocumentBuffer(self):
self.log.debug_gui("initDocumentBuffer")

# Creating new Buffer
self.nvim.command('wincmd w')
self.nvim.command('enew')
self.nvim.command('file '+ self.getName())
self.nvim.command('file '+ self.name)
self.buffer = self.nvim.current.buffer
DocumentBuffer.allBuffers[self.buffer] = self

# Buffer Settings
self.nvim.command("syntax on")
self.nvim.command('setlocal noswapfile')
self.nvim.command('setlocal buftype=nofile')
self.nvim.command("set filetype="+self.getExt())
self.nvim.command("set filetype=" + self.ext)

# ??? Returning normal function to these buttons
# self.nvim.command("nmap <silent> <up> <up>")
Expand Down
9 changes: 9 additions & 0 deletions rplugin/python3/airlatex/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,14 @@ def cursorAction(self, key="enter"):

# is file
elif self.cursorPos[-1]["type"] == "file":
name = DocumentBuffer.getName(self.cursorPos)
for buffer, document in DocumentBuffer.allBuffers.items():
self.log.debug_gui("{name} vs {document.name}")
if name == document.name:
self.nvim.command('wincmd w')
self.nvim.command('enew')
self.nvim.command(f'buffer {buffer.number}')
return
documentbuffer = DocumentBuffer(self.cursorPos, self.nvim)
create_task(self.cursorPos[0]["handler"].joinDocument(documentbuffer))

0 comments on commit 40e6849

Please sign in to comment.