Improve search scope behavior

Closes #360.
pull/359/merge
Thibaut Courouble 9 years ago
parent 8204516b3d
commit cad624613c

@ -94,6 +94,7 @@ class app.views.Search extends app.View
clear: -> clear: ->
@removeClass @constructor.activeClass @removeClass @constructor.activeClass
@trigger 'clear' @trigger 'clear'
return
externalSearch: (url) -> externalSearch: (url) ->
if value = @value if value = @value

@ -48,6 +48,8 @@ class app.views.SearchScope extends app.View
return return
selectDoc: (doc) -> selectDoc: (doc) ->
previousDoc = @doc
return if doc is previousDoc
@doc = doc @doc = doc
@tag.textContent = doc.fullName @tag.textContent = doc.fullName
@ -56,9 +58,14 @@ class app.views.SearchScope extends app.View
@input.removeAttribute 'placeholder' @input.removeAttribute 'placeholder'
@input.value = @input.value[@input.selectionStart..] @input.value = @input.value[@input.selectionStart..]
@input.style.paddingLeft = @tag.offsetWidth + 10 + 'px' @input.style.paddingLeft = @tag.offsetWidth + 10 + 'px'
$.trigger @input, 'input' $.trigger @input, 'input'
@trigger 'change', @doc, previousDoc
return
reset: => reset: =>
return unless @doc
previousDoc = @doc
@doc = null @doc = null
@tag.textContent = '' @tag.textContent = ''
@ -67,6 +74,9 @@ class app.views.SearchScope extends app.View
@input.setAttribute 'placeholder', @placeholder @input.setAttribute 'placeholder', @placeholder
@input.style.paddingLeft = '' @input.style.paddingLeft = ''
@trigger 'change', null, previousDoc
return
onKeydown: (event) => onKeydown: (event) =>
return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey

@ -114,10 +114,15 @@ class app.views.DocList extends app.View
reveal: (model) -> reveal: (model) ->
@openDoc model.doc @openDoc model.doc
@openType model.getType() if model.type @openType model.getType() if model.type
@focus model
@paginateTo model @paginateTo model
@scrollTo model @scrollTo model
return return
focus: (model) ->
@listFocus.focus @find("a[href='#{model.fullPath()}']")
return
revealCurrent: -> revealCurrent: ->
if model = app.router.context.type or app.router.context.entry if model = app.router.context.type or app.router.context.entry
@reveal model @reveal model
@ -128,6 +133,10 @@ class app.views.DocList extends app.View
@listFold.open @find("[data-slug='#{doc.slug}']") @listFold.open @find("[data-slug='#{doc.slug}']")
return return
closeDoc: (doc) ->
@listFold.close @find("[data-slug='#{doc.slug}']")
return
openType: (type) -> openType: (type) ->
@listFold.open @lists[type.doc.slug].find("[data-slug='#{type.slug}']") @listFold.open @lists[type.doc.slug].find("[data-slug='#{type.slug}']")
return return

@ -16,6 +16,8 @@ class app.views.Sidebar extends app.View
@search @search
.on 'searching', @showResults .on 'searching', @showResults
.on 'clear', @showDocList .on 'clear', @showDocList
.scope
.on 'change', @onScopeChange
@results = new app.views.Results @, @search @results = new app.views.Results @, @search
@docList = new app.views.DocList @docList = new app.views.DocList
@ -54,6 +56,12 @@ class app.views.Sidebar extends app.View
reset: -> reset: ->
@showDocList true @showDocList true
return
onScopeChange: (newDoc, previousDoc) =>
@docList.closeDoc(previousDoc) if previousDoc
if newDoc then @docList.reveal(newDoc.toEntry()) else @scrollToTop()
return
saveScrollPosition: -> saveScrollPosition: ->
if @view is @docList if @view is @docList

Loading…
Cancel
Save