From 9e7d22312d399d3f892afc96f131680ce3945d76 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:39:20 +0000 Subject: [PATCH 1/2] fix(dncl): show the console after reloading in the Japanese mode The console was shown only when the Japanese tab was active, so a reload in the Code tab of the Japanese mode showed the stage. Show it in every tab but the Ruby tab while the program is written in Japanese (not in a lesson that does not allow it). Closes #2628 Co-Authored-By: Claude Opus 5.5 --- docs/extension-smalruby-console/README.md | 4 ++ .../scratch-gui/src/containers/ruby-tab.jsx | 23 ++++++---- .../scratch-gui/src/lib/smalruby-console.js | 23 +++++++++- .../test/unit/lib/smalruby-console.test.js | 45 ++++++++++++++++++- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/docs/extension-smalruby-console/README.md b/docs/extension-smalruby-console/README.md index 72374de14d..de17dd34bd 100644 --- a/docs/extension-smalruby-console/README.md +++ b/docs/extension-smalruby-console/README.md @@ -44,6 +44,10 @@ Scratch には「言う」「聞いて待つ」しかないが、日本語のプ `showSmalrubyConsole(dispatch)` / `hideSmalrubyConsole(dispatch)` を呼ぶ)。人が隠したこと(ボタン・ [ステージにもどる])は Redux の `hiddenByUser` に残り、`showSmalrubyConsole` はそれを上書きしない (コードタブから戻っても隠したまま)。`hideSmalrubyConsole`(ルビータブ)はこれを忘れる。 +- 日本語モードのあいだ(最後に開いた文字のタブが日本語タブ)は、ルビータブ以外のどのタブでもコンソールを既定にする + (`shouldShowSmalrubyConsoleByDefault`)。そのため、コードタブのままブラウザを読み込み直しても、コンソールが出る。 + `hiddenByUser` は作品に保存しないので、読み込み直すと、人が隠していたコンソールもまた出る。 + 日本語モードを許さないレッスンでは出さない。 - 日本語タブを開いても、出すのは**コンソールの画面だけ**で、拡張機能は作品に足さない。拡張機能は、 日本語 → Ruby の変換で `表示する` / `【外部からの入力】`(Ruby の `console.puts` / `console.gets`)が 出て、そのブロックを作るときに初めて足す(変換器がブロックの opcode から拡張機能を読み込む)。 diff --git a/packages/scratch-gui/src/containers/ruby-tab.jsx b/packages/scratch-gui/src/containers/ruby-tab.jsx index ff1296f82b..aa368fa1d2 100644 --- a/packages/scratch-gui/src/containers/ruby-tab.jsx +++ b/packages/scratch-gui/src/containers/ruby-tab.jsx @@ -57,7 +57,11 @@ import { generatePreviewCode } from '../lib/ruby-script-preview'; import { targetCodeToBlocks } from '../lib/ruby-to-blocks-converter'; import RubyToBlocksConverterHOC from '../lib/ruby-to-blocks-converter-hoc.jsx'; import { containsV1Code } from '../lib/ruby-to-blocks-converter/v1-detection'; -import { hideSmalrubyConsole, showSmalrubyConsole } from '../lib/smalruby-console.js'; +import { + hideSmalrubyConsole, + shouldShowSmalrubyConsoleByDefault, + showSmalrubyConsole, +} from '../lib/smalruby-console.js'; import { getUrlParams } from '../lib/url-params'; import { showAlertWithTimeout, closeAlertWithId } from '../reducers/alerts'; import { @@ -1613,15 +1617,16 @@ const RubyTab = (props) => { if (exitDnclModeExternallyRequested) onClearExitDnclModeRequest?.(); }, [exitDnclModeExternallyRequested, dnclModeLocked, locale, activeTabIndex]); - // The console is the stage of the Japanese tab (docs/dncl/design.md 5 章): it is shown while the - // Japanese tab shows the program in Japanese, and the Ruby tab gives the stage back. Only the - // screen is shown: the console extension is added by the conversion when the program prints - // or reads (`表示する` / `入力する`). The editing target is a dependency so that the console - // comes back after a project is loaded. - const japaneseTabActive = activeTabIndex === JAPANESE_TAB_INDEX; + // The console is the stage of the Japanese mode (docs/dncl/design.md 5 章): it is shown while the + // program is written in Japanese, in the Japanese tab and in the other tabs (a reload in the Code + // tab shows it too, B31), and the Ruby tab gives the stage back. Only the screen is shown: the + // console extension is added by the conversion when the program prints or reads + // (`表示する` / `入力する`). The editing target is a dependency so that the console comes back + // after a project is loaded. + const showsConsoleByDefault = shouldShowSmalrubyConsoleByDefault({ dnclMode, dnclModeLocked, activeTabIndex }); useEffect(() => { - if (dnclMode && japaneseTabActive) onShowSmalrubyConsole?.(); - }, [dnclMode, japaneseTabActive, editingTarget]); + if (showsConsoleByDefault) onShowSmalrubyConsole?.(); + }, [showsConsoleByDefault, editingTarget]); useEffect(() => { if (activeTabIndex === RUBY_TAB_INDEX) onHideSmalrubyConsole?.(); }, [activeTabIndex]); diff --git a/packages/scratch-gui/src/lib/smalruby-console.js b/packages/scratch-gui/src/lib/smalruby-console.js index 5a7690afaa..69e5e9a916 100644 --- a/packages/scratch-gui/src/lib/smalruby-console.js +++ b/packages/scratch-gui/src/lib/smalruby-console.js @@ -1,5 +1,6 @@ // The entry the other parts of the GUI (the Japanese tab) use to show the // console of the console extension (docs/extension-smalruby-console/README.md). +import { RUBY_TAB_INDEX } from '../reducers/editor-tab.js'; import { resetSmalrubyConsole, showSmalrubyConsoleByDefault } from '../reducers/smalruby-console.js'; import { getStageDimensions } from './screen-utils.js'; @@ -18,6 +19,20 @@ const showSmalrubyConsole = (dispatch) => { dispatch(showSmalrubyConsoleByDefault()); }; +/** + * Whether the console should be shown (unless the user hid it). The console is the stage + * of the Japanese mode: the Japanese tab shows it, and the other tabs keep it, except the + * Ruby tab, which gives the stage back. So a reload in the Code tab of the Japanese mode + * shows the console too (B31). + * @param {object} state - The state of the editor. + * @param {boolean} state.dnclMode - Whether the program is written in Japanese. + * @param {boolean} [state.dnclModeLocked] - Whether a lesson does not allow the Japanese mode. + * @param {number} state.activeTabIndex - The active tab. + * @returns {boolean} Whether to show the console. + */ +const shouldShowSmalrubyConsoleByDefault = ({ dnclMode, dnclModeLocked = false, activeTabIndex }) => + Boolean(dnclMode) && !dnclModeLocked && activeTabIndex !== RUBY_TAB_INDEX; + /** * Show the stage again in place of the console (the Ruby tab). The next Japanese tab * shows the console again, even if the user hid it. @@ -41,4 +56,10 @@ const stageCanvasSize = (rect, stageSize) => { return { width, height }; }; -export { SMALRUBY_CONSOLE_EXTENSION_ID, hideSmalrubyConsole, showSmalrubyConsole, stageCanvasSize }; +export { + SMALRUBY_CONSOLE_EXTENSION_ID, + hideSmalrubyConsole, + shouldShowSmalrubyConsoleByDefault, + showSmalrubyConsole, + stageCanvasSize, +}; diff --git a/packages/scratch-gui/test/unit/lib/smalruby-console.test.js b/packages/scratch-gui/test/unit/lib/smalruby-console.test.js index b4c2917e57..5aed7d15c9 100644 --- a/packages/scratch-gui/test/unit/lib/smalruby-console.test.js +++ b/packages/scratch-gui/test/unit/lib/smalruby-console.test.js @@ -1,5 +1,16 @@ import { getStageDimensions } from '../../../src/lib/screen-utils'; -import { hideSmalrubyConsole, showSmalrubyConsole, stageCanvasSize } from '../../../src/lib/smalruby-console'; +import { + hideSmalrubyConsole, + shouldShowSmalrubyConsoleByDefault, + showSmalrubyConsole, + stageCanvasSize, +} from '../../../src/lib/smalruby-console'; +import { + BLOCKS_TAB_INDEX, + COSTUMES_TAB_INDEX, + JAPANESE_TAB_INDEX, + RUBY_TAB_INDEX, +} from '../../../src/reducers/editor-tab'; import { resetSmalrubyConsole, showSmalrubyConsoleByDefault } from '../../../src/reducers/smalruby-console'; describe('showSmalrubyConsole', () => { @@ -14,6 +25,38 @@ describe('showSmalrubyConsole', () => { }); }); +describe('shouldShowSmalrubyConsoleByDefault', () => { + test('shows the console in the Japanese tab of the Japanese mode', () => { + expect(shouldShowSmalrubyConsoleByDefault({ dnclMode: true, activeTabIndex: JAPANESE_TAB_INDEX })).toBe(true); + }); + + test('shows the console in the other tabs of the Japanese mode (a reload in the Code tab, B31)', () => { + expect(shouldShowSmalrubyConsoleByDefault({ dnclMode: true, activeTabIndex: BLOCKS_TAB_INDEX })).toBe(true); + expect(shouldShowSmalrubyConsoleByDefault({ dnclMode: true, activeTabIndex: COSTUMES_TAB_INDEX })).toBe(true); + }); + + test('leaves the stage in the Ruby tab', () => { + expect(shouldShowSmalrubyConsoleByDefault({ dnclMode: true, activeTabIndex: RUBY_TAB_INDEX })).toBe(false); + }); + + test('leaves the stage out of the Japanese mode', () => { + expect(shouldShowSmalrubyConsoleByDefault({ dnclMode: false, activeTabIndex: BLOCKS_TAB_INDEX })).toBe(false); + expect(shouldShowSmalrubyConsoleByDefault({ dnclMode: false, activeTabIndex: JAPANESE_TAB_INDEX })).toBe( + false, + ); + }); + + test('leaves the stage in a lesson that does not allow the Japanese mode', () => { + expect( + shouldShowSmalrubyConsoleByDefault({ + dnclMode: true, + dnclModeLocked: true, + activeTabIndex: BLOCKS_TAB_INDEX, + }), + ).toBe(false); + }); +}); + describe('hideSmalrubyConsole', () => { test('shows the stage again, and forgets that the user hid the console', () => { const dispatch = jest.fn(); From d73e876bcab53b915abb8bd8a9053d0beae52846 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:45:37 +0000 Subject: [PATCH 2/2] fix(dncl): give the stage back when a lesson without Japanese starts A lesson that does not allow Japanese could start in the Code tab of the Japanese mode, where the console now shows after a reload, and keep the console in place of the stage of the lesson. Co-Authored-By: Claude Opus 5.5 --- docs/extension-smalruby-console/README.md | 2 +- packages/scratch-gui/src/containers/ruby-tab.jsx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/extension-smalruby-console/README.md b/docs/extension-smalruby-console/README.md index de17dd34bd..98188bd426 100644 --- a/docs/extension-smalruby-console/README.md +++ b/docs/extension-smalruby-console/README.md @@ -47,7 +47,7 @@ Scratch には「言う」「聞いて待つ」しかないが、日本語のプ - 日本語モードのあいだ(最後に開いた文字のタブが日本語タブ)は、ルビータブ以外のどのタブでもコンソールを既定にする (`shouldShowSmalrubyConsoleByDefault`)。そのため、コードタブのままブラウザを読み込み直しても、コンソールが出る。 `hiddenByUser` は作品に保存しないので、読み込み直すと、人が隠していたコンソールもまた出る。 - 日本語モードを許さないレッスンでは出さない。 + 日本語モードを許さないレッスンでは出さない(日本語モードのコードタブでそのレッスンを始めたときも、ステージに戻す)。 - 日本語タブを開いても、出すのは**コンソールの画面だけ**で、拡張機能は作品に足さない。拡張機能は、 日本語 → Ruby の変換で `表示する` / `【外部からの入力】`(Ruby の `console.puts` / `console.gets`)が 出て、そのブロックを作るときに初めて足す(変換器がブロックの opcode から拡張機能を読み込む)。 diff --git a/packages/scratch-gui/src/containers/ruby-tab.jsx b/packages/scratch-gui/src/containers/ruby-tab.jsx index aa368fa1d2..7a9317862d 100644 --- a/packages/scratch-gui/src/containers/ruby-tab.jsx +++ b/packages/scratch-gui/src/containers/ruby-tab.jsx @@ -1630,6 +1630,11 @@ const RubyTab = (props) => { useEffect(() => { if (activeTabIndex === RUBY_TAB_INDEX) onHideSmalrubyConsole?.(); }, [activeTabIndex]); + // A lesson that does not allow Japanese gives the stage back too, even when it starts in the + // Code tab of the Japanese mode (the console shown there would hide the stage of the lesson). + useEffect(() => { + if (dnclModeLocked && dnclModeRef.current) onHideSmalrubyConsole?.(); + }, [dnclModeLocked]); // Furigana toggle effect useEffect(() => {