From 5d62cf7901d1998c26b09adfe49152aaa4728246 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 15 Jun 2025 16:46:19 +0200 Subject: [PATCH] Avoid the selection being empty in selection mode Emptying the selection with the spacebar slider puts the selection mode in an unexpected state. This checks that this doesn't happen. For example, moving the right end of the selection (by going right then left in a single stroke) after it reached the left end will push it with every steps to keep the selection of size 1. --- srcs/juloo.keyboard2/KeyEventHandler.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 0dd7f87..11c89cd 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -320,10 +320,16 @@ public final class KeyEventHandler { int sel_start = et.selectionStart; int sel_end = et.selectionEnd; - if (sel_left == (sel_start <= sel_end)) - sel_start += d; - else - sel_end += d; + boolean modify_sel_start = sel_left == (sel_start <= sel_end); + do + { + if (modify_sel_start) + sel_start += d; + else + sel_end += d; + // Move the cursor twice if moving it once would make the selection + // empty and stop selection mode. + } while (sel_start == sel_end); if (conn.setSelection(sel_start, sel_end)) return; // Fallback to sending key events if [setSelection] failed }