diff options
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r-- | scene/gui/text_edit.cpp | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c497bc5363..1759f3eb04 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1842,6 +1842,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (k.mod.shift) _post_shift_selection(); + _cancel_completion(); + completion_hint=""; } break; case KEY_END: { @@ -1855,6 +1857,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (k.mod.shift) _post_shift_selection(); + + _cancel_completion(); + completion_hint=""; } break; #endif @@ -1867,6 +1872,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (k.mod.shift) _post_shift_selection(); + + _cancel_completion(); + completion_hint=""; + } break; case KEY_PAGEDOWN: { @@ -1878,6 +1887,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (k.mod.shift) _post_shift_selection(); + + _cancel_completion(); + completion_hint=""; + } break; case KEY_A: { @@ -2064,6 +2077,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { const CharType chr[2] = {(CharType)k.unicode, 0}; + if (completion_hint!="" && k.unicode==')') { + completion_hint=""; + } if(auto_brace_completion_enabled && _is_pair_symbol(chr[0])) { _consume_pair_symbol(chr[0]); } else { @@ -3323,9 +3339,32 @@ void TextEdit::_update_completion_candidates() { //look for keywords first - bool pre_keyword=false; + bool inquote=false; + int first_quote=-1; - if (cofs>0 && l[cofs-1]==' ') { + int c=cofs-1; + while(c>=0) { + if (l[c]=='"' || l[c]=='\'') { + inquote=!inquote; + if (first_quote==-1) + first_quote=c; + } + c--; + } + + bool pre_keyword=false; + bool cancel=false; + + //print_line("inquote: "+itos(inquote)+"first quote "+itos(first_quote)+" cofs-1 "+itos(cofs-1)); + if (!inquote && first_quote==cofs-1) { + //no completion here + //print_line("cancel!"); + cancel=true; + } if (inquote && first_quote!=-1) { + + s=l.substr(first_quote,cofs-first_quote); + //print_line("s: 1"+s); + } else if (cofs>0 && l[cofs-1]==' ') { int kofs=cofs-1; String kw; while (kofs>=0 && l[kofs]==' ') @@ -3337,7 +3376,7 @@ void TextEdit::_update_completion_candidates() { } pre_keyword=keywords.has(kw); - print_line("KW "+kw+"? "+itos(pre_keyword)); + //print_line("KW "+kw+"? "+itos(pre_keyword)); } else { @@ -3354,7 +3393,7 @@ void TextEdit::_update_completion_candidates() { update(); - if (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1])))) { + if (cancel || (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1]))))) { //none to complete, cancel _cancel_completion(); return; @@ -3421,7 +3460,16 @@ void TextEdit::query_code_comple() { String l = text[cursor.line]; int ofs = CLAMP(cursor.column,0,l.length()); - if (ofs>0 && (_is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1])))) + bool inquote=false; + + int c=ofs-1; + while(c>=0) { + if (l[c]=='"' || l[c]=='\'') + inquote=!inquote; + c--; + } + + if (ofs>0 && (inquote || _is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1])))) emit_signal("request_completion"); } |