From 66b1bdc9c90e1f29ecec096286136b527ec6b8ed Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 15 Sep 2023 18:00:27 +0200 Subject: Refactor: Preferred positions for extra keys The new PreferredPos class represents where an extra key should be placed Currently used to place keys at the same positions they were placed before. --- srcs/juloo.keyboard2/ExtraKeys.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'srcs/juloo.keyboard2/ExtraKeys.java') diff --git a/srcs/juloo.keyboard2/ExtraKeys.java b/srcs/juloo.keyboard2/ExtraKeys.java index cfac362..aa2e38f 100644 --- a/srcs/juloo.keyboard2/ExtraKeys.java +++ b/srcs/juloo.keyboard2/ExtraKeys.java @@ -22,7 +22,7 @@ class ExtraKeys /** Add the keys that should be added to the keyboard into [dst]. Keys already added to [dst] might have an impact, see [ExtraKey.compute]. */ - public void compute(Set dst, Query q) + public void compute(Map dst, Query q) { for (ExtraKey k : _ks) k.compute(dst, q); @@ -72,7 +72,7 @@ class ExtraKeys } /** Whether the key should be added to the keyboard. */ - public void compute(Set dst, Query q) + public void compute(Map dst, Query q) { // Add the alternative if it's the only one. The list of alternatives is // enforced to be complete by the merging step. The same [kv] will not @@ -80,11 +80,14 @@ class ExtraKeys // alternatives. // Selecting the dead key in the "Add key to the keyboard" option would // disable this behavior for a key. - boolean use_alternative = (alternatives.size() == 1 && !dst.contains(kv)); + boolean use_alternative = (alternatives.size() == 1 && !dst.containsKey(kv)); if ((q.script == null || script == null || q.script.equals(script)) && (alternatives.size() == 0 || !q.present.containsAll(alternatives))) - dst.add(use_alternative ? alternatives.get(0) : kv); + { + KeyValue kv_ = use_alternative ? alternatives.get(0) : kv; + dst.put(kv_, KeyboardData.PreferredPos.DEFAULT); + } } /** Return a new key from two. [kv] are expected to be equal. [script] is -- cgit v1.2.3