Skip to content

Commit

Permalink
Merge pull request #176 from lambdalisue/action
Browse files Browse the repository at this point in the history
Vitalize internal modules
  • Loading branch information
lambdalisue authored Aug 23, 2020
2 parents d73afa7 + 79493bb commit 9d79568
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 366 deletions.
13 changes: 13 additions & 0 deletions autoload/fern/action.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let s:Action = vital#fern#import('App.Action')

function! fern#action#_init() abort
call s:Action.init()
endfunction

function! fern#action#call(...) abort
call call(s:Action.call, a:000, s:Action)
endfunction

function! fern#action#list(...) abort
return call(s:Action.list, a:000, s:Action)
endfunction
188 changes: 0 additions & 188 deletions autoload/fern/internal/action.vim

This file was deleted.

63 changes: 18 additions & 45 deletions autoload/fern/internal/locator.vim
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
let s:conditions = [
\ { wi -> !wi.loclist },
\ { wi -> !wi.quickfix },
\ { wi -> !getwinvar(wi.winid, '&winfixwidth', 0) },
\ { wi -> !getwinvar(wi.winid, '&winfixheight', 0) },
\ { wi -> !getbufvar(wi.bufnr, '&previewwindow', 0) },
\]
function! fern#internal#locator#score(winnr) abort
let s:WindowLocator = vital#fern#import('App.WindowLocator')

let winid = win_getid(a:winnr)
let wininfo = getwininfo(winid)
if empty(wininfo)
return 0
endif
let wi = wininfo[0]
let score = 1
for Condition in s:conditions
let score += Condition(wi)
endfor
return score
function! fern#internal#locator#list(...) abort
return call(s:WindowLocator.list, a:000, s:WindowLocator)
endfunction

function! fern#internal#locator#find(origin) abort
let nwinnr = winnr('$')
if nwinnr == 1
return 1
endif
let origin = a:origin == 0 ? winnr() : a:origin
let former = range(origin, winnr('$'))
let latter = reverse(range(1, origin - 1))
let threshold = g:fern#internal#locator#THRESHOLD
while threshold > 0
for winnr in (former + latter)
if fern#internal#locator#score(winnr) >= threshold
return winnr
endif
endfor
let threshold -= 1
endwhile
return 0
function! fern#internal#locator#focus(...) abort
return call(s:WindowLocator.focus, a:000, s:WindowLocator)
endfunction

function! fern#internal#locator#focus(origin) abort
let winnr = fern#internal#locator#find(a:origin)
if winnr == 0 || winnr == winnr()
return 1
endif
call win_gotoid(win_getid(winnr))
function! fern#internal#locator#get_condition(...) abort
return call(s:WindowLocator.get_condition, a:000, s:WindowLocator)
endfunction

let g:fern#internal#locator#THRESHOLD = len(s:conditions) + 1
lockvar g:fern#internal#locator#THRESHOLD
function! fern#internal#locator#set_condition(...) abort
return call(s:WindowLocator.set_condition, a:000, s:WindowLocator)
endfunction

function! fern#internal#locator#get_threshold(...) abort
return call(s:WindowLocator.get_threshold, a:000, s:WindowLocator)
endfunction

function! fern#internal#locator#set_threshold(...) abort
return call(s:WindowLocator.set_threshold, a:000, s:WindowLocator)
endfunction
2 changes: 1 addition & 1 deletion autoload/fern/internal/viewer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function! s:init() abort
call helper.fern.renderer.syntax()
call fern#hook#emit('viewer:syntax', helper)
doautocmd <nomodeline> User FernSyntax
call fern#internal#action#init()
call fern#action#_init()

let Profile = fern#profile#start('fern#internal#viewer:init')
return s:Promise.resolve()
Expand Down
Loading

0 comments on commit 9d79568

Please sign in to comment.