Keep autocomplete hints out of the way when typing
This commit is contained in:
parent
f783750c0d
commit
b58506d546
|
@ -3,8 +3,36 @@ define(() => {
|
||||||
|
|
||||||
const TRIMMER = /^([ \t]*)(.*)$/;
|
const TRIMMER = /^([ \t]*)(.*)$/;
|
||||||
const SQUASH_START = /^[ \t\r\n:,]/;
|
const SQUASH_START = /^[ \t\r\n:,]/;
|
||||||
|
const SQUASH_END = /[ \t\r\n]$/;
|
||||||
|
|
||||||
function getHints(cm) {
|
function makeRanges(cm, line, chFrom, chTo) {
|
||||||
|
const ln = cm.getLine(line);
|
||||||
|
const ranges = {
|
||||||
|
wordFrom: {line: line, ch: chFrom},
|
||||||
|
squashFrom: {line: line, ch: chFrom},
|
||||||
|
wordTo: {line: line, ch: chTo},
|
||||||
|
squashTo: {line: line, ch: chTo},
|
||||||
|
};
|
||||||
|
if(chFrom > 0 && ln[chFrom - 1] === ' ') {
|
||||||
|
ranges.squashFrom.ch --;
|
||||||
|
}
|
||||||
|
if(ln[chTo] === ' ') {
|
||||||
|
ranges.squashTo.ch ++;
|
||||||
|
}
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeHintItem(text, ranges) {
|
||||||
|
return {
|
||||||
|
text: text,
|
||||||
|
displayText: (text === '\n') ? '<END>' : text.trim(),
|
||||||
|
className: (text === '\n') ? 'pick-virtual' : null,
|
||||||
|
from: SQUASH_START.test(text) ? ranges.squashFrom : ranges.wordFrom,
|
||||||
|
to: SQUASH_END.test(text) ? ranges.squashTo : ranges.wordTo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHints(cm, options) {
|
||||||
const cur = cm.getCursor();
|
const cur = cm.getCursor();
|
||||||
const token = cm.getTokenAt(cur);
|
const token = cm.getTokenAt(cur);
|
||||||
let partial = token.string;
|
let partial = token.string;
|
||||||
|
@ -24,30 +52,27 @@ define(() => {
|
||||||
comp = comp.concat(token.state.knownAgent);
|
comp = comp.concat(token.state.knownAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ln = cm.getLine(cur.line);
|
const ranges = makeRanges(cm, cur.line, from, token.end);
|
||||||
const wordFrom = {line: cur.line, ch: from};
|
let selfValid = false;
|
||||||
const squashFrom = {line: cur.line, ch: from};
|
|
||||||
if(from > 0 && ln[from - 1] === ' ') {
|
|
||||||
squashFrom.ch --;
|
|
||||||
}
|
|
||||||
const wordTo = {line: cur.line, ch: token.end};
|
|
||||||
const list = (comp
|
const list = (comp
|
||||||
.filter((opt) => opt.startsWith(partial))
|
.filter((opt) => opt.startsWith(partial))
|
||||||
.map((opt) => {
|
.map((opt) => {
|
||||||
return {
|
if(opt === partial + ' ' && !options.completeSingle) {
|
||||||
text: opt,
|
selfValid = true;
|
||||||
displayText: (opt === '\n') ? '<END>' : opt.trim(),
|
return null;
|
||||||
className: (opt === '\n') ? 'pick-virtual' : null,
|
}
|
||||||
from: SQUASH_START.test(opt) ? squashFrom : wordFrom,
|
return makeHintItem(opt, ranges);
|
||||||
to: wordTo,
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
|
.filter((opt) => (opt !== null))
|
||||||
);
|
);
|
||||||
|
if(selfValid && list.length > 0) {
|
||||||
|
list.unshift(makeHintItem(partial + ' ', ranges));
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
from: wordFrom,
|
from: ranges.wordFrom,
|
||||||
to: wordTo,
|
to: ranges.wordTo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue