Skip to content

Commit

Permalink
Improve session output and prompt handling (#689)
Browse files Browse the repository at this point in the history
* improve session output and prompt handling

* Moved focus to SE on ⎕ input

Co-authored-by: JonnersW <jonners.walton@btinternet.com>
  • Loading branch information
e9gille and JonnersW authored Apr 30, 2021
1 parent ba7d214 commit f8fc1e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ D.IDE = function IDE(opts = {}) {
ide.promptType = t;
if (t && ide.pending.length) D.send('Execute', { trace: 0, text: `${ide.pending.shift()}\n` });
else eachWin((w) => { w.prompt(t); });
t === 4 && ide.wins[0].focus(); // ⍞ input
(t === 2 || t === 4) && ide.wins[0].focus(); // ⎕ / ⍞ input
t === 1 && ide.getStats();
if (t === 1 && ide.bannerDone === 0) {
// arrange for the banner to appear at the top of the session window
Expand Down
32 changes: 19 additions & 13 deletions src/se.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@
const model = me.getModel();
const l = model.getLineCount();
const s0 = model.getLineContent(l);
let sp = s;
const ssp = ' ';
let text = (s0 === ssp || se.promptType === 3) ? s : s0 + s;
if (s[s.length - 1] === '\n' && se.promptType === 1) text += ssp;
se.isReadOnly && me.updateOptions({ readOnly: false });
if (this.dirty[l] != null) {
const cp = me.getPosition();
se.edit([{ range: new monaco.Range(l, 1, l, 1 + s0.length), text: `${s0}\n${sp}` }]);
se.edit([{ range: new monaco.Range(l, 1, l, 1 + s0.length), text: `${s0}\n${text}` }]);
me.setPosition(cp);
} else {
if (se.isReadOnly && !/^\s*$/.test(s0)) sp = s0 + sp;
else if (se.promptType == 1) sp += s0;
se.edit([{ range: new monaco.Range(l, 1, l, 1 + s0.length), text: sp }]);
se.edit([{ range: new monaco.Range(l, 1, l, 1 + s0.length), text }]);
const ll = model.getLineCount();
const lc = model.getLineMaxColumn(ll);
me.setPosition({ lineNumber: ll, column: lc });
Expand All @@ -242,21 +242,27 @@
const se = this;
const { me } = se;
const model = me.getModel();
const l = model.getLineCount();
const t = model.getLineContent(l);
const ssp = ' ';
const line = model.getLineCount();
const column = model.getLineMaxColumn(line);
const t = model.getLineContent(line);
const promtChanged = se.promptType !== x;
se.promptType = x;
se.isReadOnly = !x;
me.updateOptions({ readOnly: !x });
if ((x === 1 && this.dirty[l] == null) || ![0, 1, 3, 4].includes(x)) {
if ((x === 1 && this.dirty[line] == null) || ![0, 1, 3, 4].includes(x)) {
const isEmpty = /^\s*$/.test(t);
const text = isEmpty ? ssp : `${t}\n${ssp}`;
se.edit(
[{ range: new monaco.Range(l, 1, l, 1 + t.length), text: ' ' }],
promtChanged ? [new monaco.Selection(l, 7, l, 7)] : me.getSelections(),
[{ range: new monaco.Range(line, 1, line, column), text }],
(promtChanged || !isEmpty)
? [new monaco.Selection(line + !isEmpty, 7, line + !isEmpty, 7)] : me.getSelections(),
);
} else if (t === ' ') {
se.edit([{ range: new monaco.Range(l, 1, l, 7), text: '' }]);
se.oModel.setValue(me.getValue());
} else if (t === ssp) {
se.edit([{ range: new monaco.Range(line, 1, line, 7), text: '' }]);
} else {
me.setPosition({ lineNumber: l, column: 1 + t.length });
me.setPosition({ lineNumber: line, column });
}
if (!x) {
se.taBuffer.length = 0;
Expand Down

0 comments on commit f8fc1e7

Please sign in to comment.