mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
✨ Show text cursor in the entire text rect
This commit is contained in:
@@ -189,6 +189,7 @@ impl TextContentLayout {
|
||||
* Check if the current x,y (in paragraph relative coordinates) is inside
|
||||
* the paragraph
|
||||
*/
|
||||
#[allow(dead_code)]
|
||||
fn intersects(paragraph: &skia_safe::textlayout::Paragraph, x: f32, y: f32) -> bool {
|
||||
if y < 0.0 || y > paragraph.height() {
|
||||
return false;
|
||||
@@ -693,7 +694,28 @@ impl TextContent {
|
||||
(fallback_width, fallback_height)
|
||||
}
|
||||
|
||||
pub fn intersect_position(&self, shape: &Shape, x_pos: f32, y_pos: f32) -> bool {
|
||||
pub fn intersect_position_in_shape(&self, shape: &Shape, x_pos: f32, y_pos: f32) -> bool {
|
||||
let rect = shape.selrect;
|
||||
let mut matrix = Matrix::new_identity();
|
||||
let center = shape.center();
|
||||
let Some(inv_transform) = &shape.transform.invert() else {
|
||||
return false;
|
||||
};
|
||||
matrix.pre_translate(center);
|
||||
matrix.pre_concat(inv_transform);
|
||||
matrix.pre_translate(-center);
|
||||
|
||||
let result = matrix.map_point((x_pos, y_pos));
|
||||
|
||||
let x_pos = result.x;
|
||||
let y_pos = result.y;
|
||||
|
||||
x_pos >= rect.x() && x_pos <= rect.right() && y_pos >= rect.y() && y_pos <= rect.bottom()
|
||||
}
|
||||
|
||||
// Leave this function for future use in the upcoming render editor
|
||||
#[allow(dead_code)]
|
||||
pub fn intersect_position_in_text(&self, shape: &Shape, x_pos: f32, y_pos: f32) -> bool {
|
||||
let rect = self.content_rect(&shape.selrect, shape.vertical_align);
|
||||
let mut matrix = Matrix::new_identity();
|
||||
let center = shape.center();
|
||||
|
||||
@@ -341,7 +341,7 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn intersect_position(
|
||||
pub extern "C" fn intersect_position_in_shape(
|
||||
a: u32,
|
||||
b: u32,
|
||||
c: u32,
|
||||
@@ -355,7 +355,7 @@ pub extern "C" fn intersect_position(
|
||||
return false;
|
||||
};
|
||||
if let Type::Text(content) = &shape.shape_type {
|
||||
return content.intersect_position(shape, x_pos, y_pos);
|
||||
return content.intersect_position_in_shape(shape, x_pos, y_pos);
|
||||
}
|
||||
});
|
||||
false
|
||||
|
||||
Reference in New Issue
Block a user