From 6021e1a1bea55d1895e49504fb604740cc406026 Mon Sep 17 00:00:00 2001 From: "smalruby3-editor-bot[bot]" <297607354+smalruby3-editor-bot[bot]@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:09:24 +0000 Subject: [PATCH 1/2] fix(dncl): keep the order of functions after running the japanese program Running in the Japanese tab turned the Ruby of the blocks into blocks again. That Ruby puts the function definitions first, so after a run the functions moved to the top of the program. Run the Ruby in the written order of the scripts instead (rubyInScriptOrder). Closes #2620 Co-Authored-By: Claude Opus 5.5 --- docs/dncl/README.md | 1 + packages/scratch-gui/src/containers/ruby-tab.jsx | 5 +++-- .../integration/dncl-code-tab-script-order.test.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/dncl/README.md b/docs/dncl/README.md index bae6c09139..b4c0558bd6 100644 --- a/docs/dncl/README.md +++ b/docs/dncl/README.md @@ -486,6 +486,7 @@ Ruby の `puts` / `gets` は、いままでどおりコンソールのブロッ - ブロックはプログラムを関数の定義のところでしかスクリプトに分けないので、日本語タブではスクリプトの間に空の行を入れない。 ブロックは空の行を持たないので、日本語で書いた空の行は、ブロックを通ると消える(これまでと同じ)。 - コードタブで足したスクリプトは、並びの最後に入る。 +- 日本語タブで実行するときも、ブロックにする Ruby をこの並びで作り直す(`handleExecuteLine`)。関数を先に出す Ruby のままブロックにすると、実行のあとから関数の定義が先頭に移る。 - ルビティー(`genai-ruby-adapter.js`)が読む、エディタに出ていないスプライトの日本語も同じ並びで作る(エディタの日本語と比べるため)。 - 日本語タブに入るとき(ルビータブから・コードタブから)も同じ並びで日本語にする(`ruby-tab.jsx` の `switchLanguage`)。 コードタブから戻るときは、エディタにまだ前の日本語が残っていることがあるので、エディタの中身を読まず、ブロックから作った Ruby を渡して日本語にする diff --git a/packages/scratch-gui/src/containers/ruby-tab.jsx b/packages/scratch-gui/src/containers/ruby-tab.jsx index ff1296f82b..c36ab84266 100644 --- a/packages/scratch-gui/src/containers/ruby-tab.jsx +++ b/packages/scratch-gui/src/containers/ruby-tab.jsx @@ -1345,11 +1345,12 @@ const RubyTab = (props) => { clearErrors(); - const code = rubyCode.code; - // In DNCL mode, execute all top-level scripts from top to bottom // instead of just the cursor line. const isDncl = dnclModeRef.current; + // The Ruby made from the blocks puts the function definitions first: run the program + // in the order it was written, or the blocks take that order (Issue #2620). + const code = isDncl ? rubyInScriptOrder(rubyCode.target, rubyCode.code, rubyVersion) : rubyCode.code; // The Ruby lacks the Japanese lines with an error: stop as the green flag does (Issue #2560). if (isDncl && dnclEditErrorRef.current) { onShowAlert('convertJapaneseError'); diff --git a/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js b/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js index a4c339a287..01313ea9f4 100644 --- a/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js +++ b/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js @@ -109,6 +109,18 @@ describe('The Japanese tab after the Code tab (Issue #2577)', () => { expect(await getEditorValue(driver)).toBe(FUNCTIONS_BETWEEN_CALLS); }); + // Running takes the Ruby the blocks give back, which puts the function definitions first: the + // run must keep the written order (Issue #2620). + test('running after the Code tab keeps the order of the functions', async () => { + await openJapaneseTabWith(driver, FUNCTIONS_BETWEEN_CALLS); + await throughCodeTab(driver, 1500); + await clickByTestId(driver, 'ruby-toolbar-execute'); + await pause(2000); + expect(await getEditorValue(driver)).toBe(FUNCTIONS_BETWEEN_CALLS); + await throughCodeTab(driver, 1500); + expect(await getEditorValue(driver)).toBe(FUNCTIONS_BETWEEN_CALLS); + }); + // 30 round trips take about a minute, longer on a slow CI runner than the 95 s of the helper. test('coming back from the Code tab 30 times never falls back to the Ruby tab', async () => { await openJapaneseTabWith(driver, FUNCTION_AFTER_MAIN); From 3a213e6cdac573e1e1f800685fcb25c0dc6543a0 Mon Sep 17 00:00:00 2001 From: "smalruby3-editor-bot[bot]" <297607354+smalruby3-editor-bot[bot]@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:32:20 +0000 Subject: [PATCH 2/2] test(dncl): run a program with a list after the code tab too The issue was not seen with short programs without a list, so the run test also uses the program with a list. Make the ordered Ruby only after the check of the Japanese lines with an error. Refs #2620 Co-Authored-By: Claude Opus 5.5 --- packages/scratch-gui/src/containers/ruby-tab.jsx | 6 +++--- .../integration/dncl-code-tab-script-order.test.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/scratch-gui/src/containers/ruby-tab.jsx b/packages/scratch-gui/src/containers/ruby-tab.jsx index c36ab84266..38d1a2e012 100644 --- a/packages/scratch-gui/src/containers/ruby-tab.jsx +++ b/packages/scratch-gui/src/containers/ruby-tab.jsx @@ -1348,14 +1348,14 @@ const RubyTab = (props) => { // In DNCL mode, execute all top-level scripts from top to bottom // instead of just the cursor line. const isDncl = dnclModeRef.current; - // The Ruby made from the blocks puts the function definitions first: run the program - // in the order it was written, or the blocks take that order (Issue #2620). - const code = isDncl ? rubyInScriptOrder(rubyCode.target, rubyCode.code, rubyVersion) : rubyCode.code; // The Ruby lacks the Japanese lines with an error: stop as the green flag does (Issue #2560). if (isDncl && dnclEditErrorRef.current) { onShowAlert('convertJapaneseError'); return; } + // The Ruby made from the blocks puts the function definitions first: run the program + // in the order it was written, or the blocks take that order (Issue #2620). + const code = isDncl ? rubyInScriptOrder(rubyCode.target, rubyCode.code, rubyVersion) : rubyCode.code; // Running shows the read mode, to follow the program by the line numbers (Issue #2380). if (isDncl && problemFormViewRef.current) problemFormViewRef.current.showReadMode(); const targetLine = isDncl ? 1 : findExecutableLine(code, lineNumber); diff --git a/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js b/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js index 01313ea9f4..af1a7d85ee 100644 --- a/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js +++ b/packages/scratch-gui/test/integration/dncl-code-tab-script-order.test.js @@ -110,15 +110,19 @@ describe('The Japanese tab after the Code tab (Issue #2577)', () => { }); // Running takes the Ruby the blocks give back, which puts the function definitions first: the - // run must keep the written order (Issue #2620). - test('running after the Code tab keeps the order of the functions', async () => { - await openJapaneseTabWith(driver, FUNCTIONS_BETWEEN_CALLS); + // run must keep the written order (Issue #2620). The issue was not seen with short programs + // without a list, so a program with a list is run too. + test.each([ + ['two functions between the calls', FUNCTIONS_BETWEEN_CALLS], + ['a list and a function after the main program', FUNCTION_AFTER_MAIN], + ])('running after the Code tab keeps the order of the functions (%s)', async (_name, program) => { + await openJapaneseTabWith(driver, program); await throughCodeTab(driver, 1500); await clickByTestId(driver, 'ruby-toolbar-execute'); await pause(2000); - expect(await getEditorValue(driver)).toBe(FUNCTIONS_BETWEEN_CALLS); + expect(await getEditorValue(driver)).toBe(program); await throughCodeTab(driver, 1500); - expect(await getEditorValue(driver)).toBe(FUNCTIONS_BETWEEN_CALLS); + expect(await getEditorValue(driver)).toBe(program); }); // 30 round trips take about a minute, longer on a slow CI runner than the 95 s of the helper.