Yi Ming
9174157f74
feat(pos): pos:to_offset(), pos.offset() #39564
...
Problem:
For a given position, it is not easy to compare which of several other positions is closest to it.
Solution:
Add support for converting `vim.Pos` to a buffer byte offset.
This allows for sorting, e.g:
```lua
table.sort(positions, function(pos1, pos2)
return pos1:to_offset() < pos2:to_offset()
end
```
Or a binary search, e.g:
```lua
vim.list.bisect(positions, pos, { key = function(pos) return pos:to_offset() end })
```
2026-05-06 16:37:16 -04:00
..
2026-05-06 11:15:31 -04:00
2025-05-06 05:15:31 -07:00
2026-05-06 08:55:34 -04:00
2026-03-13 20:32:01 +01:00
2026-05-06 08:15:00 -04:00
2026-04-18 06:50:28 -04:00
2026-03-13 20:32:01 +01:00
2026-04-20 02:31:09 +02:00
2026-05-06 08:15:00 -04:00
2025-08-17 20:40:28 -07:00
2026-04-25 20:29:19 +03:00
2026-05-06 08:15:00 -04:00
2026-05-06 08:15:00 -04:00
2026-04-30 07:26:40 -04:00
2025-12-16 13:22:05 -05:00
2026-03-13 15:57:36 -04:00
2026-04-30 07:26:40 -04:00
2026-04-30 07:12:35 -04:00
2026-05-06 16:02:59 +01:00
2026-02-23 17:33:13 -05:00
2026-05-06 08:15:00 -04:00
2026-05-06 11:13:15 -04:00
2026-04-30 07:12:35 -04:00
2026-04-25 11:16:18 -04:00
2026-02-12 07:15:20 -05:00
2026-01-12 10:58:01 -08:00
2026-04-24 11:57:35 -04:00
2026-04-30 07:12:35 -04:00
2026-01-09 10:07:15 +01:00
2026-05-06 16:02:59 +01:00
2026-03-23 08:00:53 -04:00
2026-03-12 11:04:05 -04:00
2026-04-30 05:56:16 -04:00
2026-05-05 16:26:59 -04:00
2026-05-06 08:15:00 -04:00
2026-05-06 16:37:16 -04:00
2024-02-03 16:53:41 +01:00
2026-04-27 13:43:46 -04:00
2025-02-10 03:04:01 -08:00
2026-04-24 07:37:21 -04:00
2026-04-30 07:12:35 -04:00
2025-07-12 20:54:22 -07:00
2026-05-06 08:15:00 -04:00
2026-04-30 07:26:40 -04:00
2026-04-28 18:29:17 -04:00
2026-04-30 07:12:35 -04:00
2026-04-08 13:33:00 -04:00