feat: support nip46

This commit is contained in:
2025-02-10 13:46:51 +07:00
parent c4573ef1da
commit 0347e8b3c5
7 changed files with 352 additions and 127 deletions

View File

@@ -1504,14 +1504,20 @@ impl EntityInputHandler for TextInput {
let mut index_offset = 0;
for line in lines.iter() {
if let Some(p) = line.position_for_index(range.start - index_offset, line_height) {
if let Some(p) =
line.position_for_index(range.start.saturating_sub(index_offset), line_height)
{
start_origin = Some(p + point(px(0.), y_offset));
}
if let Some(p) = line.position_for_index(range.end - index_offset, line_height) {
if let Some(p) =
line.position_for_index(range.end.saturating_sub(index_offset), line_height)
{
end_origin = Some(p + point(px(0.), y_offset));
}
y_offset += line.size(line_height).height;
if start_origin.is_some() && end_origin.is_some() {
break;
}
@@ -1519,18 +1525,30 @@ impl EntityInputHandler for TextInput {
index_offset += line.len();
}
let start_origin = start_origin.unwrap_or_default();
let end_origin = end_origin.unwrap_or_default();
Some(Bounds::from_corners(
bounds.origin + start_origin.unwrap_or_default(),
bounds.origin + end_origin.unwrap_or_default(),
bounds.origin + start_origin,
// + line_height for show IME panel under the cursor line.
bounds.origin + point(end_origin.x, end_origin.y + line_height),
))
}
fn character_index_for_point(
&mut self,
_point: gpui::Point<Pixels>,
point: gpui::Point<Pixels>,
_window: &mut Window,
_cx: &mut Context<Self>,
) -> Option<usize> {
let line_height = self.last_line_height;
let line_point = self.last_bounds?.localize(&point)?;
let lines = self.last_layout.as_ref()?;
for line in lines.iter() {
if let Ok(utf8_index) = line.index_for_position(line_point, line_height) {
return Some(self.offset_to_utf16(utf8_index));
}
}
None
}
}