Browse Source

Improved autocomplete.

merge-requests/365/head
eidheim 10 years ago
parent
commit
859936392e
  1. 19
      src/source.cc

19
src/source.cc

@ -1249,12 +1249,15 @@ Source::ClangViewParse(file_path, project_path), autocomplete_cancel_starting(fa
autocomplete_cancel_starting=true; autocomplete_cancel_starting=true;
if(completion_dialog_shown) { if(completion_dialog_shown) {
completion_dialog->hide(); completion_dialog->hide();
start_reparse();
} }
} }
}); });
signal_scroll_event().connect([this](GdkEventScroll* event){ signal_scroll_event().connect([this](GdkEventScroll* event){
if(completion_dialog_shown) if(completion_dialog_shown) {
completion_dialog->hide(); completion_dialog->hide();
start_reparse();
}
return false; return false;
}, false); }, false);
signal_key_release_event().connect([this](GdkEventKey* key){ signal_key_release_event().connect([this](GdkEventKey* key){
@ -1270,6 +1273,7 @@ Source::ClangViewParse(file_path, project_path), autocomplete_cancel_starting(fa
autocomplete_cancel_starting=true; autocomplete_cancel_starting=true;
if(completion_dialog_shown) { if(completion_dialog_shown) {
completion_dialog->hide(); completion_dialog->hide();
start_reparse();
} }
return false; return false;
@ -1277,12 +1281,7 @@ Source::ClangViewParse(file_path, project_path), autocomplete_cancel_starting(fa
} }
bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) { bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) {
if(key->keyval>=32 && key->keyval<=126) {
if(key->keyval=='>' && last_keyval=='-')
last_keyval=127;
else
last_keyval=key->keyval; last_keyval=key->keyval;
}
if(completion_dialog_shown) { if(completion_dialog_shown) {
if(completion_dialog->on_key_press(key)) if(completion_dialog->on_key_press(key))
return true; return true;
@ -1293,15 +1292,17 @@ bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) {
void Source::ClangViewAutocomplete::start_autocomplete() { void Source::ClangViewAutocomplete::start_autocomplete() {
if(!has_focus()) if(!has_focus())
return; return;
auto iter=get_buffer()->get_insert()->get_iter();
if(!((last_keyval>='0' && last_keyval<='9') || if(!((last_keyval>='0' && last_keyval<='9') ||
(last_keyval>='a' && last_keyval<='z') || (last_keyval>='A' && last_keyval<='Z') || (last_keyval>='a' && last_keyval<='z') || (last_keyval>='A' && last_keyval<='Z') ||
last_keyval=='_' || last_keyval==127 || last_keyval=='.' || last_keyval==':')) { last_keyval=='_' || last_keyval=='.' || last_keyval==':' ||
(last_keyval=='>' && iter.backward_char() && iter.backward_char() && *iter=='-'))) {
autocomplete_cancel_starting=true; autocomplete_cancel_starting=true;
return; return;
} }
std::string line=" "+get_line_before_insert(); std::string line=" "+get_line_before_insert();
if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) { if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) {
const std::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)])(->|\\.|::)([a-zA-Z0-9_]*)$"); const std::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$");
const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$"); const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, in_specified_namespace)) { if(std::regex_match(line, sm, in_specified_namespace)) {
@ -1344,9 +1345,9 @@ void Source::ClangViewAutocomplete::autocomplete() {
completion_dialog=std::unique_ptr<CompletionDialog>(new CompletionDialog(*this, get_buffer()->create_mark(start_iter))); completion_dialog=std::unique_ptr<CompletionDialog>(new CompletionDialog(*this, get_buffer()->create_mark(start_iter)));
auto rows=std::make_shared<std::unordered_map<std::string, std::string> >(); auto rows=std::make_shared<std::unordered_map<std::string, std::string> >();
completion_dialog->on_hide=[this](){ completion_dialog->on_hide=[this](){
start_reparse();
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
completion_dialog_shown=false; completion_dialog_shown=false;
start_reparse();
}; };
completion_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) { completion_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) {
auto row = rows->at(selected); auto row = rows->at(selected);

Loading…
Cancel
Save