Repository: flxzt/rnote (language: rust)

Issue:
Unable to select text using stylus
**Describe the bug**  
Using the typewriter, trying to select text with stylus immediately undoes the selection when you lift the stylus away from the screen. It works completely fine with mouse.

.

**Screenshots**  

https://github.com/user-attachments/assets/96fac41a-0fbc-4db9-a403-f7f471fae21e



**Desktop (please complete the following information):**  
 I think you already know those lol but here it goes:
 - OS: Fedora 40
 - App Version: 0.11.0
 - Installation Source: Flatpak
 - Desktop Environment: Gnome 46
 - Display Server: Wayland
 - Input Source: Onscreen tablet



Discussion / hints:

Fix patch:
diff --git a/crates/rnote-engine/src/pens/typewriter/mod.rs b/crates/rnote-engine/src/pens/typewriter/mod.rs
index 928bd80c80..074ff03e27 100644
--- a/crates/rnote-engine/src/pens/typewriter/mod.rs
+++ b/crates/rnote-engine/src/pens/typewriter/mod.rs
@@ -206,7 +206,7 @@ impl DrawableOnDoc for Typewriter {
                     );
                     let adjust_text_width_node_state = match modify_state {
                         ModifyState::AdjustTextWidth { .. } => PenState::Down,
-                        ModifyState::Idle => {
+                        ModifyState::Idle | ModifyState::Selecting { .. } => {
                             if let Some(pos) = self.pos {
                                 if adjust_text_width_node_bounds.contains_local_point(&pos.into()) {
                                     PenState::Proximity
@@ -238,7 +238,7 @@ impl DrawableOnDoc for Typewriter {
                             Self::translate_node_bounds(typewriter_bounds, engine_view.camera);
                         let translate_node_state = match modify_state {
                             ModifyState::Translating { .. } => PenState::Down,
-                            ModifyState::Idle => {
+                            ModifyState::Idle | ModifyState::Selecting { .. } => {
                                 if let Some(pos) = self.pos {
                                     if translate_node_bounds.contains_local_point(&pos.into()) {
                                         PenState::Proximity
diff --git a/crates/rnote-engine/src/pens/typewriter/penevents.rs b/crates/rnote-engine/src/pens/typewriter/penevents.rs
index f315ce4e32..b14c529bff 100644
--- a/crates/rnote-engine/src/pens/typewriter/penevents.rs
+++ b/crates/rnote-engine/src/pens/typewriter/penevents.rs
@@ -445,7 +445,12 @@ impl Typewriter {
                 pen_down,
                 ..
             } => {
-                *modify_state = ModifyState::Idle;
+                if !matches!(modify_state, ModifyState::Selecting { .. }) {
+                    // do nothing if the state is selected
+                    // This prevents text from becoming deselected when hovering the pen
+                    // see issue #1222
+                    *modify_state = ModifyState::Idle;
+                }
                 *pen_down = false;
 
                 EventResult {


Test patch: