-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from lambdalisue/action
Vitalize internal modules
- Loading branch information
Showing
11 changed files
with
507 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.