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
a0ea5829
Commit
a0ea5829
authored
Jul 01, 2020
by
Evan W. Patton
Committed by
Jeffrey Schiller
Jul 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort component names with numeric suffixes in a saner way
Change-Id: Iffdeec04dd0b1c9e6c9e081ce85d6bc0fd1f9f12
parent
a3318598
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
appinventor/blocklyeditor/src/component_database.js
appinventor/blocklyeditor/src/component_database.js
+19
-2
No files found.
appinventor/blocklyeditor/src/component_database.js
View file @
a0ea5829
...
@@ -112,6 +112,20 @@ Blockly.ComponentDatabase = function() {
...
@@ -112,6 +112,20 @@ Blockly.ComponentDatabase = function() {
this
.
i18nPropertyDescriptions_
=
{};
this
.
i18nPropertyDescriptions_
=
{};
};
};
/**
* Regular expression to split a component name into a prefix and suffix where the suffix contains
* only a numeric value (if any).
*
* Examples:
*
* "Button1" => ["Button", "1"]
* "Nonumber" => ["Nonumber"]
* "Button1Button2" => ["Button1Button", "2"]
*
* @type {!RegExp}
*/
Blockly
.
ComponentDatabase
.
prototype
.
SUFFIX_REGEX
=
new
RegExp
(
'
^(.*?)([0-9]*)$
'
)
/**
/**
* Add a new instance to the ComponentDatabase.
* Add a new instance to the ComponentDatabase.
* @param {!string} uid UUID of the component instance
* @param {!string} uid UUID of the component instance
...
@@ -271,7 +285,8 @@ Blockly.ComponentDatabase.prototype.getComponentNamesByType = function(component
...
@@ -271,7 +285,8 @@ Blockly.ComponentDatabase.prototype.getComponentNamesByType = function(component
for
(
var
uid
in
this
.
instances_
)
{
for
(
var
uid
in
this
.
instances_
)
{
if
(
this
.
instances_
.
hasOwnProperty
(
uid
)
&&
this
.
instances_
[
uid
].
typeName
==
componentType
)
{
if
(
this
.
instances_
.
hasOwnProperty
(
uid
)
&&
this
.
instances_
[
uid
].
typeName
==
componentType
)
{
var
name
=
this
.
instances_
[
uid
].
name
;
var
name
=
this
.
instances_
[
uid
].
name
;
componentNameArray
.
push
([
name
,
name
]);
var
match
=
name
.
match
(
this
.
SUFFIX_REGEX
)
||
[
name
,
'
0
'
];
componentNameArray
.
push
([
name
,
name
,
match
[
1
],
parseInt
(
match
[
2
]
||
'
0
'
,
10
)]);
}
}
}
}
if
(
componentNameArray
.
length
==
0
)
{
if
(
componentNameArray
.
length
==
0
)
{
...
@@ -279,7 +294,9 @@ Blockly.ComponentDatabase.prototype.getComponentNamesByType = function(component
...
@@ -279,7 +294,9 @@ Blockly.ComponentDatabase.prototype.getComponentNamesByType = function(component
}
else
{
}
else
{
// Sort the components by name
// Sort the components by name
componentNameArray
.
sort
(
function
(
a
,
b
)
{
componentNameArray
.
sort
(
function
(
a
,
b
)
{
if
(
a
[
0
]
<
b
[
0
])
{
if
(
a
[
2
]
===
b
[
2
])
{
return
a
[
3
]
-
b
[
3
];
}
else
if
(
a
[
0
]
<
b
[
0
])
{
return
-
1
;
return
-
1
;
}
else
if
(
a
[
0
]
>
b
[
0
])
{
}
else
if
(
a
[
0
]
>
b
[
0
])
{
return
1
;
return
1
;
...
...
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