Merge lp:~jeremy-munsch/synapse-project/native-de-shortcut into lp:synapse-project

Proposed by Jérémy Munsch
Status: Merged
Merged at revision: 631
Proposed branch: lp:~jeremy-munsch/synapse-project/native-de-shortcut
Merge into: lp:synapse-project
Diff against target: 107 lines (+47/-0)
3 files modified
src/core/utils.vala (+26/-0)
src/ui/controller.vala (+17/-0)
src/ui/keybindings.vala (+4/-0)
To merge this branch: bzr merge lp:~jeremy-munsch/synapse-project/native-de-shortcut
Reviewer Review Type Date Requested Status
Rico Tzschichholz Approve
Review via email: mp+277817@code.launchpad.net

Description of the change

Add shortcut ctrl+backspace for delete word

To post a comment you must log in.
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

https://paste.debian.net/plain/333517

"remove_last_word" is not working correctly so please test this part more.

"Hello you" > ""
"Hello you " > "Hello"
-> both should result in "Hello " or "Hello"?

review: Needs Fixing
Revision history for this message
Jérémy Munsch (jeremy-munsch) wrote :

Well i just tested:

"Hello you" > "Hello" *OK*
"Hello you " > "Hello you" *NO OK*

also :
"Hello" > "" *OK*
"Hello " > "" *NO OK*
"Hello you little" > "Hello you" *OK*
"Hello you little " > "Hello you little" *NO OK*

I cannot reproduce "Hello you" > "", this is unwanted behaviour indeed.

I'll make corrections

Revision history for this message
Jérémy Munsch (jeremy-munsch) wrote :

Sorry i mistaped test:

"Hello " > "Hello" *NO OK*

Revision history for this message
Jérémy Munsch (jeremy-munsch) wrote :

launchpad is removing multiple spaces, but it check words like '_' == ' '
"Hello_you______little" > "Hello_you" *OK*
"Hello_you________little_" > "Hello_you ________little" *NO OK*

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Ok, looks like it gets called twice on my system, so "remove_last_word" is called to often but what it does is correct.

Revision history for this message
Jérémy Munsch (jeremy-munsch) wrote :
Revision history for this message
Jérémy Munsch (jeremy-munsch) wrote :

> Ok, looks like it gets called twice on my system, so "remove_last_word" is
> called to often but what it does is correct.

That may be the input method again, this is causing lot of troubles (é_è) <-- sad dude

Which input metod are you using ? Does using GTK_IM_METHOD changes this ?
I am using GTK_IM_METHOD='' synapse on my system, otherwise it crash, this is also a workaround for #1500912

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Hmm, right, here it is the default: GTK_IM_MODULE="ibus"
With GTK_IM_MODULE="" it works as it is intended.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Do not make the argument owned.

The trailing space should be preserved after cutting off the last word.

review: Needs Fixing
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

I have taken a look at the remove_last_word method.

It should work in all cases that way
https://paste.debian.net/plain/333745

Jfyi, regarding "space_index = -1 == space_index ? 0 : space_index+1;". You can't simply do "space_index+1" since this might not be a valid byte-position in this utf8 string.

review: Needs Fixing
631. By Jérémy Munsch

Add shortcut ctrl+backspace for delete word

Revision history for this message
Jérémy Munsch (jeremy-munsch) wrote :

Ok thank you, I applied the patch.

> Jfyi, regarding "space_index = -1 == space_index ? 0 : space_index+1;". You
> can't simply do "space_index+1" since this might not be a valid byte-position
> in this utf8 string.

Indeed I haven't taught about that.

