Merge pull request #8745 from penpot/azazeln28-fix-text-selection-misalignment

🐛 Fix text selection misalignment
This commit is contained in:
Alejandro Alonso 2026-03-24 11:43:44 +01:00 committed by GitHub
commit 2ceb2c8d95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 20 deletions

View File

@ -1,14 +1,9 @@
use crate::shapes::{Shape, TextContent, Type, VerticalAlign}; use crate::shapes::{Shape, TextContent, Type, VerticalAlign};
use crate::state::{TextEditorState, TextSelection}; use crate::state::{TextEditorState, TextSelection};
use skia_safe::textlayout::{RectHeightStyle, RectWidthStyle}; use skia_safe::textlayout::{RectHeightStyle, RectWidthStyle};
use skia_safe::{BlendMode, Canvas, Matrix, Paint, Rect}; use skia_safe::{BlendMode, Canvas, Paint, Rect};
pub fn render_overlay( pub fn render_overlay(canvas: &Canvas, editor_state: &TextEditorState, shape: &Shape) {
canvas: &Canvas,
editor_state: &TextEditorState,
shape: &Shape,
transform: &Matrix,
) {
if !editor_state.is_active { if !editor_state.is_active {
return; return;
} }
@ -18,16 +13,12 @@ pub fn render_overlay(
}; };
canvas.save(); canvas.save();
canvas.concat(transform);
if editor_state.selection.is_selection() { if editor_state.selection.is_selection() {
render_selection(canvas, editor_state, text_content, shape); render_selection(canvas, editor_state, text_content, shape);
} }
if editor_state.cursor_visible { if editor_state.cursor_visible {
render_cursor(canvas, editor_state, text_content, shape); render_cursor(canvas, editor_state, text_content, shape);
} }
canvas.restore(); canvas.restore();
} }

View File

@ -1212,6 +1212,7 @@ impl Shape {
matrix matrix
} }
#[allow(dead_code)]
pub fn get_concatenated_matrix(&self, shapes: ShapesPoolRef) -> Matrix { pub fn get_concatenated_matrix(&self, shapes: ShapesPoolRef) -> Matrix {
let mut matrix = Matrix::new_identity(); let mut matrix = Matrix::new_identity();
let mut current_id = self.id; let mut current_id = self.id;

View File

@ -2,6 +2,8 @@ use macros::{wasm_error, ToJs};
use crate::math::{Matrix, Point, Rect}; use crate::math::{Matrix, Point, Rect};
use crate::mem; use crate::mem;
use crate::render::text_editor as text_editor_render;
use crate::render::SurfaceId;
use crate::shapes::{Shape, TextContent, TextPositionWithAffinity, Type, VerticalAlign}; use crate::shapes::{Shape, TextContent, TextPositionWithAffinity, Type, VerticalAlign};
use crate::state::TextSelection; use crate::state::TextSelection;
use crate::utils::uuid_from_u32_quartet; use crate::utils::uuid_from_u32_quartet;
@ -841,21 +843,13 @@ pub extern "C" fn text_editor_render_overlay() {
return; return;
}; };
let transform = shape.get_concatenated_matrix(&state.shapes);
use crate::render::text_editor as te_render;
use crate::render::SurfaceId;
let canvas = state.render_state.surfaces.canvas(SurfaceId::Target); let canvas = state.render_state.surfaces.canvas(SurfaceId::Target);
canvas.save(); canvas.save();
let viewbox = state.render_state.viewbox; let viewbox = state.render_state.viewbox;
let zoom = viewbox.zoom * state.render_state.options.dpr(); let zoom = viewbox.zoom * state.render_state.options.dpr();
canvas.scale((zoom, zoom)); canvas.scale((zoom, zoom));
canvas.translate((-viewbox.area.left, -viewbox.area.top)); canvas.translate((-viewbox.area.left, -viewbox.area.top));
text_editor_render::render_overlay(canvas, &state.text_editor_state, shape);
te_render::render_overlay(canvas, &state.text_editor_state, shape, &transform);
canvas.restore(); canvas.restore();
state.render_state.flush_and_submit(); state.render_state.flush_and_submit();
}); });