Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/dncl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ Ruby の `puts` / `gets` は、いままでどおりコンソールのブロッ
- ブロックはプログラムを関数の定義のところでしかスクリプトに分けないので、日本語タブではスクリプトの間に空の行を入れない。
ブロックは空の行を持たないので、日本語で書いた空の行は、ブロックを通ると消える(これまでと同じ)。
- コードタブで足したスクリプトは、並びの最後に入る。
- 日本語タブで実行するときも、ブロックにする Ruby をこの並びで作り直す(`handleExecuteLine`)。関数を先に出す Ruby のままブロックにすると、実行のあとから関数の定義が先頭に移る。
- ルビティー(`genai-ruby-adapter.js`)が読む、エディタに出ていないスプライトの日本語も同じ並びで作る(エディタの日本語と比べるため)。
- 日本語タブに入るとき(ルビータブから・コードタブから)も同じ並びで日本語にする(`ruby-tab.jsx` の `switchLanguage`)。
コードタブから戻るときは、エディタにまだ前の日本語が残っていることがあるので、エディタの中身を読まず、ブロックから作った Ruby を渡して日本語にする
Expand Down
5 changes: 3 additions & 2 deletions packages/scratch-gui/src/containers/ruby-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,6 @@ 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;
Expand All @@ -1355,6 +1353,9 @@ const RubyTab = (props) => {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ 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). 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(program);
await throughCodeTab(driver, 1500);
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.
test('coming back from the Code tab 30 times never falls back to the Ruby tab', async () => {
await openJapaneseTabWith(driver, FUNCTION_AFTER_MAIN);
Expand Down
Loading