From e895fc2adf8ad88dce64eff2d13641987d5aa0d7 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 22 Jun 2015 09:29:01 +0000 Subject: [PATCH] ide: Complete identifier improved git-svn-id: svn://ultimatepp.org/upp/trunk@8579 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Assist.cpp | 72 +++++++++++++++++++++---------------------- uppsrc/ide/Assist.h | 2 -- uppsrc/ide/ide.key | 1 - uppsrc/ide/idebar.cpp | 1 - 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/uppsrc/ide/Assist.cpp b/uppsrc/ide/Assist.cpp index 7f4962c04..8fdc3a193 100644 --- a/uppsrc/ide/Assist.cpp +++ b/uppsrc/ide/Assist.cpp @@ -540,27 +540,53 @@ void AssistEditor::PopUpAssist(bool auto_insert) popup.Ctrl::PopUp(this, false, false, true); } -Vector AssistEditor::GetFileIds() +bool sILess(const String& a, const String& b) { - Index id; + return ToUpper(a) < ToUpper(b); +} + +void AssistEditor::Complete() +{ + CloseAssist(); + + Index ids; int l = GetCursorLine() - 1; while(l >= 0) { String x = GetUtf8Line(l); CParser p(x); while(!p.IsEof()) if(p.IsId()) - id.FindAdd(p.ReadId()); + ids.FindAdd(p.ReadId()); else p.SkipTerm(); l--; } - return id.PickKeys(); -} + + Vector id = ids.PickKeys(); + Upp::Sort(id, sILess); -void AssistEditor::Complete() -{ - CloseAssist(); - Vector id = GetFileIds(); + int c = GetCursor(); + String q = IdBack(c); + if(q.GetCount()) { + String h; + for(int i = 0; i < id.GetCount(); i++) { + String s = id[i]; + if(s.StartsWith(q)) { + if(IsNull(h)) + h = s; + else { + s.Trim(min(s.GetCount(), h.GetCount())); + for(int j = 0; j < s.GetCount(); j++) + if(s[j] != h[j]) { + h.Trim(j); + break; + } + } + } + } + if(h.GetCount() > q.GetCount()) + Paste(h.Mid(q.GetCount()).ToWString()); + } for(int i = 0; i < id.GetCount(); i++) { CppItemInfo& f = assist_item.Add(); f.name = id[i]; @@ -572,34 +598,6 @@ void AssistEditor::Complete() PopUpAssist(true); } -void AssistEditor::Complete2() -{ - CloseAssist(); - int c = GetCursor(); - String q = IdBack(c); - if(IsNull(q)) - return; - String h; - Vector id = GetFileIds(); - for(int i = 0; i < id.GetCount(); i++) { - String s = id[i]; - if(s.StartsWith(q)) { - if(IsNull(h)) - h = s; - else { - s.Trim(min(s.GetCount(), h.GetCount())); - for(int j = 0; j < s.GetCount(); j++) - if(s[j] != h[j]) { - h.Trim(j); - break; - } - } - } - } - if(h.GetCount() > q.GetCount()) - Paste(h.Mid(q.GetCount()).ToWString()); -} - void AssistEditor::Abbr() { CloseAssist(); diff --git a/uppsrc/ide/Assist.h b/uppsrc/ide/Assist.h index 7828af6e6..20d544ae7 100644 --- a/uppsrc/ide/Assist.h +++ b/uppsrc/ide/Assist.h @@ -186,9 +186,7 @@ struct AssistEditor : CodeEditor, Navigator { void SyncParamInfo(); void StartParamInfo(const CppItem& m, int pos); - Vector GetFileIds(); void Complete(); - void Complete2(); void Abbr(); void Context(Parser& parser, int pos); diff --git a/uppsrc/ide/ide.key b/uppsrc/ide/ide.key index 2298e3033..881878f2c 100644 --- a/uppsrc/ide/ide.key +++ b/uppsrc/ide/ide.key @@ -103,7 +103,6 @@ KEY(TOGGLEINDEX, "File index", K_CTRL_F12) KEY(SEARCHINDEX, "File index search", K_F12) //KEY2(SEARCHCODE, "Search symbol", K_CTRL_U, K_CTRL_Y|K_SHIFT) KEY(COMPLETE, "Complete identifier with list", K_CTRL_COMMA) -KEY(COMPLETE2, "Complete identifier", K_CTRL_M) KEY(TOUPPER, "To uppercase", 0) KEY(TOLOWER, "To lowercase", 0) diff --git a/uppsrc/ide/idebar.cpp b/uppsrc/ide/idebar.cpp index 1667c8bba..863f6aaf2 100644 --- a/uppsrc/ide/idebar.cpp +++ b/uppsrc/ide/idebar.cpp @@ -573,7 +573,6 @@ void Ide::BrowseMenu(Bar& menu) menu.Add(!designer, AK_VIRTUALS, callback(&editor, &AssistEditor::Virtuals)); menu.Add(!designer, AK_THISBACKS, callback(&editor, &AssistEditor::Thisbacks)); menu.Add(!designer, AK_COMPLETE, callback(&editor, &AssistEditor::Complete)); - menu.Add(!designer, AK_COMPLETE2, callback(&editor, &AssistEditor::Complete2)); menu.Add(!designer, AK_ABBR, callback(&editor, &AssistEditor::Abbr)); menu.Add(!designer, "Insert", THISBACK(InsertMenu)); menu.MenuSeparator();