summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-10-30 22:22:46 +0100
committerGitHub <noreply@github.com>2017-10-30 22:22:46 +0100
commit4889b806984ce454f906f066c8b3f63c7efa401e (patch)
treee63480d73c93a933f1c83903b6041743d07e964d
parent6a11e8c3773d27f1a7531b16324edbf1c803ed43 (diff)
parent7683ff3e42539a24bc333573e271e2ae77eb5c61 (diff)
Merge pull request #12471 from mhilbrunner/autocomplete
Fix get_node() and $ autocompletion when using single quotes
-rw-r--r--core/ustring.cpp22
-rw-r--r--core/ustring.h4
-rw-r--r--modules/gdscript/gd_editor.cpp4
-rw-r--r--scene/gui/text_edit.cpp6
4 files changed, 34 insertions, 2 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index b85996e3d1..80881f1adb 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -2476,6 +2476,11 @@ bool String::begins_with(const char *p_string) const {
return *p_string == 0;
}
+bool String::is_enclosed_in(const String &p_string) const {
+
+ return begins_with(p_string) && ends_with(p_string);
+}
+
bool String::is_subsequence_of(const String &p_string) const {
return _base_is_subsequence_of(p_string, false);
@@ -2486,6 +2491,11 @@ bool String::is_subsequence_ofi(const String &p_string) const {
return _base_is_subsequence_of(p_string, true);
}
+bool String::is_quoted() const {
+
+ return is_enclosed_in("\"") || is_enclosed_in("'");
+}
+
bool String::_base_is_subsequence_of(const String &p_string, bool case_insensitive) const {
int len = length();
@@ -3906,6 +3916,18 @@ String String::sprintf(const Array &values, bool *error) const {
return formatted;
}
+String String::quote(String quotechar) const {
+ return quotechar + *this + quotechar;
+}
+
+String String::unquote() const {
+ if (!is_quoted()) {
+ return *this;
+ }
+
+ return substr(1, length() - 2);
+}
+
#include "translation.h"
#ifdef TOOLS_ENABLED
diff --git a/core/ustring.h b/core/ustring.h
index ab4e325f2c..aa4a5c910d 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -118,8 +118,10 @@ public:
bool begins_with(const String &p_string) const;
bool begins_with(const char *p_string) const;
bool ends_with(const String &p_string) const;
+ bool is_enclosed_in(const String &p_string) const;
bool is_subsequence_of(const String &p_string) const;
bool is_subsequence_ofi(const String &p_string) const;
+ bool is_quoted() const;
Vector<String> bigrams() const;
float similarity(const String &p_string) const;
String format(const Variant &values, String placeholder = "{_}") const;
@@ -132,6 +134,8 @@ public:
String lpad(int min_length, const String &character = " ") const;
String rpad(int min_length, const String &character = " ") const;
String sprintf(const Array &values, bool *error) const;
+ String quote(String quotechar = "\"") const;
+ String unquote() const;
static String num(double p_num, int p_decimals = -1);
static String num_scientific(double p_num);
static String num_real(double p_num);
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index bcb998aee0..d9b10ff3fa 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -2111,9 +2111,9 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
for (List<String>::Element *E = opts.front(); E; E = E->next()) {
String opt = E->get().strip_edges();
- if (opt.begins_with("\"") && opt.ends_with("\"")) {
+ if (opt.is_quoted()) {
r_forced = true;
- String idopt = opt.substr(1, opt.length() - 2);
+ String idopt = opt.unquote();
if (idopt.replace("/", "_").is_valid_identifier()) {
options.insert(idopt);
} else {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index acf6d55eb5..2d55c077f1 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -4489,7 +4489,13 @@ void TextEdit::_update_completion_candidates() {
completion_index = 0;
completion_base = s;
Vector<float> sim_cache;
+ bool single_quote = s.begins_with("'");
+
for (int i = 0; i < completion_strings.size(); i++) {
+ if (single_quote && completion_strings[i].is_quoted()) {
+ completion_strings[i] = completion_strings[i].unquote().quote("'");
+ }
+
if (s == completion_strings[i]) {
// A perfect match, stop completion
_cancel_completion();