Revision history for this message
Rico Tzschichholz (ricotz) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/utils.vala'
2--- src/core/utils.vala 2015-11-15 17:19:04 +0000
3+++ src/core/utils.vala 2015-11-19 09:11:53 +0000
4@@ -54,6 +54,32 @@
5 return input.substring (0, len);
6 }
7
8+ public static string remove_last_word (string input)
9+ {
10+ long char_count = input.char_count ();
11+ int index = input.index_of_nth_char (char_count - 1);
12+ unichar pchar = input.get_char (index);
13+
14+ while (pchar == ' ' && index > 0)
15+ {
16+ input.get_prev_char (ref index, out pchar);
17+ }
18+
19+ int next_index = index;
20+
21+ do
22+ {
23+ index = next_index;
24+ input.get_prev_char (ref next_index, out pchar);
25+ }
26+ while (pchar != ' ' && next_index > 0);
27+
28+ if (next_index <= 0)
29+ return "";
30+ else
31+ return input.slice (0, index);
32+ }
33+
34 public static async bool query_exists_async (GLib.File f)
35 {
36 bool exists;
37
38=== modified file 'src/ui/controller.vala'
39--- src/ui/controller.vala 2014-07-10 11:39:28 +0000
40+++ src/ui/controller.vala 2015-11-19 09:11:53 +0000
41@@ -231,6 +231,14 @@
42 }
43 }
44
45+ protected void search_delete_word ()
46+ {
47+ if (model.query[model.searching_for] == "") return;
48+ model.query[model.searching_for] = Synapse.Utils.remove_last_word (model.query[model.searching_for]);
49+
50+ search ();
51+ }
52+
53 protected void search_add_delete_char (string? newchar = null)
54 {
55 if (newchar == null)
56@@ -246,6 +254,12 @@
57 model.query[model.searching_for] =
58 model.query[model.searching_for] + newchar;
59 }
60+
61+ search ();
62+ }
63+
64+ void search ()
65+ {
66 switch (model.searching_for)
67 {
68 case SearchingFor.SOURCES:
69@@ -299,6 +313,9 @@
70 case KeyComboConfig.Commands.SEARCH_DELETE_CHAR:
71 search_add_delete_char ();
72 break;
73+ case KeyComboConfig.Commands.SEARCH_DELETE_WORD:
74+ search_delete_word ();
75+ break;
76 case KeyComboConfig.Commands.CLEAR_SEARCH_OR_HIDE:
77 clear_search_or_hide_pressed ();
78 break;
79
80=== modified file 'src/ui/keybindings.vala'
81--- src/ui/keybindings.vala 2014-07-10 11:39:28 +0000
82+++ src/ui/keybindings.vala 2015-11-19 09:11:53 +0000
83@@ -31,6 +31,7 @@
84 ACTIVATE,
85 INVALID_COMMAND,
86 SEARCH_DELETE_CHAR,
87+ SEARCH_DELETE_WORD,
88 NEXT_RESULT,
89 PREV_RESULT,
90 NEXT_CATEGORY,
91@@ -55,6 +56,7 @@
92 public string execute { get; set; default = "Return"; }
93 public string execute_without_hide { get; set; default = "<Shift>Return"; }
94 public string delete_char { get; set; default = "BackSpace"; }
95+ public string delete_word { get; set; default = "<Control>BackSpace"; }
96 public string alternative_delete_char { get; set; default = "Delete"; }
97 public string next_match { get; set; default = "Down"; }
98 public string prev_match { get; set; default = "Up"; }
99@@ -168,6 +170,8 @@
100 kcs.set_keycombo_command (keyval, mods, Commands.SEARCH_DELETE_CHAR);
101 name_to_key_mod (alternative_delete_char, out keyval, out mods);
102 kcs.set_keycombo_command (keyval, mods, Commands.SEARCH_DELETE_CHAR);
103+ name_to_key_mod (delete_word, out keyval, out mods);
104+ kcs.set_keycombo_command (keyval, mods, Commands.SEARCH_DELETE_WORD);
105 name_to_key_mod (next_match, out keyval, out mods);
106 kcs.set_keycombo_command (keyval, mods, Commands.NEXT_RESULT);
107 name_to_key_mod (prev_match, out keyval, out mods);