@@ -23,6 +23,8 @@ const colours = {
2323 BLK : `black` ,
2424} ;
2525
26+ const SELECTED_COLOUR = `#383838` ;
27+
2628const dateFormats = {
2729 '*MDY' : `mm/dd/yyyy` ,
2830 '*DMY' : `dd/mm/yyyy` ,
@@ -745,7 +747,7 @@ function setActiveField(konvaElement, fieldInfo) {
745747 lastActiveKonvaElement = konvaElement ;
746748
747749 const bg = lastActiveKonvaElement . findOne ( `#bg` ) ;
748- bg . fill ( colours . BLU ) ;
750+ bg . fill ( SELECTED_COLOUR ) ;
749751
750752 updateSelectedFieldSidebar ( fieldInfo ) ;
751753 } else {
@@ -1039,22 +1041,31 @@ function createKeywordPanel(id, inputKeywords, onUpdate) {
10391041
10401042 tree . addEventListener ( 'vsc-run-action' , ( event ) => {
10411043 console . log ( event . detail ) ;
1042- // TODO: check event.action for `delete` and `edit`
1043- // TODO: show UI here and update event.value with changes value
1044-
10451044 /** @type {Keyword } */
10461045 const currentKeyword = event . detail . value ;
1047- editKeyword ( event . detail . value , ( newKeyword ) => {
1048- const oldKeywordIndex = keywords . findIndex ( k => k . name === currentKeyword . name && k . value === currentKeyword . value )
1049- if ( oldKeywordIndex >= 0 ) {
1050- keywords [ oldKeywordIndex ] = newKeyword ;
1051- } else {
1052- keywords . push ( newKeyword ) ;
1053- }
1046+ const oldKeywordIndex = keywords . findIndex ( k => k . name === currentKeyword . name && k . value === currentKeyword . value ) ;
10541047
1055- clearKeywordEditor ( ) ;
1056- rerenderTree ( ) ;
1057- } ) ;
1048+ switch ( event . detail . actionId ) {
1049+ case `delete` :
1050+ if ( oldKeywordIndex >= 0 ) {
1051+ keywords . splice ( oldKeywordIndex , 1 ) ;
1052+ }
1053+ rerenderTree ( ) ;
1054+ break ;
1055+
1056+ case `edit` :
1057+ editKeyword ( ( newKeyword ) => {
1058+ if ( oldKeywordIndex >= 0 ) {
1059+ keywords [ oldKeywordIndex ] = newKeyword ;
1060+ } else {
1061+ keywords . push ( newKeyword ) ;
1062+ }
1063+
1064+ clearKeywordEditor ( ) ;
1065+ rerenderTree ( ) ;
1066+ } , event . detail . value ) ;
1067+ break ;
1068+ }
10581069 } ) ;
10591070
10601071 section . appendChild ( tree ) ;
@@ -1066,9 +1077,17 @@ function createKeywordPanel(id, inputKeywords, onUpdate) {
10661077 newKeyword . innerText = `New Keyword` ;
10671078 newKeyword . style . margin = `1em` ;
10681079 newKeyword . style . display = `block` ;
1069- // TODO: event listener
1080+
1081+ newKeyword . addEventListener ( `click` , ( e ) => {
1082+ editKeyword ( ( newKeyword ) => {
1083+ keywords . push ( newKeyword ) ;
1084+ clearKeywordEditor ( ) ;
1085+ rerenderTree ( ) ;
1086+ } ) ;
1087+ } ) ;
1088+
10701089 const updateButton = document . createElement ( `vscode-button` ) ;
1071- updateButton . innerText = `Change keyword ` ;
1090+ updateButton . innerText = `Update ` ;
10721091
10731092 // Center the button
10741093 updateButton . style . margin = `1em` ;
@@ -1173,10 +1192,10 @@ function clearKeywordEditor() {
11731192}
11741193
11751194/**
1176- * @param {Keyword } keyword
11771195 * @param {(keyword: Keyword) => void } onUpdate
1196+ * @param {Keyword } [keyword]
11781197 */
1179- function editKeyword ( keyword , onUpdate ) {
1198+ function editKeyword ( onUpdate , keyword ) {
11801199 const group = document . createElement ( `vscode-form-group` ) ;
11811200 group . id = `currentKeywordEditor` ;
11821201 group . setAttribute ( `variant` , `vertical` ) ;
@@ -1205,7 +1224,7 @@ function editKeyword(keyword, onUpdate) {
12051224 const options = [ `None` ] ;
12061225
12071226 for ( let i = 1 ; i <= 99 ; i ++ ) {
1208- options . push ( i ) ;
1227+ options . push ( String ( i ) ) ;
12091228 }
12101229
12111230 options . forEach ( option => {
@@ -1234,31 +1253,31 @@ function editKeyword(keyword, onUpdate) {
12341253 } ;
12351254
12361255 group . appendChild ( createLabel ( `Keyword` , `keyword` ) ) ;
1237- group . appendChild ( createInputField ( `keyword` , keyword . name ) ) ;
1256+ group . appendChild ( createInputField ( `keyword` , keyword ? keyword . name : `` ) ) ;
12381257
12391258 group . appendChild ( createLabel ( `Value` , `value` ) ) ;
1240- group . appendChild ( createInputField ( `value` , keyword . value || `` ) ) ;
1259+ group . appendChild ( createInputField ( `value` , keyword ? ( keyword . value || `` ) : `` ) ) ;
12411260
12421261 group . appendChild ( createLabel ( `Indicator 1` , `ind1` ) ) ;
1243- group . appendChild ( createIndicatorSelect ( `ind1` , keyword . conditions [ 0 ] ?. indicator ) ) ;
1262+ group . appendChild ( createIndicatorSelect ( `ind1` , keyword ? keyword . conditions [ 0 ] ?. indicator : undefined ) ) ;
12441263
1245- group . appendChild ( createCheckbox ( `neg1` , `Negate` , keyword . conditions [ 0 ] ?. negate ) ) ;
1264+ group . appendChild ( createCheckbox ( `neg1` , `Negate` , keyword ? keyword . conditions [ 0 ] ?. negate : undefined ) ) ;
12461265
12471266 group . appendChild ( createLabel ( `Indicator 2` , `ind2` ) ) ;
1248- group . appendChild ( createIndicatorSelect ( `ind2` , keyword . conditions [ 1 ] ?. indicator ) ) ;
1267+ group . appendChild ( createIndicatorSelect ( `ind2` , keyword ? keyword . conditions [ 1 ] ?. indicator : undefined ) ) ;
12491268
1250- group . appendChild ( createCheckbox ( `neg2` , `Negate` , keyword . conditions [ 1 ] ?. negate ) ) ;
1269+ group . appendChild ( createCheckbox ( `neg2` , `Negate` , keyword ? keyword . conditions [ 1 ] ?. negate : undefined ) ) ;
12511270
12521271 group . appendChild ( createLabel ( `Indicator 3` , `ind3` ) ) ;
1253- group . appendChild ( createIndicatorSelect ( `ind3` , keyword . conditions [ 2 ] ?. indicator ) ) ;
1272+ group . appendChild ( createIndicatorSelect ( `ind3` , keyword ? keyword . conditions [ 2 ] ?. indicator : undefined ) ) ;
12541273
1255- group . appendChild ( createCheckbox ( `neg3` , `Negate` , keyword . conditions [ 2 ] ?. negate ) ) ;
1274+ group . appendChild ( createCheckbox ( `neg3` , `Negate` , keyword ? keyword . conditions [ 2 ] ?. negate : undefined ) ) ;
12561275
12571276 const button = document . createElement ( `vscode-button` ) ;
12581277 button . setAttribute ( `icon` , `check` ) ;
12591278 button . style . marginTop = `1em` ;
12601279 button . style . display = `block` ;
1261- button . innerText = `Save ` ;
1280+ button . innerText = `Confirm ` ;
12621281 button . onclick = ( ) => {
12631282 const keywordName = group . querySelector ( `#keyword` ) . value ;
12641283 const keywordValue = group . querySelector ( `#value` ) . value ;
0 commit comments