Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
837b3c83
Commit
837b3c83
authored
Jan 24, 2020
by
Evan W. Patton
Committed by
Susan Rati Lane
Jan 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap typeblock updates in an event group (#1958)
Change-Id: Ife5cf5abdbaa2a0498ed018c4ab7a6398236a2da
parent
efc47714
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
59 deletions
+63
-59
appinventor/blocklyeditor/src/typeblock.js
appinventor/blocklyeditor/src/typeblock.js
+63
-59
No files found.
appinventor/blocklyeditor/src/typeblock.js
View file @
837b3c83
...
...
@@ -484,7 +484,7 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
var
numberMatch
=
numberReg
.
exec
(
blockName
);
var
textReg
=
new
RegExp
(
'
^[
\
"|
\'
]+
'
,
'
g
'
);
var
textMatch
=
textReg
.
exec
(
blockName
);
if
(
numberMatch
&&
numberMatch
.
length
>
0
){
if
(
numberMatch
&&
numberMatch
.
length
>
0
)
{
blockToCreate
=
{
canonicName
:
'
math_number
'
,
dropDown
:
{
...
...
@@ -492,8 +492,7 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
value
:
blockName
}
};
}
else
if
(
textMatch
&&
textMatch
.
length
===
1
){
}
else
if
(
textMatch
&&
textMatch
.
length
===
1
)
{
blockToCreate
=
{
canonicName
:
'
text
'
,
dropDown
:
{
...
...
@@ -501,74 +500,78 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
value
:
blockName
.
substring
(
1
)
}
};
}
else
}
else
{
return
;
// block does not exist: return
}
}
var
blockToCreateName
=
''
;
var
block
;
if
(
blockToCreate
.
dropDown
){
//All blocks should have a dropDown property, even if empty
blockToCreateName
=
blockToCreate
.
canonicName
;
// components have mutator attributes we need to deal with. We can also add these for special blocks
// e.g., this is done for create empty list
if
(
!
goog
.
object
.
isEmpty
(
blockToCreate
.
mutatorAttributes
))
{
//construct xml
var
xmlString
=
'
<xml><block type="
'
+
blockToCreateName
+
'
"><mutation
'
;
for
(
var
attributeName
in
blockToCreate
.
mutatorAttributes
)
{
xmlString
+=
attributeName
+
'
="
'
+
blockToCreate
.
mutatorAttributes
[
attributeName
]
+
'
"
'
;
}
Blockly
.
Events
.
setGroup
(
true
);
try
{
if
(
blockToCreate
.
dropDown
)
{
//All blocks should have a dropDown property, even if empty
blockToCreateName
=
blockToCreate
.
canonicName
;
// components have mutator attributes we need to deal with. We can also add these for special blocks
// e.g., this is done for create empty list
if
(
!
goog
.
object
.
isEmpty
(
blockToCreate
.
mutatorAttributes
))
{
//construct xml
var
xmlString
=
'
<xml><block type="
'
+
blockToCreateName
+
'
"><mutation
'
;
for
(
var
attributeName
in
blockToCreate
.
mutatorAttributes
)
{
xmlString
+=
attributeName
+
'
="
'
+
blockToCreate
.
mutatorAttributes
[
attributeName
]
+
'
"
'
;
}
xmlString
+=
'
>
'
;
xmlString
+=
'
</mutation></block></xml>
'
;
var
xml
=
Blockly
.
Xml
.
textToDom
(
xmlString
);
block
=
Blockly
.
Xml
.
domToBlock
(
xml
.
firstChild
,
self
.
workspace_
);
}
else
{
block
=
self
.
workspace_
.
newBlock
(
blockToCreateName
);
block
.
initSvg
();
//Need to init the block before doing anything else
if
(
block
.
type
&&
(
block
.
type
==
"
procedures_callnoreturn
"
||
block
.
type
==
"
procedures_callreturn
"
))
{
//Need to make sure Procedure Block inputs are updated
Blockly
.
FieldProcedure
.
onChange
.
call
(
block
.
getField
(
"
PROCNAME
"
),
blockToCreate
.
dropDown
.
value
);
xmlString
+=
'
>
'
;
xmlString
+=
'
</mutation></block></xml>
'
;
var
xml
=
Blockly
.
Xml
.
textToDom
(
xmlString
);
block
=
Blockly
.
Xml
.
domToBlock
(
xml
.
firstChild
,
self
.
workspace_
);
}
else
{
block
=
self
.
workspace_
.
newBlock
(
blockToCreateName
);
block
.
initSvg
();
//Need to init the block before doing anything else
if
(
block
.
type
&&
(
block
.
type
==
"
procedures_callnoreturn
"
||
block
.
type
==
"
procedures_callreturn
"
))
{
//Need to make sure Procedure Block inputs are updated
Blockly
.
FieldProcedure
.
onChange
.
call
(
block
.
getField
(
"
PROCNAME
"
),
blockToCreate
.
dropDown
.
value
);
}
}
}
if
(
blockToCreate
.
dropDown
.
titleName
&&
blockToCreate
.
dropDown
.
value
){
block
.
setFieldValue
(
blockToCreate
.
dropDown
.
value
,
blockToCreate
.
dropDown
.
titleName
);
// change type checking for split blocks
if
(
blockToCreate
.
dropDown
.
value
==
'
SPLITATFIRST
'
||
blockToCreate
.
dropDown
.
value
==
'
SPLIT
'
)
{
block
.
getInput
(
"
AT
"
).
setCheck
(
Blockly
.
Blocks
.
Utilities
.
YailTypeToBlocklyType
(
"
text
"
,
Blockly
.
Blocks
.
Utilities
.
INPUT
));
}
else
if
(
blockToCreate
.
dropDown
.
value
==
'
SPLITATFIRSTOFANY
'
||
blockToCreate
.
dropDown
.
value
==
'
SPLITATANY
'
)
{
block
.
getInput
(
"
AT
"
).
setCheck
(
Blockly
.
Blocks
.
Utilities
.
YailTypeToBlocklyType
(
"
list
"
,
Blockly
.
Blocks
.
Utilities
.
INPUT
));
if
(
blockToCreate
.
dropDown
.
titleName
&&
blockToCreate
.
dropDown
.
value
)
{
block
.
setFieldValue
(
blockToCreate
.
dropDown
.
value
,
blockToCreate
.
dropDown
.
titleName
);
// change type checking for split blocks
if
(
blockToCreate
.
dropDown
.
value
==
'
SPLITATFIRST
'
||
blockToCreate
.
dropDown
.
value
==
'
SPLIT
'
)
{
block
.
getInput
(
"
AT
"
).
setCheck
(
Blockly
.
Blocks
.
Utilities
.
YailTypeToBlocklyType
(
"
text
"
,
Blockly
.
Blocks
.
Utilities
.
INPUT
));
}
else
if
(
blockToCreate
.
dropDown
.
value
==
'
SPLITATFIRSTOFANY
'
||
blockToCreate
.
dropDown
.
value
==
'
SPLITATANY
'
)
{
block
.
getInput
(
"
AT
"
).
setCheck
(
Blockly
.
Blocks
.
Utilities
.
YailTypeToBlocklyType
(
"
list
"
,
Blockly
.
Blocks
.
Utilities
.
INPUT
));
}
}
}
else
{
throw
new
Error
(
'
Type Block not correctly set up for:
'
+
blockToCreateName
);
}
}
else
{
throw
new
Error
(
'
Type Block not correctly set up for:
'
+
blockToCreateName
);
}
block
.
render
();
var
blockSelected
=
Blockly
.
selected
;
var
selectedX
,
selectedY
,
selectedXY
;
if
(
blockSelected
)
{
selectedXY
=
blockSelected
.
getRelativeToSurfaceXY
();
selectedX
=
selectedXY
.
x
;
selectedY
=
selectedXY
.
y
;
self
.
connectIfPossible
(
blockSelected
,
block
);
if
(
!
block
.
parentBlock_
){
//Place it close but a bit out of the way from the one we created.
block
.
moveBy
(
Blockly
.
selected
.
getRelativeToSurfaceXY
().
x
+
110
,
Blockly
.
selected
.
getRelativeToSurfaceXY
().
y
+
50
);
block
.
render
();
var
blockSelected
=
Blockly
.
selected
;
var
selectedX
,
selectedY
,
selectedXY
;
if
(
blockSelected
)
{
selectedXY
=
blockSelected
.
getRelativeToSurfaceXY
();
selectedX
=
selectedXY
.
x
;
selectedY
=
selectedXY
.
y
;
self
.
connectIfPossible
(
blockSelected
,
block
);
if
(
!
block
.
parentBlock_
)
{
//Place it close but a bit out of the way from the one we created.
block
.
moveBy
(
Blockly
.
selected
.
getRelativeToSurfaceXY
().
x
+
110
,
Blockly
.
selected
.
getRelativeToSurfaceXY
().
y
+
50
);
}
block
.
select
();
}
else
{
//calculate positions relative to the view and the latest click
var
left
=
self
.
workspace_
.
latestClick
.
x
;
var
top
=
self
.
workspace_
.
latestClick
.
y
;
block
.
moveBy
(
left
,
top
);
block
.
select
();
}
block
.
select
();
}
else
{
//calculate positions relative to the view and the latest click
var
left
=
self
.
workspace_
.
latestClick
.
x
;
var
top
=
self
.
workspace_
.
latestClick
.
y
;
block
.
moveBy
(
left
,
top
);
block
.
select
();
self
.
workspace_
.
requestErrorChecking
(
block
);
self
.
hide
();
self
.
workspace_
.
getParentSvg
().
parentNode
.
focus
();
// refocus workspace div
}
finally
{
Blockly
.
Events
.
setGroup
(
false
);
}
self
.
workspace_
.
requestErrorChecking
(
block
);
self
.
hide
();
self
.
workspace_
.
getParentSvg
().
parentNode
.
focus
();
// refocus workspace div
}
);
};
...
...
@@ -603,6 +606,7 @@ Blockly.TypeBlock.prototype.connectIfPossible = function(blockSelected, createdB
// Only attempt a connection if the input is empty
else
if
(
!
inputList
[
i
].
connection
.
isConnected
())
{
createdBlock
.
previousConnection
.
connect
(
inputList
[
i
].
connection
);
break
;
}
}
catch
(
e
)
{
//We can ignore these exceptions; they happen when connecting two blocks
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment