@@ -42,6 +42,7 @@ const state = {
4242 pendingPromotion : null , // { from, to } while waiting for user to pick
4343 capturedByWhite : [ ] , // pieces taken by white (black pieces lost)
4444 capturedByBlack : [ ] , // pieces taken by black (white pieces lost)
45+ sqlInputHasTemplate : false , // true while the SQL textarea shows an auto-filled template
4546} ;
4647
4748/* ─── Helpers ─────────────────────────────────────────────────── */
@@ -238,6 +239,7 @@ function fillSQLInputTemplate(sqName, piece) {
238239 `SET position = '???'\n` +
239240 `WHERE position = '${ sqName } '\n` +
240241 ` AND color = '${ color } ';` ;
242+ state . sqlInputHasTemplate = true ;
241243 // Place cursor on the ??? so the user can immediately type the destination
242244 const idx = input . value . indexOf ( '???' ) ;
243245 input . focus ( ) ;
@@ -420,8 +422,9 @@ function executeMove(from, to, promotion) {
420422
421423 // Clear SQL input template after a successful board-click move
422424 const sqlMoveInput = document . getElementById ( 'sqlMoveInput' ) ;
423- if ( sqlMoveInput && sqlMoveInput . value . includes ( '???' ) ) {
425+ if ( sqlMoveInput && state . sqlInputHasTemplate ) {
424426 sqlMoveInput . value = '' ;
427+ state . sqlInputHasTemplate = false ;
425428 clearSQLRunError ( ) ;
426429 }
427430
@@ -787,6 +790,7 @@ function startGame(whiteName, blackName, showSQL, existingPGN) {
787790 state . capturedByWhite = [ ] ;
788791 state . capturedByBlack = [ ] ;
789792 state . pendingPromotion = null ;
793+ state . sqlInputHasTemplate = false ;
790794
791795 // Names in UI
792796 document . getElementById ( 'whitePlayerName' ) . textContent = state . whitePlayer ;
@@ -1020,6 +1024,7 @@ function init() {
10201024 document . getElementById ( 'btnClearInput' ) . addEventListener ( 'click' , ( ) => {
10211025 const input = document . getElementById ( 'sqlMoveInput' ) ;
10221026 if ( input ) input . value = '' ;
1027+ state . sqlInputHasTemplate = false ;
10231028 clearSQLRunError ( ) ;
10241029 } ) ;
10251030 document . getElementById ( 'sqlMoveInput' ) . addEventListener ( 'keydown' , ( e ) => {
0 commit comments