Exemple #1
0
def update(nextState=None):
    start = time.time()
    if FADE.prevent:
        return

    currentWindows = FADE.windows
    currentBuffers = FADE.buffers

    #Check our globals/settings for changes
    status = GLOBALS.update()

    if status & GLOBALS.BASEGROUPS:
        if GLOBALS.enable_basegroups:
            GLOBALS.basegroups_faded = highlighter.fade_names(
                GLOBALS.basegroups)

    if status & GLOBALS.DISABLE_SIGNS:
        unfadeAllSigns()
    elif status & GLOBALS.ERROR:
        return
    if status & GLOBALS.RECALCULATE:
        highlighter.recalculate()
        return
    elif status & GLOBALS.FULL_INVALIDATE:
        highlighter.reset()
        for winState in currentWindows.values():
            if winState.faded:
                unfadeWin(winState)
                winState.faded = False
        for bufferState in currentBuffers.values():
            bufferState.coords = {}

        #TODO remove this code when possible
        #Ideally this return would not be necessary, but oni current requires a hard refresh here
        return
    else:
        #this is a pre check to make sure that highlights have not been wiped (for example by colorscheme changes)
        highlighter.pre_check()

    fade = {}
    unfade = {}

    FADE.startWin = FADE.currentWin = vim.eval('win_getid(' +
                                               str(vim.current.window.number) +
                                               ')')
    activeBuffer = nextState["activeBuffer"]
    activeWindow = nextState['activeWindow']
    activeTab = nextState['activeTab']
    activeDiff = False
    activeScrollbind = False
    nextWindows = {}
    nextBuffers = {}
    fade_signs = []
    unfade_signs = []
    diffs = []
    scrollbinds = []

    FADE.activeBuffer = activeBuffer

    for window in vim.windows:
        winnr = str(window.number)
        bufnr = str(window.buffer.number)
        tabnr = str(window.tabpage.number)
        if activeTab != tabnr:
            continue
        (winid, diff, wrap, buftype, win_disabled, buf_disabled,
         vimade_fade_active, scrollbind, win_syntax, buf_syntax,
         tabstop) = vim.eval(
             '[win_getid(' + winnr + '), gettabwinvar(' + tabnr + ',' + winnr +
             ',"&diff"), gettabwinvar(' + tabnr + ',' + winnr +
             ',"&wrap"), gettabwinvar(' + tabnr + ',' + winnr +
             ',"&buftype"), gettabwinvar(' + tabnr + ',' + winnr +
             ',"vimade_disabled"), getbufvar(' + bufnr +
             ', "vimade_disabled"),  g:vimade_fade_active, gettabwinvar(' +
             tabnr + ',' + winnr + ',"&scrollbind"), gettabwinvar(' + tabnr +
             ',' + winnr + ',"current_syntax"), gettabwinvar(' + tabnr + ',' +
             winnr + ',"&syntax"), gettabwinvar(' + tabnr + ',' + winnr +
             ',"&tabstop")]')
        syntax = win_syntax if win_syntax else buf_syntax
        floating = vim.eval('nvim_win_get_config(' + str(winid) +
                            ')') if HAS_NVIM_WIN_GET_CONFIG else False
        if floating and 'relative' in floating:
            floating = floating['relative']
        else:
            floating = False

        diff = int(diff)
        wrap = int(wrap)
        scrollbind = int(scrollbind)
        vimade_fade_active = int(vimade_fade_active)
        hasActiveBuffer = False if vimade_fade_active else bufnr == activeBuffer
        hasActiveWindow = False if vimade_fade_active else winid == activeWindow

        # window was unhandled -- add to FADE
        if not bufnr in FADE.buffers:
            FADE.buffers[bufnr] = {}
            bufState = FADE.buffers[bufnr] = BufState(bufnr)
        else:
            bufState = FADE.buffers[bufnr]

        if not winid in FADE.windows:
            state = FADE.windows[winid] = WinState(winid, window,
                                                   hasActiveBuffer,
                                                   hasActiveWindow)
            state.syntax = syntax
        else:
            state = FADE.windows[winid]

        state.win = window
        state.name = window.buffer.name
        state.number = winnr
        state.tab = tabnr
        state.diff = diff

        if state.tabstop != tabstop:
            state.tabstop = int(tabstop)

        if (floating
                and not vimade_fade_active) or win_disabled or buf_disabled:
            unfade[winid] = state
            continue

        if syntax != state.syntax:
            state.clear_syntax = state.syntax
            state.syntax = syntax
            if not hasActiveBuffer:
                fade[winid] = state

        state.buftype = buftype

        if state.wrap != wrap:
            state.wrap = wrap
            if not hasActiveWindow:
                fade[winid] = state

        if diff and GLOBALS.group_diff:
            diffs.append(state)
            if hasActiveBuffer:
                activeDiff = True

        if scrollbind and GLOBALS.group_scrollbind:
            scrollbinds.append(state)
            if hasActiveBuffer:
                activeScrollbind = True

        # window state changed
        cursor = window.cursor
        width = window.width
        height = window.height
        if (height != state.height or width != state.width
                or cursor[0] != state.cursor[0]
                or cursor[1] != state.cursor[1]):
            state.height = height
            state.width = width
            state.cursor = (cursor[0], cursor[1])
            if not hasActiveBuffer:
                fade[winid] = state
            state.size_changed = True
        else:
            state.size_changed = False
        if state.buffer != bufnr:
            state.buffer = bufnr
        if state.hasActiveBuffer != hasActiveBuffer:
            state.hasActiveBuffer = hasActiveBuffer
            if hasActiveBuffer:
                unfade[winid] = state
            else:
                fade[winid] = state
        if state.hasActiveWindow != hasActiveWindow:
            state.hasActiveWindow = hasActiveWindow

        if state.faded and hasActiveBuffer:
            unfade[winid] = state
        elif not state.faded and not hasActiveBuffer:
            fade[winid] = state

        if 'coc-explorer' in state.name or 'NERD' in state.name:
            state.is_explorer = True
        if 'minimap' in state.name:
            state.is_minimap = True

            currentBuf = '\n'.join(state.win.buffer)
            #TODO can we add additional buf comparisons and move bufState check out of fadeWin?
            if GLOBALS.fade_minimap:
                if not bufState.faded or currentBuf != bufState.last:
                    bufState.last = currentBuf
                    fade[winid] = state
                    if winid in unfade:
                        del unfade[winid]
            else:
                unfade[winid] = state
                if winid in fade:
                    del fade[winid]

        nextWindows[winid] = state
        nextBuffers[bufnr] = True

    if activeDiff and len(diffs) > 1:
        for state in diffs:
            if state.id in fade:
                del fade[state.id]
            unfade[state.id] = state

    if activeScrollbind and len(scrollbinds) > 1:
        for state in scrollbinds:
            if state.id in fade:
                del fade[state.id]
            unfade[state.id] = state

    for win in fade.values():
        fadeWin(win)
        if GLOBALS.enable_basegroups:
            fadeBase(win)
        if not FADE.buffers[win.buffer].faded:
            fade_signs.append(win)
            FADE.buffers[win.buffer].faded = time.time()
        win.faded = True
    for win in unfade.values():
        if win.faded:
            unfadeWin(win)
            win.faded = False
            if GLOBALS.enable_basegroups:
                unfadeBase(win)
            if not win.buffer in unfade_signs:
                FADE.buffers[win.buffer].faded = 0
                unfade_signs.append(FADE.buffers[win.buffer])

    expr = []
    ids = []
    for win in list(FADE.windows.keys()):
        if not win in nextWindows:
            expr.append('win_id2tabwin(' + win + ')')
            ids.append(win)
    expr = vim.eval('[' + ','.join(expr) + ']')
    i = 0
    for item in expr:
        if item[0] == '0' and item[1] == '0':
            del FADE.windows[ids[i]]
        i += 1

    expr = []
    ids = []
    for key in list(FADE.buffers.keys()):
        if not key in nextBuffers:
            expr.append('win_findbuf(' + key + ')')
            ids.append(key)
    expr = vim.eval('[' + ','.join(expr) + ']')
    i = 0
    for item in expr:
        if len(item) == 0:
            del FADE.buffers[ids[i]]
        i += 1

    if GLOBALS.enable_signs:
        now = time.time()
        signs_retention_period = GLOBALS.signs_retention_period

        sign_buffers = {}
        for win in nextWindows.values():
            bufnr = win.buffer
            if bufnr in buffers and win.faded:
                buf = buffers[bufnr]
                if ((buf.faded and buf.faded != True) or
                    (bufnr in sign_buffers)
                        or win.size_changed) and win not in fade_signs:
                    sign_buffers[bufnr] = True
                    fade_signs.append(win)
                    if signs_retention_period != -1 and (
                            now - buf.faded) * 1000 >= signs_retention_period:
                        buf.faded = True

        if len(fade_signs) or len(unfade_signs):
            if len(fade_signs):
                signs.fade_wins(fade_signs, FADE.buffers)
            signs.unfade_bufs(unfade_signs)
    returnToWin()
    FADE.prevent = False
Exemple #2
0
def unfadeAllSigns():
    currentBuffers = buffers
    if len(currentBuffers):
        signs.unfade_bufs(currentBuffers.values())
Exemple #3
0
def unfadeSigns(bufnr):
    signs.unfade_bufs([bufnr])