Skip to content

Commit 56a2dc9

Browse files
committed
Merge branch 'master' of github.com:cristianfalvo/gnome-shell-extension-clipboard-indicator into cristianfalvo-master
2 parents 5769ad9 + b7a22c8 commit 56a2dc9

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ export const PrefsFields = {
2828
CLEAR_HISTORY_ON_INTERVAL : 'clear-history-on-interval',
2929
CLEAR_HISTORY_INTERVAL : 'clear-history-interval',
3030
NEXT_HISTORY_CLEAR : 'next-history-clear',
31+
CASE_SENSITIVE_SEARCH : 'case-sensitive-search',
32+
REGEX_SEARCH : 'regex-search',
3133
};

extension.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ let EXCLUDED_APPS = [];
4545
let CLEAR_HISTORY_ON_INTERVAL = false;
4646
let CLEAR_HISTORY_INTERVAL = 60;
4747
let NEXT_HISTORY_CLEAR = -1;
48+
let CASE_SENSITIVE_SEARCH = false;
49+
let REGEX_SEARCH = false;
4850

4951
export default class ClipboardIndicatorExtension extends Extension {
5052
enable () {
@@ -401,7 +403,10 @@ const ClipboardIndicator = GObject.registerClass({
401403
items. It the entry is empty, the section is restored with all items
402404
set as visible. */
403405
_onSearchTextChanged () {
404-
let searchedText = this.searchEntry.get_text().toLowerCase();
406+
407+
// Text to be searched converted to lowercase if search is case insensitive
408+
let searchedText = this.searchEntry.get_text();
409+
if (!CASE_SENSITIVE_SEARCH) searchedText = searchedText.toLowerCase();
405410

406411
if(searchedText === '') {
407412
this._getAllIMenuItems().forEach(function(mItem){
@@ -410,8 +415,21 @@ const ClipboardIndicator = GObject.registerClass({
410415
}
411416
else {
412417
this._getAllIMenuItems().forEach(function(mItem){
413-
let text = mItem.clipContents.toLowerCase();
414-
let isMatching = text.indexOf(searchedText) >= 0;
418+
// Clip content converted to lowercase if search is case insensitive
419+
let text = mItem.clipContents;
420+
if (!CASE_SENSITIVE_SEARCH) text = text.toLowerCase();
421+
422+
let isMatching = false;
423+
if (REGEX_SEARCH){
424+
/* Regex flags:
425+
- 'm' for multiline matching (when multiline content is copied)
426+
- 'i' for case insensitive matching when search is not set to case sensitive
427+
*/
428+
let text_regex = new RegExp(searchedText, 'm' + (CASE_SENSITIVE_SEARCH ? '' : 'i'));
429+
isMatching = text_regex.test(text);
430+
}else{
431+
isMatching = text.indexOf(searchedText) >= 0;
432+
}
415433
mItem.actor.visible = isMatching
416434
});
417435
}
@@ -1115,6 +1133,8 @@ const ClipboardIndicator = GObject.registerClass({
11151133
CLEAR_HISTORY_ON_INTERVAL = settings.get_boolean(PrefsFields.CLEAR_HISTORY_ON_INTERVAL);
11161134
CLEAR_HISTORY_INTERVAL = settings.get_int(PrefsFields.CLEAR_HISTORY_INTERVAL);
11171135
NEXT_HISTORY_CLEAR = settings.get_int(PrefsFields.NEXT_HISTORY_CLEAR);
1136+
CASE_SENSITIVE_SEARCH = settings.get_boolean(PrefsFields.CASE_SENSITIVE_SEARCH);
1137+
REGEX_SEARCH = settings.get_boolean(PrefsFields.REGEX_SEARCH);
11181138
}
11191139

11201140
async _onSettingsChange () {

prefs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class ClipboardIndicatorPreferences extends ExtensionPreferences
1313
const page = new Adw.PreferencesPage();
1414
page.add(settingsUI.ui);
1515
page.add(settingsUI.behavior);
16+
page.add(settingsUI.search);
1617
page.add(settingsUI.limits);
1718
page.add(settingsUI.exclusion);
1819
page.add(settingsUI.topbar);
@@ -134,6 +135,14 @@ class Settings {
134135
halign: Gtk.Align.CENTER,
135136
});
136137

138+
this.case_sensitive_search = new Adw.SwitchRow({
139+
title: _("Case-sensitive search")
140+
});
141+
142+
this.regex_search = new Adw.SwitchRow({
143+
title: _("Regular expression matching in search")
144+
});
145+
137146
this.field_exclusion_row_add_button.connect('clicked', () => {
138147
this.field_exclusion_row_add_button.set_sensitive(false);
139148
this.excluded_row_counter++;
@@ -167,6 +176,7 @@ class Settings {
167176
this.topbar = new Adw.PreferencesGroup({ title: _('Topbar') });
168177
this.notifications = new Adw.PreferencesGroup({ title: _('Notifications') });
169178
this.shortcuts = new Adw.PreferencesGroup({ title: _('Shortcuts') });
179+
this.search = new Adw.PreferencesGroup({title: _('Search')});
170180

171181
this.ui.add(this.field_preview_size);
172182
this.ui.add(this.field_move_item_first);
@@ -196,6 +206,9 @@ class Settings {
196206
this.notifications.add(this.field_cycle_notification_toggle)
197207
this.notifications.add(this.field_confirm_clear_toggle);
198208

209+
this.search.add(this.case_sensitive_search);
210+
this.search.add(this.regex_search);
211+
199212
this.#buildShorcuts(this.shortcuts);
200213

201214
this.schema.bind(PrefsFields.HISTORY_SIZE, this.field_size, 'value', Gio.SettingsBindFlags.DEFAULT);
@@ -219,6 +232,8 @@ class Settings {
219232
this.schema.bind(PrefsFields.CACHE_IMAGES, this.field_cache_images, 'active', Gio.SettingsBindFlags.DEFAULT);
220233
this.schema.bind(PrefsFields.CLEAR_HISTORY_ON_INTERVAL, this.field_clear_history_on_interval, 'active', Gio.SettingsBindFlags.DEFAULT);
221234
this.schema.bind(PrefsFields.CLEAR_HISTORY_INTERVAL, this.field_clear_history_interval, 'value', Gio.SettingsBindFlags.DEFAULT);
235+
this.schema.bind(PrefsFields.CASE_SENSITIVE_SEARCH, this.case_sensitive_search, 'active', Gio.SettingsBindFlags.DEFAULT);
236+
this.schema.bind(PrefsFields.REGEX_SEARCH, this.regex_search, 'active', Gio.SettingsBindFlags.DEFAULT);
222237

223238
this.field_clear_history_interval.set_sensitive(this.field_clear_history_on_interval.active);
224239
this.#fetchExludedAppsList();

schemas/gschemas.compiled

95 Bytes
Binary file not shown.

schemas/org.gnome.shell.extensions.clipboard-indicator.gschema.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,15 @@
215215
The timestamp for the next scheduled history clear.
216216
</description>
217217
</key>
218+
<key name="case-sensitive-search" type="b">
219+
<default>false</default>
220+
<summary>Case sensitive search</summary>
221+
<description>Make search case sensitive</description>
222+
</key>
223+
<key name="regex-search" type="b">
224+
<default>false</default>
225+
<summary>Regex-based search</summary>
226+
<description>Allow regex in search</description>
227+
</key>
218228
</schema>
219229
</schemalist>

0 commit comments

Comments
 (0)