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: ->
@removeClass @constructor.activeClass
@trigger 'clear'
return
externalSearch: (url) ->
if value = @value

@ -48,6 +48,8 @@ class app.views.SearchScope extends app.View
return
selectDoc: (doc) ->
previousDoc = @doc
return if doc is previousDoc
@doc = doc
@tag.textContent = doc.fullName
@ -56,9 +58,14 @@ class app.views.SearchScope extends app.View
@input.removeAttribute 'placeholder'
@input.value = @input.value[@input.selectionStart..]
@input.style.paddingLeft = @tag.offsetWidth + 10 + 'px'
$.trigger @input, 'input'
@trigger 'change', @doc, previousDoc
return
reset: =>
return unless @doc
previousDoc = @doc
@doc = null
@tag.textContent = ''
@ -67,6 +74,9 @@ class app.views.SearchScope extends app.View
@input.setAttribute 'placeholder', @placeholder
@input.style.paddingLeft = ''
@trigger 'change', null, previousDoc
return
onKeydown: (event) =>
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) ->
@openDoc model.doc
@openType model.getType() if model.type
@focus model
@paginateTo model
@scrollTo model
return
focus: (model) ->
@listFocus.focus @find("a[href='#{model.fullPath()}']")
return
revealCurrent: ->
if model = app.router.context.type or app.router.context.entry
@reveal model
@ -128,6 +133,10 @@ class app.views.DocList extends app.View
@listFold.open @find("[data-slug='#{doc.slug}']")
return
closeDoc: (doc) ->
@listFold.close @find("[data-slug='#{doc.slug}']")
return
openType: (type) ->
@listFold.open @lists[type.doc.slug].find("[data-slug='#{type.slug}']")
return

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

Loading…
Cancel
Save