From 327b4e7c2e62b41f8b495aa611b93ee1aa5a2dfe Mon Sep 17 00:00:00 2001 From: "smalruby3-editor-bot[bot]" <297607354+smalruby3-editor-bot[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:18:29 +0000 Subject: [PATCH 1/2] fix(dncl): indent by 4 spaces when typing in the Japanese tab Enter after a line that ends with : and Tab indented by 2 spaces, while the standard form is written (by ja-notation and the snippets) with 4. The Japanese tab now uses 4; the Ruby tab keeps 2. The docs tell how to type the indent without the ruled lines. Refs #2272 Co-Authored-By: Claude Opus 5.5 --- docs/dncl/README.md | 1 + packages/scratch-gui/.prettierignore | 1 + .../scratch-gui/src/containers/ruby-tab.jsx | 5 +- .../integration/dncl-typing-indent.test.js | 52 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 packages/scratch-gui/test/integration/dncl-typing-indent.test.js diff --git a/docs/dncl/README.md b/docs/dncl/README.md index c4ea4c64d3..3c2ff27347 100644 --- a/docs/dncl/README.md +++ b/docs/dncl/README.md @@ -67,6 +67,7 @@ ![テキスト(フォーカスがあるとき)と「できた」](screenshots/0102-text-1280x800.png) - **フォーカスがあるあいだ**はテキスト(空白の点と字下げのガイドも見える)。フォーカスを外すか、エディタ右上の **「できた」** ボタン(`ruby-tab-problem-form-done`。フォーカスがあるときだけ出る。キーボードでも押せる)を押すと問題の形になる。検索などでエディタのフォーカスが外れたときも問題の形になる(フォーカスで切りかえる仕様)。 +- **罫線は打たない**: テキストでは字下げを空白で書く(罫線の文字 `│` `└` などは打たなくてよい)。キーボードでは、`:` で終わる行(`もし … ならば:`・`… の間繰り返す:`・`… ずつ増やしながら繰り返す:`・`関数 名前(引数):`・`そうでなければ:`)で Enter を押すと次の行が 4 空白字下げされ、中の行で Enter を押すと同じ字下げが続く。`そうでなければ:` / `そうでなくもし … ならば:` は打つと 1 段もどる。ブロックを出るときは、字下げの直後で Backspace(1 回で 1 段もどる)か Shift+Tab。Tab は 4 空白。補完のスニペット(`もし...ならば` など)も 4 空白で入る。罫線の付いた問題をコピーして貼り付けたときは、罫線を読み飛ばして読み込む。 - 罫線は字下げから決める(`dncl-problem-form.js` の `layoutProblemForm`)。字下げの幅の数え方(タブは 4 桁、全角空白は 2 桁)は読み込みと共通(`dncl-indent.js`)。字下げの幅は 2 空白でも 4 空白でもよい。ブロックの最後の行は L 字、それ以外は縦線。 - **if/else は最後の枝だけ L 字**(次の行が同じ深さの `そうでなくもし` / `そうでなければ` なら縦線のまま)。 - **DNCL 風の形**(`を実行する` / `を繰り返す` / `と定義する` で閉じる)は、縦線を閉じの行の手前まで引き、L 字にしない。閉じのことばがブロックの終わりを示すので、L 字を足すと終わりが 2 つになり、コピーを読み込むと `end` が 1 つ余る。 diff --git a/packages/scratch-gui/.prettierignore b/packages/scratch-gui/.prettierignore index d0d0a970ac..abdafd67ba 100644 --- a/packages/scratch-gui/.prettierignore +++ b/packages/scratch-gui/.prettierignore @@ -471,6 +471,7 @@ test/integration/* !test/integration/dncl-mode-validation.test.js !test/integration/dncl-problem-form.test.js !test/integration/dncl-settings-pattern.test.js +!test/integration/dncl-typing-indent.test.js !test/integration/feedback-link.test.js !test/integration/ruby-editor-actions.test.js !test/integration/ruby-module.test.js diff --git a/packages/scratch-gui/src/containers/ruby-tab.jsx b/packages/scratch-gui/src/containers/ruby-tab.jsx index 484ba6c015..cacf64840c 100644 --- a/packages/scratch-gui/src/containers/ruby-tab.jsx +++ b/packages/scratch-gui/src/containers/ruby-tab.jsx @@ -1826,7 +1826,10 @@ const RubyTab = (props) => { lineNumbers: dnclMode ? problemFormLineNumberLabels : 'on', lineNumbersMinChars: dnclMode ? lineNumbersMinChars : 5, scrollBeyondLastLine: true, - tabSize: 2, + // The Japanese tab writes the standard form indented 4 spaces (as + // ja-notation and the snippets write it), so Enter after `:` and Tab + // indent by 4 there too. + tabSize: dnclMode ? 4 : 2, fixedOverflowWidgets: true, wordBasedSuggestions: 'off', autoIndent: 'full', diff --git a/packages/scratch-gui/test/integration/dncl-typing-indent.test.js b/packages/scratch-gui/test/integration/dncl-typing-indent.test.js new file mode 100644 index 0000000000..7f766fb703 --- /dev/null +++ b/packages/scratch-gui/test/integration/dncl-typing-indent.test.js @@ -0,0 +1,52 @@ +import path from 'path'; +import { By, Key } from 'selenium-webdriver'; +import SeleniumHelper from '../helpers/selenium-helper'; + +// Typing in the Japanese tab needs no ruled lines (Issue #1731, W10): Enter +// after a line that ends with `:` indents the next line by 4 spaces (the +// width of the standard form), and the ruled lines are drawn only on the +// problem form. The program is written for this test. +const seleniumHelper = new SeleniumHelper(); +const { getDriver, getLogs, loadUri } = seleniumHelper; + +const uri = path.resolve(__dirname, '../../build/index.html'); + +const editorValue = (d) => d.executeScript('return window.monacoEditor.getValue()'); + +let driver; + +describe('Japanese tab: typing the indent', () => { + beforeAll(async () => { + driver = await getDriver(); + }); + + afterAll(async () => { + await driver.quit(); + }); + + test('indents by 4 spaces after `:` and goes back with Backspace', async () => { + await loadUri(`${uri}?locale=ja&tab=japanese`); + await driver.wait( + () => + driver.executeScript( + 'return !!window.monacoEditor && window.monacoEditor.getModel().getLanguageId() === "dncl"', + ), + 10000, + 'The Japanese tab did not start', + ); + await driver.executeScript('window.monacoEditor.setValue(""); window.monacoEditor.focus();'); + const textarea = await driver.findElement(By.css('.monaco-editor textarea')); + await textarea.sendKeys('x = 3', Key.ENTER, 'もし x > 1 ならば:', Key.ENTER); + await textarea.sendKeys('表示する(x)', Key.ENTER, Key.BACK_SPACE, '表示する(0)'); + await driver.wait( + async () => (await editorValue(driver)).endsWith('表示する(0)'), + 10000, + 'The lines were not typed', + ); + expect(await editorValue(driver)).toBe( + ['x = 3', 'もし x > 1 ならば:', ' 表示する(x)', '表示する(0)'].join('\n'), + ); + + expect(await getLogs()).toEqual([]); + }); +}); From a7e5436c1bb4a0f803093da565bd4f6aa95db7a7 Mon Sep 17 00:00:00 2001 From: "smalruby3-editor-bot[bot]" <297607354+smalruby3-editor-bot[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:42:43 +0000 Subject: [PATCH 2/2] test(dncl): type into the focused editor one key at a time Refs #2272 Co-Authored-By: Claude Opus 5.5 --- .../integration/dncl-typing-indent.test.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/scratch-gui/test/integration/dncl-typing-indent.test.js b/packages/scratch-gui/test/integration/dncl-typing-indent.test.js index 7f766fb703..7f30550998 100644 --- a/packages/scratch-gui/test/integration/dncl-typing-indent.test.js +++ b/packages/scratch-gui/test/integration/dncl-typing-indent.test.js @@ -1,5 +1,5 @@ import path from 'path'; -import { By, Key } from 'selenium-webdriver'; +import { Key } from 'selenium-webdriver'; import SeleniumHelper from '../helpers/selenium-helper'; // Typing in the Japanese tab needs no ruled lines (Issue #1731, W10): Enter @@ -25,7 +25,7 @@ describe('Japanese tab: typing the indent', () => { }); test('indents by 4 spaces after `:` and goes back with Backspace', async () => { - await loadUri(`${uri}?locale=ja&tab=japanese`); + await loadUri(`${uri}?rubyMode=dncl&locale=ja&tab=ruby`); await driver.wait( () => driver.executeScript( @@ -35,9 +35,25 @@ describe('Japanese tab: typing the indent', () => { 'The Japanese tab did not start', ); await driver.executeScript('window.monacoEditor.setValue(""); window.monacoEditor.focus();'); - const textarea = await driver.findElement(By.css('.monaco-editor textarea')); - await textarea.sendKeys('x = 3', Key.ENTER, 'もし x > 1 ならば:', Key.ENTER); - await textarea.sendKeys('表示する(x)', Key.ENTER, Key.BACK_SPACE, '表示する(0)'); + const textarea = await driver.switchTo().activeElement(); + // Each key goes alone: Enter sent in one string with the text is typed as a + // line break, which Monaco does not indent. + const type = async (...keys) => { + for (const key of keys) { + await textarea.sendKeys(key); + await driver.sleep(100); + } + }; + await type( + 'x = 3', + Key.ENTER, + 'もし x > 1 ならば:', + Key.ENTER, + '表示する(x)', + Key.ENTER, + Key.BACK_SPACE, + '表示する(0)', + ); await driver.wait( async () => (await editorValue(driver)).endsWith('表示する(0)'), 10000,