mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Improve tab trigger boundary checks
When two neighboring characters have different character class or one is an alpha numeric character (excl. underscore) and the other is not, we consider this a valid boundary for a tab trigger. This closes issue #157.
This commit is contained in:
@@ -84,9 +84,16 @@ static std::vector<bundles::item_ptr> items_for_tab_expansion (ng::buffer_t cons
|
||||
size_t line = buffer.convert(caret).line;
|
||||
size_t bol = buffer.begin(line);
|
||||
|
||||
bool lastWasWordChar = false;
|
||||
std::string lastCharacterClass = ng::kCharacterClassUnknown;
|
||||
|
||||
for(size_t i = bol; i < caret; i += buffer[i].size())
|
||||
{
|
||||
if(i == bol || !text::is_word_char(buffer[i-1]))
|
||||
// we don’t use text::is_word_char because that function treats underscores as word characters, which is undesired, see <issue://157>.
|
||||
bool isWordChar = CFCharacterSetIsLongCharacterMember(CFCharacterSetGetPredefined(kCFCharacterSetAlphaNumeric), utf8::to_ch(buffer[i]));
|
||||
std::string characterClass = character_class(buffer, i);
|
||||
|
||||
if(i == bol || lastWasWordChar != isWordChar || lastCharacterClass != characterClass)
|
||||
{
|
||||
std::vector<bundles::item_ptr> const& items = bundles::query(bundles::kFieldTabTrigger, buffer.substr(i, caret), ng::scope(buffer, ng::ranges_t(i), scopeAttributes));
|
||||
if(!items.empty())
|
||||
@@ -96,6 +103,9 @@ static std::vector<bundles::item_ptr> items_for_tab_expansion (ng::buffer_t cons
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
lastWasWordChar = isWordChar;
|
||||
lastCharacterClass = characterClass;
|
||||
}
|
||||
|
||||
return std::vector<bundles::item_ptr>();
|
||||
|
||||
Reference in New Issue
Block a user