Skip to content

Commit

Permalink
Add custom read-only tips
Browse files Browse the repository at this point in the history
  • Loading branch information
e9gille committed Oct 6, 2022
1 parent 2b03c6d commit 66aad1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/ed.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@
mouseL = p.lineNumber; mouseC = p.column; mouseTS = e.event.timestamp;
}
});
const messageContribution = me.getContribution('editor.contrib.messageController');
me.onDidAttemptReadOnlyEdit(() => {
if (ed.hasEmbeddedBreaks) {
messageContribution.showMessage('Cannot edit variable with embedded line breaks.', me.getPosition());
} else if (!ed.ide.connected) {
messageContribution.showMessage('Cannot edit while disconnected from interpreter.', me.getPosition());
} else {
messageContribution.showMessage('Cannot edit while interpreter busy.', me.getPosition());
}
});

me.onDidFocusEditorText(() => { ed.focusTS = +new Date(); ed.ide.focusedWin = ed; });
ed.processAutocompleteReply = D.ac(me);
ed.tb = $(ed.dom).find('a');
Expand Down Expand Up @@ -302,30 +313,30 @@
}
D.ide.floating && $('title', ed.dom.ownerDocument).text(`${ed.name} - ${ed.ide.caption}`);
model.winid = ed.id;
if (ee.text.some((t) => /[\n\r]/.test(t))) {
ed.oText = ee.text.map((t) => t.replace('\n', '␤').replace('\r','␍')).join(model.getEOL());
ee.readOnly = true;
ed.hasEmbeddedBreaks = ee.text.some((t) => /[\n\r]/.test(t));
if (ed.hasEmbeddedBreaks) {
ed.oText = ee.text.map((t) => t.replace('\n', '␤').replace('\r', '␍')).join(model.getEOL());
} else {
ed.oText = ee.text.join(model.getEOL());
}
ed.isReadOnlyEntity = !!ee.readOnly || ed.hasEmbeddedBreaks;
// model.setEOL(monaco.editor.EndOfLineSequence.LF);
// entityType: 16 NestedArray 512 AplClass
// 1 DefinedFunction 32 QuadORObject 1024 AplInterface
// 2 SimpleCharArray 64 NativeFile 2048 AplSession
// 4 SimpleNumericArray 128 SimpleCharVector 4096 ExternalFunction
// 8 MixedSimpleArray 256 AplNamespace
const etype = {
2: ee.readOnly ? 'chararr' : 'charmat',
2: ed.isReadOnlyEntity ? 'chararr' : 'charmat',
4: 'numarr',
8: 'mixarr',
16: ee.readOnly ? 'mixarr' : 'charvecvec',
16: ed.isReadOnlyEntity ? 'mixarr' : 'charvecvec',
32: 'quador',
64: 'mixarr',
128: 'charvec',
}[ee.entityType];
ed.isCode = [1, 256, 512, 1024, 2048, 4096].indexOf(ee.entityType) >= 0;
model.setValue(ed.oText);
ed.isReadOnlyEntity = !!ee.readOnly;
if (/(\.|\\|\/)/.test(ee.name)) {
me.setModel(monaco.editor.createModel(ed.oText, null, monaco.Uri.file(ee.name)));
} else {
Expand Down Expand Up @@ -671,7 +682,7 @@
DO(me) { me.trigger('editor', 'editor.action.removeCommentLine'); },
indentOrComplete(me) {
const sels = me.getSelections();

const c = me.getPosition();
const ci = c.column - 1;
if (sels.length === 1 && sels[0].startLineNumber !== sels[0].endLineNumber) {
Expand Down
8 changes: 8 additions & 0 deletions src/se.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ D.Se = function Se(ide) { // constructor
se.stashLines();
});
me.onMouseUp(se.stashLines.bind(se));
const messageContribution = me.getContribution('editor.contrib.messageController');
me.onDidAttemptReadOnlyEdit(() => {
if (!se.promptType) {
messageContribution.showMessage('Cannot edit while interpreter busy.', me.getPosition());
} else if (!se.ide.connected) {
messageContribution.showMessage('Cannot edit while disconnected from interpreter.', me.getPosition());
}
});
me.onDidChangeModelContent((e) => {
if (!me.listen || me.getModel().bqc) return;
e.changes.forEach((c) => {
Expand Down

0 comments on commit 66aad1d

Please sign in to comment.