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 @@ -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 つ余る。
Expand Down
1 change: 1 addition & 0 deletions packages/scratch-gui/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/scratch-gui/src/containers/ruby-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
68 changes: 68 additions & 0 deletions packages/scratch-gui/test/integration/dncl-typing-indent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import path from 'path';
import { 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}?rubyMode=dncl&locale=ja&tab=ruby`);
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.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,
'The lines were not typed',
);
expect(await editorValue(driver)).toBe(
['x = 3', 'もし x > 1 ならば:', ' 表示する(x)', '表示する(0)'].join('\n'),
);

expect(await getLogs()).toEqual([]);
});
});
Loading