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

List graphics #38

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix objects without braces, a little bit
dabbler0 committed Mar 11, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0e232bae0abaaec8d8691495bc49c5b3a89866b5
1 change: 0 additions & 1 deletion EMBEDDING.md
Original file line number Diff line number Diff line change
@@ -151,4 +151,3 @@ Each function is associated with a configuration object. It can specify:
- command: true if it's a "command" block that can serve as a top-level statement.
- (specify both value and command if it can be both).
- color: colorname to set the color of the block. If omitted, a default color is chosen.

37 changes: 22 additions & 15 deletions src/coffee.coffee
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
MOSTLY_BLOCK = ['mostly-block']
MOSTLY_VALUE = ['mostly-value']
LIST_WRAPPER = ['list']
OBJ_WRAPPER = ['object', 'list']
BLANK_BLOCK = ['blank-block']
VALUE_ONLY = ['value-only']
LVALUE = ['lvalue']
FORBID_ALL = ['forbid-all']
@@ -500,7 +502,7 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
if node.value.nodeType() is 'Code'
@addCode node.value, depth + 1, indentDepth
else
@csSocketAndMark node.value, depth + 1, 0, indentDepth
@csSocketAndMark node.value, depth + 1, -1, indentDepth

# ### For ###
# Color CONTROL, options sockets @index, @source, @name, @from.
@@ -577,7 +579,7 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
subject = @getParenBase(object)
if subject.nodeType() is 'Value' and subject.base.nodeType() is 'Literal' and
subject.properties?.length in [0, undefined]
@csBlock object, depth + 2, 100, 'blank', null, ANY_DROP
@csBlock object, depth + 2, 100, 'blank', null, BLANK_BLOCK

# See if there is a comma after this object
bounds = @getBounds object
@@ -639,11 +641,7 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
# maybe our View architecture is wrong.
when 'Obj'
@csBlock node, depth, 0, 'violet', wrappingParen, VALUE_ONLY

for property in node.properties
if property.nodeType() is 'Assign'
@csSocketAndMark property.variable, depth + 1, 0, indentDepth, FORBID_ALL
@csSocketAndMark property.value, depth + 1, 0, indentDepth
@csIndentAndMark indentDepth, node.properties, depth + 1, OBJ_WRAPPER


locationsAreIdentical: (a, b) ->
@@ -733,6 +731,9 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
bounds.end.line -= 1
bounds.end.column = @lines[bounds.end.line].length + 1

if node.nodeType() is 'Obj'
bounds.start = @boundMin bounds.start, @getWrappingBounds(node.properties[0], node.properties[node.properties.length - 1]).start

# When we have a 'Value' object,
# its base may have some exceptions in it,
# in which case we want to pass on to
@@ -781,16 +782,23 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
parenWrapped: wrappingParen?
}

# Add an indent node and guess
# at the indent depth
csIndent: (indentDepth, firstNode, lastNode, depth, classes = []) ->
getWrappingBounds: (firstNode, lastNode) ->
first = @getBounds(firstNode).start
last = @getBounds(lastNode).end

if @lines[first.line][...first.column].trim().length is 0
first.line -= 1
first.column = @lines[first.line].length

return {
start: first
end: last
}

# Add an indent node and guess
# at the indent depth
csIndent: (indentDepth, firstNode, lastNode, depth, classes = []) ->
{start: first, end: last} = @getWrappingBounds firstNode, lastNode
if first.line isnt last.line
trueDepth = @lines[last.line].length - @lines[last.line].trimLeft().length
prefix = @lines[last.line][indentDepth...trueDepth]
@@ -799,10 +807,7 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
prefix = ' '

@addIndent {
bounds: {
start: first
end: last
}
bounds: {start: first, end: last}
depth: depth
classes: classes
prefix: prefix
@@ -975,12 +980,14 @@ define ['droplet-helper', 'droplet-model', 'droplet-parser', 'coffee-script'], (
if ('block-only' in block.classes or
'mostly-block' in block.classes or
'any-drop' in block.classes or
'blank-block' in block.classes or
block.type is 'segment') and not ('list' in context.classes)
return helper.ENCOURAGE

else if ('mostly-value' in block.classes or
'value-only' in block.classes or
'any-drop' in block.classes) and
'any-drop' in block.classes or
'blank-block' in block.classes) and
'list' in context.classes
return helper.ENCOURAGE

2 changes: 1 addition & 1 deletion src/parser.coffee
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ define ['droplet-helper', 'droplet-model'], (helper, model) ->
# Construct a handwritten block with the given
# text inside
constructHandwrittenBlock: (text) ->
block = new model.Block 0, 'blank', helper.ANY_DROP, ['Value', 'any-drop']
block = new model.Block 0, 'blank', helper.ANY_DROP, ['Value', 'blank-block']
socket = new model.Socket 0, true
textToken = new model.TextToken text

6 changes: 3 additions & 3 deletions src/view.coffee
Original file line number Diff line number Diff line change
@@ -1279,7 +1279,7 @@ define ['droplet-helper', 'droplet-draw', 'droplet-model'], (helper, draw, model
if @multilineChildrenData[line] is NO_MULTILINE
# Draw the left edge of the bounding box.
left.push new @view.draw.Point bounds.x, bounds.y
if @model.parent? and 'list' in @model.visParent().classes
if @model.parent? and 'list' in @model.visParent().classes and line is 0
left.push new @view.draw.Point bounds.x, (bounds.y + bounds.bottom()) / 2 - BULLET_ARROW_WIDTH
left.push new @view.draw.Point bounds.x + BULLET_ARROW_WIDTH, (bounds.y + bounds.bottom()) / 2
left.push new @view.draw.Point bounds.x, (bounds.y + bounds.bottom()) / 2 + BULLET_ARROW_WIDTH
@@ -1293,7 +1293,7 @@ define ['droplet-helper', 'droplet-draw', 'droplet-model'], (helper, draw, model
if @multilineChildrenData[line] is MULTILINE_START
# Draw the left edge of the bounding box.
left.push new @view.draw.Point bounds.x, bounds.y
if @model.parent? and 'list' in @model.visParent().classes
if @model.parent? and 'list' in @model.visParent().classes and line is 0
left.push new @view.draw.Point bounds.x, (bounds.y + bounds.bottom()) / 2 - BULLET_ARROW_WIDTH
left.push new @view.draw.Point bounds.x + BULLET_ARROW_WIDTH, (bounds.y + bounds.bottom()) / 2
left.push new @view.draw.Point bounds.x, (bounds.y + bounds.bottom()) / 2 + BULLET_ARROW_WIDTH
@@ -1353,7 +1353,7 @@ define ['droplet-helper', 'droplet-draw', 'droplet-model'], (helper, draw, model
unless @multilineChildrenData[line - 1] in [MULTILINE_START, MULTILINE_END_START] and
multilineChild.child.type is 'indent'
right.push new @view.draw.Point multilineBounds.x, multilineBounds.y
if 'list' in multilineChild.child.classes
if 'list' in multilineChild.child.classes and @view.getViewNodeFor(multilineChild.child).lineChildren[line - multilineChild.startLine][0].startLine is line - multilineChild.startLine
right.push new @view.draw.Point multilineBounds.x, (multilineBounds.y + multilineBounds.bottom()) / 2 - BULLET_ARROW_WIDTH
right.push new @view.draw.Point multilineBounds.x + BULLET_ARROW_WIDTH, (multilineBounds.y + multilineBounds.bottom()) / 2
right.push new @view.draw.Point multilineBounds.x, (multilineBounds.y + multilineBounds.bottom()) / 2 + BULLET_ARROW_WIDTH