mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 09:10:48 +01:00
[apps/code] autocompletionText uses the right text length
Before, there was no notion that the autocompleted text might not be a null terminated string.
This commit is contained in:
@@ -256,6 +256,7 @@ void PythonTextArea::addAutocompletion() {
|
||||
|
||||
const char * autocompletionLocation = const_cast<char *>(cursorLocation());
|
||||
const char * textToInsert = nullptr;
|
||||
int textToInsertLength = 0;
|
||||
CodePoint prevCodePoint = UTF8Helper::PreviousCodePoint(m_contentView.editedText(), autocompletionLocation);
|
||||
if (!UTF8Helper::CodePointIsEndOfWord(prevCodePoint)
|
||||
&& UTF8Helper::CodePointIsEndOfWord(UTF8Helper::CodePointAtLocation(autocompletionLocation)))
|
||||
@@ -267,11 +268,11 @@ void PythonTextArea::addAutocompletion() {
|
||||
* builtins, then in the imported modules/scripts. */
|
||||
VariableBoxController * varBox = m_contentView.pythonDelegate()->variableBoxController();
|
||||
const char * beginningOfWord = m_contentView.textToAutocomplete();
|
||||
textToInsert = varBox->autocompletionForText(m_contentView.pythonDelegate()->menuController()->editedScriptIndex(), beginningOfWord);
|
||||
textToInsert = varBox->autocompletionForText(m_contentView.pythonDelegate()->menuController()->editedScriptIndex(), beginningOfWord, &textToInsertLength);
|
||||
}
|
||||
|
||||
// Try to insert the text (this might fail if the buffer is full)
|
||||
if (textToInsert && m_contentView.insertTextAtLocation(textToInsert, const_cast<char *>(autocompletionLocation))) {
|
||||
if (textToInsert && textToInsertLength > 0 && m_contentView.insertTextAtLocation(textToInsert, const_cast<char *>(autocompletionLocation), textToInsertLength)) {
|
||||
m_contentView.setAutocompleting(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ void VariableBoxController::loadFunctionsAndVariables(int scriptIndex, const cha
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * VariableBoxController::autocompletionForText(int scriptIndex, const char * text) {
|
||||
const char * VariableBoxController::autocompletionForText(int scriptIndex, const char * text, int * textToInsertLength) {
|
||||
// TODO LEA Accelerate
|
||||
loadFunctionsAndVariables(scriptIndex, text);
|
||||
const char * endOfText = UTF8Helper::EndOfWord(text);
|
||||
@@ -342,6 +342,7 @@ const char * VariableBoxController::autocompletionForText(int scriptIndex, const
|
||||
const char * currentName = node->name();
|
||||
int currentNameLength = node->nameLength();
|
||||
if ((currentNameLength < 0 || currentNameLength != textLength) && strncmp(text, currentName, textLength) == 0) {
|
||||
*textToInsertLength = currentNameLength - textLength;
|
||||
return currentName + textLength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
/* VariableBoxController */
|
||||
void loadFunctionsAndVariables(int scriptIndex, const char * textToAutocomplete);
|
||||
const char * autocompletionForText(int scriptIndex, const char * text);
|
||||
const char * autocompletionForText(int scriptIndex, const char * text, int * textToInsertLength);
|
||||
private:
|
||||
constexpr static int k_maxScriptObjectNameSize = 100;
|
||||
constexpr static int k_maxNumberOfDisplayedRows = 6; // 240/40
|
||||
|
||||
Reference in New Issue
Block a user