From ac816853403bb0d24f842266d91e37376f5e28ef Mon Sep 17 00:00:00 2001 From: BruceSherwood Date: Tue, 1 Feb 2022 11:40:10 -0800 Subject: [PATCH] Simpler fix to menu choices --- labextension/vpython/src/glowcommlab.js | 9 ++------- vpython/vpython_libraries/glowcomm.html | 9 ++------- vpython/vpython_libraries/glowcomm.js | 7 +------ 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/labextension/vpython/src/glowcommlab.js b/labextension/vpython/src/glowcommlab.js index d1bc6f6..8f2f27f 100644 --- a/labextension/vpython/src/glowcommlab.js +++ b/labextension/vpython/src/glowcommlab.js @@ -537,13 +537,8 @@ function decode(data) { vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])] } } else if (textattrs.indexOf(attr) > -1) { - if (attr == 'choices') { // menu choices are wrapped in a list - val = m[3].slice(1, -1) // remove outer brackets - val = val.replace(/'/g, '') // remove quotes - val = val.replace(/, /g, ',') // remove spaces after commas - let s = val.split(',') - val = [] - for (let a of s) { val.push(a) } + if (attr == 'choices') { // menu choices are wrapped in a list + val = m[3].slice(2, -2).split("', '") // choices separated by ', ' } else { // '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '
' val = m[3].replace(/
/g, "\n") diff --git a/vpython/vpython_libraries/glowcomm.html b/vpython/vpython_libraries/glowcomm.html index da47092..1c1f3e0 100644 --- a/vpython/vpython_libraries/glowcomm.html +++ b/vpython/vpython_libraries/glowcomm.html @@ -454,13 +454,8 @@ vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])] } } else if (textattrs.indexOf(attr) > -1) { - if (attr == 'choices') { // menu choices are wrapped in a list - val = m[3].slice(1, -1) // remove outer brackets - val = val.replace(/'/g, '') // remove quotes - val = val.replace(/, /g, ',') // remove spaces after commas - let s = val.split(',') - val = [] - for (let a of s) { val.push(a) } + if (attr == 'choices') { // menu choices are wrapped in a list + val = m[3].slice(2, -2).split("', '") // choices separated by ', ' } else { // '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '
' val = m[3].replace(/
/g, "\n") diff --git a/vpython/vpython_libraries/glowcomm.js b/vpython/vpython_libraries/glowcomm.js index fde6627..2f24dc2 100644 --- a/vpython/vpython_libraries/glowcomm.js +++ b/vpython/vpython_libraries/glowcomm.js @@ -505,12 +505,7 @@ function decode(data) { } } else if (textattrs.indexOf(attr) > -1) { if (attr == 'choices') { // menu choices are wrapped in a list - val = m[3].slice(1, -1) // remove outer brackets - val = val.replace(/'/g, '') // remove quotes - val = val.replace(/, /g, ',') // remove spaces after commas - let s = val.split(',') - val = [] - for (let a of s) { val.push(a) } + val = m[3].slice(2, -2).split("', '") // choices separated by ', ' } else { // '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '
' val = m[3].replace(/
/g, "\n")