|
16 | 16 | 'use strict'; |
17 | 17 |
|
18 | 18 | /* ─── Configuration ──────────────────────────────────────────── */ |
| 19 | +const SAMPLE_SQL_QUERY = |
| 20 | + `-- Sample: move the e-pawn two squares forward\nUPDATE chess_piece\nSET position = 'e4'\nWHERE position = 'e2';`; |
| 21 | + |
19 | 22 | const PIECE_UNICODE = { |
20 | 23 | wK: '♔', wQ: '♕', wR: '♖', wB: '♗', wN: '♘', wP: '♙', |
21 | 24 | bK: '♚', bQ: '♛', bR: '♜', bB: '♝', bN: '♞', bP: '♟', |
@@ -833,8 +836,11 @@ function appendSQL(code, label, moveNum, atEnd) { |
833 | 836 | state.sqlBlocks.push({ code, label, moveNum }); |
834 | 837 |
|
835 | 838 | if (document.getElementById('chkAutoScroll').checked) { |
836 | | - // Scroll to top to reveal the freshly-prepended block |
837 | | - if (!atEnd) { |
| 839 | + if (atEnd) { |
| 840 | + // Game-init block appended at bottom — scroll down to show it |
| 841 | + content.scrollTop = content.scrollHeight; |
| 842 | + } else { |
| 843 | + // Move blocks prepended at top — scroll up to reveal the new block |
838 | 844 | content.scrollTop = 0; |
839 | 845 | } |
840 | 846 | } |
@@ -864,10 +870,9 @@ function startGame(whiteName, blackName, showSQL, existingPGN) { |
864 | 870 | // Clear SQL input and pre-fill with sample query |
865 | 871 | const sqlMoveInput = document.getElementById('sqlMoveInput'); |
866 | 872 | if (sqlMoveInput) { |
867 | | - sqlMoveInput.value = |
868 | | - `-- Sample: move the e-pawn two squares forward\nUPDATE chess_piece\nSET position = 'e4'\nWHERE position = 'e2';`; |
| 873 | + sqlMoveInput.value = SAMPLE_SQL_QUERY; |
869 | 874 | } |
870 | | - state.sqlInputHasTemplate = false; |
| 875 | + state.sqlInputHasTemplate = true; |
871 | 876 | clearSQLRunError(); |
872 | 877 |
|
873 | 878 | // SQL panel visibility |
@@ -1093,10 +1098,9 @@ function init() { |
1093 | 1098 | document.getElementById('btnSampleSQL').addEventListener('click', () => { |
1094 | 1099 | const input = document.getElementById('sqlMoveInput'); |
1095 | 1100 | if (input) { |
1096 | | - input.value = |
1097 | | - `-- Sample: move the e-pawn two squares forward\nUPDATE chess_piece\nSET position = 'e4'\nWHERE position = 'e2';`; |
| 1101 | + input.value = SAMPLE_SQL_QUERY; |
1098 | 1102 | } |
1099 | | - state.sqlInputHasTemplate = false; |
| 1103 | + state.sqlInputHasTemplate = true; |
1100 | 1104 | clearSQLRunError(); |
1101 | 1105 | }); |
1102 | 1106 | document.getElementById('btnClearInput').addEventListener('click', () => { |
|
0 commit comments