On 23/02/03 4:26 AM, Bram Moolenaar wrote:
> Ernie Rael wrote:
>
>> I want to determine what text property, if any, is under the mouse
>> position. The best options seems to be
>>
>> prop_find({lnum: mpos.line, col: mpos.column, ...})
>>
>> and then check if the returned property covers the mouse position.
>>
>> I am wondering about having an "exact: true" option in prop_find's
>> "search for" options. When "exact: true" a property is only returned
>> if (lnum, col) are covered by the property, otherwise an empty
>> dictionary is returned.
>>
>> Using this would minimize extra code, including vim9 code to check
>> if returned property covers mouse pos. This is used on every mouse
>> movement event, would be nice to minimize overhead.
>>
>> Would a patch that adds "exact: true" be considered? I haven't looked
>> at the code yet; first looking for comments on this approach.
> prop_find() can be inefficient, since it searches the whole buffer.
> That is especially when no match is found.
Right. The idea is that when "exact: true", prop_find only checks if
there is a prop
match at lnum/col. If there is a match, return the prop otherwise
immediately return
empty; there is no search when "exact" is true. I suppose
"exact_location" is more
descriptive, but longer.
>
> How about using prop_list() instead? It only checks for properties in
> one line, which is what you want. We could add a "col" entry in the
> {props} argument to narrow down to properties that include this column.
The current prop_list is not too bad since the search already can be
limited. Still requires
searching the returned list. Was trying to avoid checking if the
returned props overlap
mouse pos, but I tend to over optimize while looking to minimize
vim9script code in favor
of builtins.
I almost didn't mention it at all since it does seem pretty minor, I
even thought about
prop_find_at(...) which implies exact and lnum/col could be required
positional args.
Like I said, tend to over optimize.
-ernie