-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get full unicode char at cursor position
Closes #864
- Loading branch information
Showing
3 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local context = require('blink.cmp.completion.trigger.context') | ||
local utils = {} | ||
|
||
--- Gets the full Unicode character at cursor position | ||
--- @return string | ||
function utils.get_char_at_cursor() | ||
local line = context.get_line() | ||
local cursor_col = context.get_cursor()[2] | ||
|
||
-- Find the start of the UTF-8 character | ||
local start_col = cursor_col | ||
while start_col > 1 do | ||
local char = string.byte(line:sub(start_col, start_col)) | ||
if char < 0x80 or char > 0xBF then break end | ||
start_col = start_col - 1 | ||
end | ||
|
||
-- Find the end of the UTF-8 character | ||
local end_col = cursor_col | ||
while end_col < #line do | ||
local char = string.byte(line:sub(end_col + 1, end_col + 1)) | ||
if char < 0x80 or char > 0xBF then break end | ||
end_col = end_col + 1 | ||
end | ||
|
||
return line:sub(start_col, end_col) | ||
end | ||
|
||
return utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters