tamago324 / LeaderF-filer

📂 LeaderF file explorer
Apache License 2.0
39 stars 5 forks source link

Preview window does not open #47

Closed einthusan closed 3 years ago

einthusan commented 3 years ago

Vim8 on MacOS - when trying to get preview to open, an error occurs. Actually, regardless of popup mode or not, it simply wont open. Does it work for you?

error("Vim(let):E484: Can't open file 5")
E353: Nothing in register "

still not sure why... will try and look into it but would be great if you can help. thanks.

einthusan commented 3 years ago

Found the problem. Can you please do this fix yourself because I have some uncommitted changes in my branch. All you need to do is replace your old _previewInPopup function in filerExpl.py with the one found from Leaderf in their source code. I have copy/pasted it below for your reference.

Edit: one more thing, you need to check its not a directory before doing the preview!

def _previewInPopup(self, *args, **kwargs):
        line = args[0]
        if lfEval("bufloaded('%s')" % escQuote(line)) == '1':
            source = int(lfEval("bufadd('%s')" % escQuote(line)))
        else:
            source = line
        self._createPopupPreview(line, source, 0)
einthusan commented 3 years ago

Turns out the preview break once you change directory in my previous example. Below I now have a version that does not break even when you change directories. Also account for not showing preview for folders.

def _previewInPopup(self, *args, **kwargs):
        if len(args) == 0:
            return
        line = args[0]

        # do not show preview for directories
        if line[-1] == "/":
            return

        file = line
        if not os.path.isabs(file):
            file = os.path.join(self._getInstance().getCwd(), lfDecode(file))
            file = os.path.normpath(lfEncode(file))

        if lfEval("bufloaded('%s')" % escQuote(file)) == '1':
            source = int(lfEval("bufadd('%s')" % escQuote(file)))
        else:
            source = file
        self._createPopupPreview(file, source, 0)
tamago324 commented 3 years ago

fixed.