@@ -1416,8 +1416,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_path(StringView base,
1416
1416
// since we are not suggesting anything starting with
1417
1417
// `/foo/', but rather just `bar...'
1418
1418
auto token_length = escape_token (token).length ();
1419
+ size_t static_offset = last_slash + 1 ;
1420
+ auto invariant_offset = token_length;
1419
1421
if (m_editor)
1420
- m_editor->suggest (token_length, last_slash + 1 );
1422
+ m_editor->transform_suggestion_offsets (invariant_offset, static_offset );
1421
1423
1422
1424
// only suggest dot-files if path starts with a dot
1423
1425
Core::DirIterator files (path,
@@ -1440,6 +1442,8 @@ Vector<Line::CompletionSuggestion> Shell::complete_path(StringView base,
1440
1442
suggestions.append ({ escape_token (file), " " });
1441
1443
}
1442
1444
suggestions.last ().input_offset = token_length;
1445
+ suggestions.last ().invariant_offset = invariant_offset;
1446
+ suggestions.last ().static_offset = static_offset;
1443
1447
}
1444
1448
}
1445
1449
}
@@ -1465,8 +1469,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(StringView name,
1465
1469
1466
1470
String completion = *match;
1467
1471
auto token_length = escape_token (name).length ();
1472
+ auto invariant_offset = token_length;
1473
+ size_t static_offset = 0 ;
1468
1474
if (m_editor)
1469
- m_editor->suggest (token_length, 0 );
1475
+ m_editor->transform_suggestion_offsets (invariant_offset, static_offset );
1470
1476
1471
1477
// Now that we have a program name starting with our token, we look at
1472
1478
// other program names starting with our token and cut off any mismatching
@@ -1475,16 +1481,17 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(StringView name,
1475
1481
Vector<Line::CompletionSuggestion> suggestions;
1476
1482
1477
1483
int index = match - cached_path.data ();
1478
- for (int i = index - 1 ; i >= 0 && cached_path[i].starts_with (name); --i) {
1484
+ for (int i = index - 1 ; i >= 0 && cached_path[i].starts_with (name); --i)
1479
1485
suggestions.append ({ cached_path[i], " " });
1480
- suggestions.last ().input_offset = token_length;
1481
- }
1482
- for (size_t i = index + 1 ; i < cached_path.size () && cached_path[i].starts_with (name); ++i) {
1486
+ for (size_t i = index + 1 ; i < cached_path.size () && cached_path[i].starts_with (name); ++i)
1483
1487
suggestions.append ({ cached_path[i], " " });
1484
- suggestions.last ().input_offset = token_length;
1485
- }
1486
1488
suggestions.append ({ cached_path[index], " " });
1487
- suggestions.last ().input_offset = token_length;
1489
+
1490
+ for (auto & entry : suggestions) {
1491
+ entry.input_offset = token_length;
1492
+ entry.invariant_offset = invariant_offset;
1493
+ entry.static_offset = static_offset;
1494
+ }
1488
1495
1489
1496
return suggestions;
1490
1497
}
@@ -1494,8 +1501,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_variable(StringView name, siz
1494
1501
Vector<Line::CompletionSuggestion> suggestions;
1495
1502
auto pattern = offset ? name.substring_view (0 , offset) : " " ;
1496
1503
1504
+ auto invariant_offset = offset;
1505
+ size_t static_offset = 0 ;
1497
1506
if (m_editor)
1498
- m_editor->suggest (offset );
1507
+ m_editor->transform_suggestion_offsets (invariant_offset, static_offset );
1499
1508
1500
1509
// Look at local variables.
1501
1510
for (auto & frame : m_local_frames) {
@@ -1516,10 +1525,15 @@ Vector<Line::CompletionSuggestion> Shell::complete_variable(StringView name, siz
1516
1525
if (suggestions.contains_slow (name))
1517
1526
continue ;
1518
1527
suggestions.append (move (name));
1519
- suggestions.last ().input_offset = offset;
1520
1528
}
1521
1529
}
1522
1530
1531
+ for (auto & entry : suggestions) {
1532
+ entry.input_offset = offset;
1533
+ entry.invariant_offset = invariant_offset;
1534
+ entry.static_offset = static_offset;
1535
+ }
1536
+
1523
1537
return suggestions;
1524
1538
}
1525
1539
@@ -1528,8 +1542,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_user(StringView name, size_t
1528
1542
Vector<Line::CompletionSuggestion> suggestions;
1529
1543
auto pattern = offset ? name.substring_view (0 , offset) : " " ;
1530
1544
1545
+ auto invariant_offset = offset;
1546
+ size_t static_offset = 0 ;
1531
1547
if (m_editor)
1532
- m_editor->suggest (offset );
1548
+ m_editor->transform_suggestion_offsets (invariant_offset, static_offset );
1533
1549
1534
1550
Core::DirIterator di (" /home" , Core::DirIterator::SkipParentAndBaseDir);
1535
1551
@@ -1540,7 +1556,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_user(StringView name, size_t
1540
1556
String name = di.next_path ();
1541
1557
if (name.starts_with (pattern)) {
1542
1558
suggestions.append (name);
1543
- suggestions.last ().input_offset = offset;
1559
+ auto & suggestion = suggestions.last ();
1560
+ suggestion.input_offset = offset;
1561
+ suggestion.invariant_offset = invariant_offset;
1562
+ suggestion.static_offset = static_offset;
1544
1563
}
1545
1564
}
1546
1565
@@ -1553,8 +1572,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_option(StringView program_nam
1553
1572
while (start < option.length () && option[start] == ' -' && start < 2 )
1554
1573
++start;
1555
1574
auto option_pattern = offset > start ? option.substring_view (start, offset - start) : " " ;
1575
+ auto invariant_offset = offset;
1576
+ size_t static_offset = 0 ;
1556
1577
if (m_editor)
1557
- m_editor->suggest (offset );
1578
+ m_editor->transform_suggestion_offsets (invariant_offset, static_offset );
1558
1579
1559
1580
Vector<Line::CompletionSuggestion> suggestions;
1560
1581
@@ -1579,13 +1600,18 @@ Vector<Line::CompletionSuggestion> Shell::complete_option(StringView program_nam
1579
1600
return builder.to_string ();
1580
1601
};
1581
1602
#define __ENUMERATE_SHELL_OPTION (name, d_, descr_ ) \
1582
- if (#name##sv.starts_with (option_pattern)) { \
1583
- suggestions.append (maybe_negate (#name)); \
1584
- suggestions.last ().input_offset = offset; \
1585
- }
1603
+ if (#name##sv.starts_with (option_pattern)) \
1604
+ suggestions.append (maybe_negate (#name));
1586
1605
1587
1606
ENUMERATE_SHELL_OPTIONS ();
1588
1607
#undef __ENUMERATE_SHELL_OPTION
1608
+
1609
+ for (auto & entry : suggestions) {
1610
+ entry.input_offset = offset;
1611
+ entry.invariant_offset = invariant_offset;
1612
+ entry.static_offset = static_offset;
1613
+ }
1614
+
1589
1615
return suggestions;
1590
1616
}
1591
1617
}
@@ -1596,18 +1622,24 @@ Vector<Line::CompletionSuggestion> Shell::complete_immediate_function_name(Strin
1596
1622
{
1597
1623
Vector<Line::CompletionSuggestion> suggestions;
1598
1624
1599
- #define __ENUMERATE_SHELL_IMMEDIATE_FUNCTION (fn_name ) \
1600
- if (auto name_view = #fn_name##sv; name_view.starts_with (name)) { \
1601
- suggestions.append ({ name_view, " " }); \
1602
- suggestions.last ().input_offset = offset; \
1603
- }
1625
+ auto invariant_offset = offset;
1626
+ size_t static_offset = 0 ;
1627
+ if (m_editor)
1628
+ m_editor->transform_suggestion_offsets (invariant_offset, static_offset);
1629
+
1630
+ #define __ENUMERATE_SHELL_IMMEDIATE_FUNCTION (fn_name ) \
1631
+ if (auto name_view = #fn_name##sv; name_view.starts_with (name)) \
1632
+ suggestions.append ({ name_view, " " });
1604
1633
1605
1634
ENUMERATE_SHELL_IMMEDIATE_FUNCTIONS ();
1606
1635
1607
1636
#undef __ENUMERATE_SHELL_IMMEDIATE_FUNCTION
1608
1637
1609
- if (m_editor)
1610
- m_editor->suggest (offset);
1638
+ for (auto & entry : suggestions) {
1639
+ entry.input_offset = offset;
1640
+ entry.invariant_offset = invariant_offset;
1641
+ entry.static_offset = static_offset;
1642
+ }
1611
1643
1612
1644
return suggestions;
1613
1645
}
0 commit comments