mirror of https://github.com/buggins/dlangide.git
better autocompletion
This commit is contained in:
parent
8389e71459
commit
ded50dfbf3
|
@ -86,17 +86,36 @@ class DSourceEdit : SourceEdit {
|
||||||
return _content.save();
|
return _content.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void insertCompletion(dstring completionText) {
|
||||||
|
TextRange range;
|
||||||
|
TextPosition p = getCaretPosition;
|
||||||
|
range.start = range.end = p;
|
||||||
|
dstring lineText = content.line(p.line);
|
||||||
|
dchar prevChar = p.pos > 0 ? lineText[p.pos - 1] : 0;
|
||||||
|
dchar nextChar = p.pos < lineText.length ? lineText[p.pos] : 0;
|
||||||
|
if (isIdentMiddleChar(prevChar)) {
|
||||||
|
while(range.start.pos > 0 && isIdentMiddleChar(lineText[range.start.pos - 1]))
|
||||||
|
range.start.pos--;
|
||||||
|
if (isIdentMiddleChar(nextChar)) {
|
||||||
|
while(range.end.pos < lineText.length && isIdentMiddleChar(lineText[range.end.pos]))
|
||||||
|
range.end.pos++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EditOperation edit = new EditOperation(EditAction.Replace, range, completionText);
|
||||||
|
_content.performOperation(edit, this);
|
||||||
|
setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
/// override to handle specific actions
|
/// override to handle specific actions
|
||||||
override bool handleAction(const Action a) {
|
override bool handleAction(const Action a) {
|
||||||
|
import ddc.lexer.tokenizer;
|
||||||
if (a) {
|
if (a) {
|
||||||
switch (a.id) {
|
switch (a.id) {
|
||||||
case IDEActions.FileSave:
|
case IDEActions.FileSave:
|
||||||
save();
|
save();
|
||||||
return true;
|
return true;
|
||||||
case IDEActions.InsertCompletion:
|
case IDEActions.InsertCompletion:
|
||||||
EditOperation edit = new EditOperation(EditAction.Replace, getCaretPosition, a.label);
|
insertCompletion(a.label);
|
||||||
_content.performOperation(edit, this);
|
|
||||||
setFocus();
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -127,6 +146,11 @@ class DSourceEdit : SourceEdit {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (suggestions.length == 1) {
|
||||||
|
insertCompletion(suggestions[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MenuItem completionPopupItems = new MenuItem(null);
|
MenuItem completionPopupItems = new MenuItem(null);
|
||||||
//Add all the suggestions.
|
//Add all the suggestions.
|
||||||
foreach(int i, dstring suggestion ; suggestions) {
|
foreach(int i, dstring suggestion ; suggestions) {
|
||||||
|
|
Loading…
Reference in New Issue