Skip to content

Commit ac81685

Browse files
committed
Simpler fix to menu choices
1 parent e542dd1 commit ac81685

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

labextension/vpython/src/glowcommlab.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,8 @@ function decode(data) {
537537
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
538538
}
539539
} else if (textattrs.indexOf(attr) > -1) {
540-
if (attr == 'choices') { // menu choices are wrapped in a list
541-
val = m[3].slice(1, -1) // remove outer brackets
542-
val = val.replace(/'/g, '') // remove quotes
543-
val = val.replace(/, /g, ',') // remove spaces after commas
544-
let s = val.split(',')
545-
val = []
546-
for (let a of s) { val.push(a) }
540+
if (attr == 'choices') { // menu choices are wrapped in a list
541+
val = m[3].slice(2, -2).split("', '") // choices separated by ', '
547542
} else {
548543
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
549544
val = m[3].replace(/<br>/g, "\n")

vpython/vpython_libraries/glowcomm.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,8 @@
454454
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
455455
}
456456
} else if (textattrs.indexOf(attr) > -1) {
457-
if (attr == 'choices') { // menu choices are wrapped in a list
458-
val = m[3].slice(1, -1) // remove outer brackets
459-
val = val.replace(/'/g, '') // remove quotes
460-
val = val.replace(/, /g, ',') // remove spaces after commas
461-
let s = val.split(',')
462-
val = []
463-
for (let a of s) { val.push(a) }
457+
if (attr == 'choices') { // menu choices are wrapped in a list
458+
val = m[3].slice(2, -2).split("', '") // choices separated by ', '
464459
} else {
465460
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
466461
val = m[3].replace(/<br>/g, "\n")

vpython/vpython_libraries/glowcomm.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,7 @@ function decode(data) {
505505
}
506506
} else if (textattrs.indexOf(attr) > -1) {
507507
if (attr == 'choices') { // menu choices are wrapped in a list
508-
val = m[3].slice(1, -1) // remove outer brackets
509-
val = val.replace(/'/g, '') // remove quotes
510-
val = val.replace(/, /g, ',') // remove spaces after commas
511-
let s = val.split(',')
512-
val = []
513-
for (let a of s) { val.push(a) }
508+
val = m[3].slice(2, -2).split("', '") // choices separated by ', '
514509
} else {
515510
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
516511
val = m[3].replace(/<br>/g, "\n")

0 commit comments

Comments
 (0)