MCPcopy Create free account
hub / github.com/commontk/CTK / cursorOffset

Method cursorOffset

Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp:132–188  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

130
131//----------------------------------------------------------------------------
132int ctkPythonConsoleCompleter::cursorOffset(const QString& completion)
133{
134 Q_D(ctkPythonConsoleCompleter);
135 QString allTextFromShell = completion;
136 int parameterCount = 0;
137 int cursorOffset = 0;
138 if (allTextFromShell.contains("()"))
139 {
140 allTextFromShell.replace("()", "");
141 // Search backward through the string for usable characters
142 QString currentCompletionText;
143 for (int i = allTextFromShell.length()-1; i >= 0; --i)
144 {
145 QChar c = allTextFromShell.at(i);
146 if (c.isLetterOrNumber() || c == '.' || c == '_')
147 {
148 currentCompletionText.prepend(c);
149 }
150 else
151 {
152 break;
153 }
154 }
155 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
156 QStringList lineSplit = currentCompletionText.split(".", Qt::KeepEmptyParts);
157 #else
158 QStringList lineSplit = currentCompletionText.split(".", QString::KeepEmptyParts);
159 #endif
160 QString functionName = lineSplit.at(lineSplit.length()-1);
161 QStringList builtinFunctionPath = QStringList() << "__main__" << "__builtins__";
162 QStringList userDefinedFunctionPath = QStringList() << "__main__";
163 if (d->isBuiltInFunction(functionName))
164 {
165 parameterCount = d->parameterCountBuiltInFunction(QStringList(builtinFunctionPath+lineSplit).join("."));
166 }
167 else if (d->isUserDefinedFunction(functionName))
168 {
169 parameterCount = d->parameterCountUserDefinedFunction(QStringList(userDefinedFunctionPath+lineSplit).join("."));
170 }
171 else if (d->isInUserDefinedClass(currentCompletionText))
172 {
173 // "self" parameter can be ignored
174 parameterCount = d->parameterCountUserDefinedClassFunction(QStringList(userDefinedFunctionPath+lineSplit).join(".")) - 1;
175 }
176 else
177 {
178 QStringList variableNameAndFunctionList = userDefinedFunctionPath + lineSplit;
179 QString variableNameAndFunction = variableNameAndFunctionList.join(".");
180 parameterCount = d->parameterCountFromDocumentation(variableNameAndFunction);
181 }
182 }
183 if (parameterCount > 0)
184 {
185 cursorOffset = 1;
186 }
187 return cursorOffset;
188}
189

Callers 1

insertCompletionMethod · 0.80

Calls 10

QStringListClass · 0.85
isBuiltInFunctionMethod · 0.80
joinMethod · 0.80
isUserDefinedFunctionMethod · 0.80
isInUserDefinedClassMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected