Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search box #174

Open
wants to merge 7 commits into
base: svg-grouping
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions css/droplet.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@
width: 100%;
/*overflow: hidden;*/
}
.droplet-palette-header {
.droplet-palette-header-wrapper {
z-index: 257;
position: absolute;
top: 0;
left: 0;
width: 100%;
background-color: #FFF;
line-height: 10px;
border-spacing: 4px;
border-bottom: 2px solid #000;
}
.droplet-palette-header {
display: table;
width: 100%;
line-height: 10px;
}
.droplet-palette-header-row {
display: table-row;
Expand Down Expand Up @@ -388,3 +391,15 @@ text {
fill: '#88F'
stroke: '#88F'
}
.droplet-palette-search-wrapper {
height: 30px;
width: 100%;
}
.droplet-palette-search {
width: 100%;
height: 100%;
border-right: none;
border-left: none;
border-top: 1px solid #888;
border-bottom: 1px solid #888;
}
58 changes: 46 additions & 12 deletions src/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ exports.Editor = class Editor

# Main canvas first
@mainCanvas = document.createElementNS SVG_STANDARD, 'svg'
#@mainCanvasWrapper = document.createElementNS SVG_STANDARD, 'g'
#@mainCanvas = document.createElementNS SVG_STANDARD, 'g'
#@mainCanvas.appendChild @mainCanvasWrapper
#@mainCanvasWrapper.appendChild @mainCanvas
@mainCanvas.setAttribute 'class', 'droplet-main-canvas'
@mainCanvas.setAttribute 'shape-rendering', 'optimizeSpeed'

Expand Down Expand Up @@ -372,7 +368,7 @@ exports.Editor = class Editor

# Stop mousedown event default behavior so that
# we don't get bad selections
if event.type is 'mousedown'
if event.type is 'mousedown' and event.target isnt @paletteSearch
event.preventDefault?()
event.returnValue = false
return false
Expand Down Expand Up @@ -782,8 +778,8 @@ Editor::clearPalette = -> # TODO remove and remove all references to

Editor::clearPaletteHighlightCanvas = -> # TODO remove and remove all references to

Editor::redrawPalette = ->
return unless @session?.currentPaletteBlocks?
Editor::redrawPalette = (garbageCollect = true) ->
return unless @session?.activePaletteBlocks?

@clearPalette()

Expand All @@ -795,7 +791,7 @@ Editor::redrawPalette = ->
# of the last bottom edge of a palette block.
lastBottomEdge = PALETTE_TOP_MARGIN

for entry in @session.currentPaletteBlocks
for entry in @session.activePaletteBlocks
# Layout this block
paletteBlockView = @session.paletteView.getViewNodeFor entry.block
paletteBlockView.layout PALETTE_LEFT_MARGIN, lastBottomEdge
Expand All @@ -818,7 +814,10 @@ Editor::redrawPalette = ->

@paletteCanvas.style.height = lastBottomEdge + 'px'

@session.paletteView.garbageCollect()
if garbageCollect
@session.paletteView.garbageCollect()
else
@session.paletteView.cleanupDraw()

Editor::rebuildPalette = ->
return unless @session?.currentPaletteBlocks?
Expand Down Expand Up @@ -1994,11 +1993,38 @@ class FloatingOperation
# This happens at population time.
hook 'populate', 0, ->
# Create the hierarchical menu element.
@paletteHeaderWrapper = document.createElement 'div'
@paletteHeaderWrapper.className = 'droplet-palette-header-wrapper'

@paletteHeader = document.createElement 'div'
@paletteHeader.className = 'droplet-palette-header'

# Append the element.
@paletteElement.appendChild @paletteHeader
@paletteElement.appendChild @paletteHeaderWrapper
@paletteHeaderWrapper.appendChild @paletteHeader

# Search box
@paletteSearchWrapper = document.createElement 'div'
@paletteSearchWrapper.className = 'droplet-palette-search-wrapper'

@paletteSearch = document.createElement 'input'
@paletteSearch.className = 'droplet-palette-search'
@paletteSearch.setAttribute 'placeholder', 'Filter blocks'

@paletteSearch.style.paddingLeft = PALETTE_LEFT_MARGIN
@paletteSearch.style.fontFamily = @session.fontFamily
@paletteSearch.style.fontSize = @session.fontSize

@paletteSearch.addEventListener 'input', =>
@paletteScroller.scrollTop = 0
searchTerm = @paletteSearch.value
@session.activePaletteBlocks = @session.currentPaletteBlocks.filter((block) ->
block.block.stringify().indexOf(searchTerm) >= 0
)
@redrawPalette false

@paletteHeaderWrapper.appendChild @paletteSearchWrapper
@paletteSearchWrapper.appendChild @paletteSearch

if @session?
@setPalette @session.paletteGroups
Expand Down Expand Up @@ -2062,6 +2088,7 @@ Editor::setPalette = (paletteGroups) ->

clickHandler = =>
do updatePalette
@paletteSearch.focus()

paletteGroupHeader.addEventListener 'click', clickHandler
paletteGroupHeader.addEventListener 'touchstart', clickHandler
Expand All @@ -2088,6 +2115,7 @@ Editor::changePaletteGroup = (group) ->
# Record that we are the selected group now
@session.currentPaletteGroup = paletteGroup.name
@session.currentPaletteBlocks = paletteGroup.parsedBlocks
@session.activePaletteBlocks = paletteGroup.parsedBlocks.slice 0
@session.currentPaletteMetadata = paletteGroup.parsedBlocks

# Unapply the "selected" style to the current palette group header
Expand Down Expand Up @@ -2122,7 +2150,7 @@ hook 'mousedown', 6, (point, event, state) ->
state.consumedHitTest = true
return

for entry in @session.currentPaletteBlocks
for entry in @session.activePaletteBlocks
hitTestResult = @hitTest palettePoint, entry.block, @session.paletteView

if hitTestResult?
Expand Down Expand Up @@ -3105,6 +3133,8 @@ Editor::scrollCursorToEndOfDocument = ->

# Pressing the up-arrow moves the cursor up.
hook 'keydown', 0, (event, state) ->
if event.target is @paletteSearch
return
if event.which is UP_ARROW_KEY
@clearLassoSelection()
prev = @getCursor().prev ? @getCursor().start?.prev
Expand Down Expand Up @@ -3161,6 +3191,8 @@ hook 'keydown', 0, (event, state) ->
return
if event.which isnt BACKSPACE_KEY
return
if event.target is @paletteSearch
return
if state.capturedBackspace
return

Expand Down Expand Up @@ -3840,7 +3872,7 @@ Editor::resizeMainScroller = ->
@mainScroller.style.height = "#{@dropletElement.clientHeight}px"

hook 'resize_palette', 0, ->
@paletteScroller.style.top = "#{@paletteHeader.clientHeight}px"
@paletteScroller.style.top = "#{@paletteHeaderWrapper.clientHeight}px"

@session.viewports.palette.height = @paletteScroller.clientHeight
@session.viewports.palette.width = @paletteScroller.clientWidth
Expand Down Expand Up @@ -4687,6 +4719,7 @@ hook 'populate', 1, ->
@redrawMain()

hook 'keydown', 0, (event, state) ->
return if event.target is @paletteSearch
if event.which in command_modifiers
unless @cursorAtSocket()
x = document.body.scrollLeft
Expand All @@ -4699,6 +4732,7 @@ hook 'keydown', 0, (event, state) ->
@copyPasteInput.setSelectionRange 0, @copyPasteInput.value.length

hook 'keyup', 0, (point, event, state) ->
return if event.target is @paletteSearch
if event.which in command_modifiers
if @cursorAtSocket()
@hiddenInput.focus()
Expand Down