mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/code] Editor asks VariableBox for autocompletion
This commit is contained in:
@@ -251,9 +251,12 @@ void PythonTextArea::addAutocompletion() {
|
||||
{
|
||||
/* The previous code point is neither the beginning of the text, nor a
|
||||
* space, nor a \n, and the next code point is the end of the word.
|
||||
* Compute the text to insert */
|
||||
// TODO LEA
|
||||
textToInsert = "test";
|
||||
* Compute the text to insert:
|
||||
* Look first in the current script variables and functions, then in the
|
||||
* builtins, then in the imported modules/scripts. */
|
||||
VariableBoxController * varBox = m_contentView.pythonDelegate()->variableBoxController();
|
||||
const char * beginningOfWord = UTF8Helper::BeginningOfWord(m_contentView.editedText(), autocompletionLocation);
|
||||
textToInsert = varBox->autocompletionForText(beginningOfWord);
|
||||
}
|
||||
|
||||
// Try to insert the text (this might fail if the buffer is full)
|
||||
|
||||
@@ -27,6 +27,7 @@ protected:
|
||||
m_autocomplete(false)
|
||||
{
|
||||
}
|
||||
App * pythonDelegate() { return m_pythonDelegate; }
|
||||
void setAutocompleting(bool autocomplete) { m_autocomplete = autocomplete; }
|
||||
bool isAutocompleting() const { return m_autocomplete; }
|
||||
void loadSyntaxHighlighter();
|
||||
|
||||
@@ -187,6 +187,10 @@ void VariableBoxController::loadFunctionsAndVariables() {
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * VariableBoxController::autocompletionForText(const char * text) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HighlightCell * VariableBoxController::leafCellAtIndex(int index) {
|
||||
assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
|
||||
return &m_leafCells[index];
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
|
||||
/* VariableBoxController */
|
||||
void loadFunctionsAndVariables();
|
||||
const char * autocompletionForText(const char * text) const;
|
||||
private:
|
||||
constexpr static int k_maxScriptObjectNameSize = 100;
|
||||
constexpr static int k_maxNumberOfDisplayedRows = 6; // 240/40
|
||||
|
||||
@@ -84,7 +84,9 @@ size_t GlyphOffsetAtCodePoint(const char * buffer, const char * position);
|
||||
* For instance, strlen("∑") = 3 but StringGlyphLength("∑") = 1 */
|
||||
size_t StringGlyphLength(const char * s, int maxSize = -1);
|
||||
|
||||
// Returns the position of the first char between ' ', '\n' and 0.
|
||||
// Returns the position of the first previous char ' ', '\n' or text
|
||||
const char * BeginningOfWord(const char * text, const char * word);
|
||||
// Returns the position of the first following char ' ', '\n' or 0
|
||||
const char * EndOfWord(const char * word);
|
||||
|
||||
};
|
||||
|
||||
@@ -378,6 +378,23 @@ size_t StringGlyphLength(const char * s, int maxSize) {
|
||||
return glyphIndex;
|
||||
}
|
||||
|
||||
const char * BeginningOfWord(const char * text, const char * word) {
|
||||
if (text == word) {
|
||||
return text;
|
||||
}
|
||||
UTF8Decoder decoder(text, word);
|
||||
const char * codePointPointer = decoder.stringPosition();
|
||||
CodePoint codePoint = decoder.previousCodePoint();
|
||||
while (!CodePointIsEndOfWord(codePoint)) {
|
||||
codePointPointer = decoder.stringPosition();
|
||||
if (codePointPointer == text) {
|
||||
break;
|
||||
}
|
||||
codePoint = decoder.previousCodePoint();
|
||||
}
|
||||
return codePointPointer;
|
||||
}
|
||||
|
||||
const char * EndOfWord(const char * word) {
|
||||
UTF8Decoder decoder(word);
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
|
||||
@@ -275,6 +275,19 @@ QUIZ_CASE(ion_utf8_helper_string_glyph_length) {
|
||||
}
|
||||
|
||||
|
||||
void assert_beginning_of_word_is(const char * text, const char * word, const char * beginningOfWord) {
|
||||
quiz_assert(UTF8Helper::BeginningOfWord(text, word) == beginningOfWord);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_utf8_helper_beginning_of_word) {
|
||||
const char * test_sentence = "01 34+ \n89";
|
||||
assert_beginning_of_word_is(test_sentence, test_sentence, test_sentence);
|
||||
assert_beginning_of_word_is(test_sentence, test_sentence + 1, test_sentence);
|
||||
assert_beginning_of_word_is(test_sentence, test_sentence + 2, test_sentence);
|
||||
assert_beginning_of_word_is(test_sentence, test_sentence + 5, test_sentence + 3);
|
||||
assert_beginning_of_word_is(test_sentence, test_sentence + 8, test_sentence + 8);
|
||||
}
|
||||
|
||||
void assert_end_of_word_is(const char * word, const char * endOfWord) {
|
||||
quiz_assert(UTF8Helper::EndOfWord(word) == endOfWord);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user