| 1383 | } |
| 1384 | |
| 1385 | void PythonShell::interactive_keypress(QKeyEvent *event) |
| 1386 | { |
| 1387 | if(event->key() == Qt::Key_Tab) |
| 1388 | { |
| 1389 | QString base = ui->lineInput->text(); |
| 1390 | if(!base.isEmpty() && !base.rbegin()->isSpace()) |
| 1391 | { |
| 1392 | // search backwards from the end for the first non dotted identifier first, and extract that |
| 1393 | // substring. This is just ASCII, not unicode |
| 1394 | for(int i = base.count() - 1; i >= 0; i--) |
| 1395 | { |
| 1396 | if(!base[i].isLetterOrNumber() && base[i] != QLatin1Char('.') && base[i] != QLatin1Char('_')) |
| 1397 | { |
| 1398 | base = base.right(base.count() - 1 - i); |
| 1399 | break; |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | // skip any initial digits that got included in the coarse search above |
| 1404 | while(!base.isEmpty() && base[0].isDigit()) |
| 1405 | base.remove(0, 1); |
| 1406 | |
| 1407 | QStringList options = interactiveContext->completionOptions(base); |
| 1408 | |
| 1409 | QString line = ui->lineInput->text(); |
| 1410 | |
| 1411 | if(!options.isEmpty()) |
| 1412 | { |
| 1413 | QString commonSubstring = options[0]; |
| 1414 | |
| 1415 | for(int i = 1; i < options.count(); i++) |
| 1416 | { |
| 1417 | const QString &opt = options[i]; |
| 1418 | if(opt.count() < commonSubstring.count()) |
| 1419 | commonSubstring.truncate(opt.count()); |
| 1420 | |
| 1421 | for(int j = 0; j < commonSubstring.count(); j++) |
| 1422 | { |
| 1423 | if(commonSubstring[j] != opt[j]) |
| 1424 | { |
| 1425 | commonSubstring.truncate(j); |
| 1426 | break; |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | if(commonSubstring.length() > base.length()) |
| 1432 | { |
| 1433 | line.chop(base.length()); |
| 1434 | line += commonSubstring; |
| 1435 | ui->lineInput->setText(line); |
| 1436 | } |
| 1437 | |
| 1438 | if(options.count() > 1) |
| 1439 | { |
| 1440 | QString text; |
| 1441 | text += line; |
| 1442 | text += lit("\n"); |
nothing calls this directly
no test coverage detected