From 0bb02227debf79602027ffde870fc61762f887c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 17 Sep 2023 22:35:41 +0200 Subject: [PATCH] Use attributes at cursor position for insertions in `Editor` --- src/edit/editor.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/edit/editor.rs b/src/edit/editor.rs index 31ebf31..274e05b 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -235,8 +235,12 @@ impl Edit for Editor { let after_len = after.text().len(); // Collect attributes - let mut final_attrs = attrs_list - .unwrap_or_else(|| AttrsList::new(line.attrs_list().get_span(line.text().len()))); + let mut final_attrs = attrs_list.unwrap_or_else(|| { + AttrsList::new( + line.attrs_list() + .get_span(self.cursor.index.saturating_sub(1)), + ) + }); // Append the inserted text, line by line // we want to see a blank entry if the string ends with a newline