Skip to content

Commit

Permalink
Autocompletion popup closes when backspacing, Fix #714 (#907)
Browse files Browse the repository at this point in the history
* trigger suggestions after period if available

* added ac suggestion limit to prefs

* removed double negation

* trigger autocomplete after N characters

* Use suggestWidgetController and hide when empty

Co-authored-by: Gilgamesh Athoraya <[email protected]>
  • Loading branch information
KarlTD and e9gille authored Aug 18, 2022
1 parent e217f63 commit b3fd0f6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ <h2>Contextual help</h2>
</select>
</label></p>
<p><label>Autocompletion a<u>f</u>ter <input id=code_acd size=5>ms</label></p>
<p><label>Make suggestions a<u>f</u>ter <input id=code_acl size=5>characters</label></p>
<p><input id=code_ss type=checkbox><label for=code_ss >Autocomplete control structures with snippets</label></p>
<p><input id=code_sh type=checkbox><label for=code_sh >Highlight matching words</label></p>
<p><input id=code_vt type=checkbox><label for=code_vt >Show <u>v</u>alue tips</label></p>
Expand Down
33 changes: 22 additions & 11 deletions src/ac.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,35 @@
model.bqc = e.changes[0].range.startColumn;
} else if (!e.isRedoing && !e.isUndoing && !e.isFlush) {
setTimeout(() => {
const sw = me._contentWidgets['editor.widget.suggestWidget'];
const swc = me.getContribution('editor.contrib.suggestController');
const sw = swc.widget.value;
if (!sw) return;
const swv = sw.widget._widget._ctxSuggestWidgetVisible.get();
const swv = swc.model.state > 0;
const r = e.changes[0].range;
if (r.startLineNumber > model.getLineCount()) return;
const limit = D.prf.autoCompleteCharacterLimit();
const l = model.getLineContent(r.startLineNumber).toLowerCase();
const bq2 = e.changes.length && RegExp(`${pk}${pk}\\w*`, 'i').test(l);
const swlist = sw.widget._widget._list;
const swlist = sw._list;
if (swv && !bq2 && swlist.length === 1) {
const t = sw.widget._widget._focusedItem.completion.insertText.toLowerCase();
const t = sw._focusedItem.completion.insertText.toLowerCase();
if (l.slice(r.startColumn - t.length, r.startColumn) === t) {
me.trigger('editor', 'hideSuggestWidget');
swc.cancelSuggestWidget();
} else {
me.trigger('editor', 'editor.action.triggerSuggest');
swc.triggerSuggest();
}
} else if (!bq2 && e.changes.length === 1 && e.changes[0].text === '') {
const cc = r.startColumn;
const word = (((RegExp('⎕?[A-Z_a-zÀ-ÖØ-Ýß-öø-üþ∆⍙Ⓐ-Ⓩ0-9]*$').exec(l.slice(0, cc)) || [])[0] || '')); // match left of cursor
if (word.length >= limit && (l[cc] || ' ') === ' ') {
swc.triggerSuggest();
} else {
swc.cancelSuggestWidget();
}
} else if (swv && !swlist.length) {
me.trigger('editor', 'hideSuggestWidget');
swc.cancelSuggestWidget();
} else if (swv && !bq2 && swlist.length > 1) {
me.trigger('editor', 'editor.action.triggerSuggest');
swc.triggerSuggest();
}
}, 50);
}
Expand Down Expand Up @@ -154,6 +164,7 @@
const l = ac.position.lineNumber;
const c = ac.position.column;
const manual = me.tabComplete;
const swc = me.getContribution('editor.contrib.suggestController');
if (D.prf.autocompletion() === 'shell' && manual) {
const [, prefix] = x.options.join(' ').match(prefixRE) || [];
if (prefix && prefix.length > x.skip) {
Expand All @@ -163,18 +174,18 @@
[{ range: new monaco.Range(l, c - x.skip, l, c), text: prefix }],
[new monaco.Selection(l, endCol, l, endCol)],
);
me.trigger('editor', 'hideSuggestWidget');
swc.cancelSuggestWidget();
me.tabComplete = 0;
return;
}
if (me.tabComplete < 2) {
me.trigger('editor', 'hideSuggestWidget');
swc.cancelSuggestWidget();
return;
}
me.tabComplete = 0;
}
if (!x.options.length || (D.prf.autocompletion() === 'shell' && !manual)) {
me.trigger('editor', 'hideSuggestWidget');
swc.cancelSuggestWidget();
if (manual) {
me.tabComplete = 0;
let i = D.prf.indent();
Expand Down
9 changes: 6 additions & 3 deletions src/mon_apl.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,10 @@
/* eslint-enable no-template-curly-in-string */
return { suggestions };
}
if (D.send) {
const word = (((RegExp('⎕?[A-Z_a-zÀ-ÖØ-Ýß-öø-üþ∆⍙Ⓐ-Ⓩ0-9]*$').exec(s.slice(0, c)) || [])[0] || '')); // match left of cursor
const limit = D.prf.autoCompleteCharacterLimit();
if (D.send && (l[s] || ' ') === ' '
&& (word.length >= limit || D.prf.autocompletion() === 'shell')) {
D.send('GetAutocomplete', { line: s, pos: c - 1, token: model.winid });
const m = model;
return new Promise((complete, error, progress) => {
Expand All @@ -871,7 +874,7 @@
};
});
}
return [];
return null;
},
});
const aplHover = {
Expand Down Expand Up @@ -907,7 +910,7 @@
};
});
}
return [];
return null;
},
};
const aplFold = {
Expand Down
1 change: 1 addition & 0 deletions src/prf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ D.prf = {};
['blockCursor', 0], // use block cursor selection?
['cursorBlinking', 'blink'], // cursor blinking
['autocompletionDelay',500],
['autoCompleteCharacterLimit',1],
['colourScheme', 'Default'], //name of the active colour scheme
['colourSchemes', []],//objects describing user-defined colour schemes
['confirmations', {}],//saved responses to TaskDialog questions
Expand Down
4 changes: 4 additions & 0 deletions src/prf_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
};
q.ac.onchange = () => {
q.acd.disabled = q.ac.value !== 'classic';
q.acl.disabled = q.ac.value !== 'classic';
q.ac.value === 'classic' && q.acd.select();
};
q.ilf.onchange = () => {
Expand Down Expand Up @@ -58,6 +59,7 @@
q.acbr.checked = !!p.autoCloseBrackets();
q.ac.value = p.autocompletion();
q.acd.value = p.autocompletionDelay();
q.acl.value = p.autoCompleteCharacterLimit();
q.bc.checked = !!p.blockCursor();
q.cb.value = p.cursorBlinking();
q.coq.checked = !!p.connectOnQuit();
Expand Down Expand Up @@ -97,6 +99,7 @@
p.autocompletion (q.ac.value);
p.autoPW (q.apw.checked);
p.autocompletionDelay(q.acd.value);
p.autoCompleteCharacterLimit (q.acl.value);
p.connectOnQuit (q.coq.checked);
p.filenameInTitle (q.fit.checked);
p.renderLineHighlight(q.rlh.value);
Expand All @@ -116,6 +119,7 @@
if (q.ai.checked && !isInt(q.sw.value, 0)) return { msg: 'Auto-indent must be a non-negative integer.', el: q.sw };
if (q.aim.checked && !isInt(q.swm.value, 0)) return { msg: 'Auto-indent in methods must be a non-negative integer.', el: q.swm };
if (q.ac.value === 'classic' && !isInt(q.acd.value, 0)) return { msg: 'Autocompletion delay must be a non-negative integer.', el: q.acd };
if (q.ac.value === 'classic' && !isInt(q.acl.value, 0)) return { msg: 'Autocompletion after N characters must be a non-negative integer.', el: q.acl };
if (q.ph.checked && !isInt(q.phs.value, 1)) return { msg: 'Persistent history size must be a positive integer.', el: q.phs };
return null;
},
Expand Down
2 changes: 0 additions & 2 deletions src/se.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@

const c = me.getPosition();
const ci = c.column - 1;
const s = me.getModel().getLineContent(c.lineNumber);
const ch = s[ci - 1];
if (sels.length === 1 && sels[0].startLineNumber !== sels[0].endLineNumber) {
me.trigger('editor', 'editor.action.indentLines');
} else if (D.prf.autocompletion() === 'off' || this.promptType === 4) {
Expand Down

0 comments on commit b3fd0f6

Please sign in to comment.