searchController: General cleanup
Fix style issues, such as indentation and == → ===. Simplify getTermsForSearchString() by removing one variable. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1667>
This commit is contained in:
parent
c8f1dca3c7
commit
1b51ae150d
@ -10,8 +10,8 @@ const ShellEntry = imports.ui.shellEntry;
|
|||||||
var FocusTrap = GObject.registerClass(
|
var FocusTrap = GObject.registerClass(
|
||||||
class FocusTrap extends St.Widget {
|
class FocusTrap extends St.Widget {
|
||||||
vfunc_navigate_focus(from, direction) {
|
vfunc_navigate_focus(from, direction) {
|
||||||
if (direction == St.DirectionType.TAB_FORWARD ||
|
if (direction === St.DirectionType.TAB_FORWARD ||
|
||||||
direction == St.DirectionType.TAB_BACKWARD)
|
direction === St.DirectionType.TAB_BACKWARD)
|
||||||
return super.vfunc_navigate_focus(from, direction);
|
return super.vfunc_navigate_focus(from, direction);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -19,11 +19,9 @@ class FocusTrap extends St.Widget {
|
|||||||
|
|
||||||
function getTermsForSearchString(searchString) {
|
function getTermsForSearchString(searchString) {
|
||||||
searchString = searchString.replace(/^\s+/g, '').replace(/\s+$/g, '');
|
searchString = searchString.replace(/^\s+/g, '').replace(/\s+$/g, '');
|
||||||
if (searchString == '')
|
if (searchString === '')
|
||||||
return [];
|
return [];
|
||||||
|
return searchString.split(/\s+/);
|
||||||
let terms = searchString.split(/\s+/);
|
|
||||||
return terms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var SearchController = GObject.registerClass({
|
var SearchController = GObject.registerClass({
|
||||||
@ -72,10 +70,14 @@ var SearchController = GObject.registerClass({
|
|||||||
this._entry.connect('notify::mapped', this._onMapped.bind(this));
|
this._entry.connect('notify::mapped', this._onMapped.bind(this));
|
||||||
global.stage.connect('notify::key-focus', this._onStageKeyFocusChanged.bind(this));
|
global.stage.connect('notify::key-focus', this._onStageKeyFocusChanged.bind(this));
|
||||||
|
|
||||||
this._entry.set_primary_icon(new St.Icon({ style_class: 'search-entry-icon',
|
this._entry.set_primary_icon(new St.Icon({
|
||||||
icon_name: 'edit-find-symbolic' }));
|
style_class: 'search-entry-icon',
|
||||||
this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
|
icon_name: 'edit-find-symbolic',
|
||||||
icon_name: 'edit-clear-symbolic' });
|
}));
|
||||||
|
this._clearIcon = new St.Icon({
|
||||||
|
style_class: 'search-entry-icon',
|
||||||
|
icon_name: 'edit-clear-symbolic',
|
||||||
|
});
|
||||||
|
|
||||||
this._iconClickedId = 0;
|
this._iconClickedId = 0;
|
||||||
this._capturedEventId = 0;
|
this._capturedEventId = 0;
|
||||||
@ -97,11 +99,11 @@ var SearchController = GObject.registerClass({
|
|||||||
|
|
||||||
this._stageKeyPressId = 0;
|
this._stageKeyPressId = 0;
|
||||||
Main.overview.connect('showing', () => {
|
Main.overview.connect('showing', () => {
|
||||||
this._stageKeyPressId = global.stage.connect('key-press-event',
|
this._stageKeyPressId =
|
||||||
this._onStageKeyPress.bind(this));
|
global.stage.connect('key-press-event', this._onStageKeyPress.bind(this));
|
||||||
});
|
});
|
||||||
Main.overview.connect('hiding', () => {
|
Main.overview.connect('hiding', () => {
|
||||||
if (this._stageKeyPressId != 0) {
|
if (this._stageKeyPressId !== 0) {
|
||||||
global.stage.disconnect(this._stageKeyPressId);
|
global.stage.disconnect(this._stageKeyPressId);
|
||||||
this._stageKeyPressId = 0;
|
this._stageKeyPressId = 0;
|
||||||
}
|
}
|
||||||
@ -170,7 +172,7 @@ var SearchController = GObject.registerClass({
|
|||||||
// text and one for the new one - the second one is handled
|
// text and one for the new one - the second one is handled
|
||||||
// incorrectly when we remove focus
|
// incorrectly when we remove focus
|
||||||
// (https://bugzilla.gnome.org/show_bug.cgi?id=636341) */
|
// (https://bugzilla.gnome.org/show_bug.cgi?id=636341) */
|
||||||
if (this._text.text != '')
|
if (this._text.text !== '')
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,8 +205,8 @@ var SearchController = GObject.registerClass({
|
|||||||
_onMapped() {
|
_onMapped() {
|
||||||
if (this._entry.mapped) {
|
if (this._entry.mapped) {
|
||||||
// Enable 'find-as-you-type'
|
// Enable 'find-as-you-type'
|
||||||
this._capturedEventId = global.stage.connect('captured-event',
|
this._capturedEventId =
|
||||||
this._onCapturedEvent.bind(this));
|
global.stage.connect('captured-event', this._onCapturedEvent.bind(this));
|
||||||
this._text.set_cursor_visible(true);
|
this._text.set_cursor_visible(true);
|
||||||
this._text.set_selection(0, 0);
|
this._text.set_selection(0, 0);
|
||||||
} else {
|
} else {
|
||||||
@ -223,7 +225,7 @@ var SearchController = GObject.registerClass({
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
let unicode = Clutter.keysym_to_unicode(symbol);
|
let unicode = Clutter.keysym_to_unicode(symbol);
|
||||||
if (unicode == 0)
|
if (unicode === 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (getTermsForSearchString(String.fromCharCode(unicode)).length > 0)
|
if (getTermsForSearchString(String.fromCharCode(unicode)).length > 0)
|
||||||
@ -242,7 +244,7 @@ var SearchController = GObject.registerClass({
|
|||||||
|
|
||||||
// the entry does not show the hint
|
// the entry does not show the hint
|
||||||
_isActivated() {
|
_isActivated() {
|
||||||
return this._text.text == this._entry.get_text();
|
return this._text.text === this._entry.get_text();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTextChanged() {
|
_onTextChanged() {
|
||||||
@ -256,9 +258,9 @@ var SearchController = GObject.registerClass({
|
|||||||
|
|
||||||
this._entry.set_secondary_icon(this._clearIcon);
|
this._entry.set_secondary_icon(this._clearIcon);
|
||||||
|
|
||||||
if (this._iconClickedId == 0) {
|
if (this._iconClickedId === 0) {
|
||||||
this._iconClickedId = this._entry.connect('secondary-icon-clicked',
|
this._iconClickedId =
|
||||||
this.reset.bind(this));
|
this._entry.connect('secondary-icon-clicked', this.reset.bind(this));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this._iconClickedId > 0) {
|
if (this._iconClickedId > 0) {
|
||||||
@ -280,7 +282,7 @@ var SearchController = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
} else if (this._searchActive) {
|
} else if (this._searchActive) {
|
||||||
let arrowNext, nextDirection;
|
let arrowNext, nextDirection;
|
||||||
if (entry.get_text_direction() == Clutter.TextDirection.RTL) {
|
if (entry.get_text_direction() === Clutter.TextDirection.RTL) {
|
||||||
arrowNext = Clutter.KEY_Left;
|
arrowNext = Clutter.KEY_Left;
|
||||||
nextDirection = St.DirectionType.LEFT;
|
nextDirection = St.DirectionType.LEFT;
|
||||||
} else {
|
} else {
|
||||||
@ -299,7 +301,7 @@ var SearchController = GObject.registerClass({
|
|||||||
} else if (symbol === Clutter.KEY_Down) {
|
} else if (symbol === Clutter.KEY_Down) {
|
||||||
this._searchResults.navigateFocus(St.DirectionType.DOWN);
|
this._searchResults.navigateFocus(St.DirectionType.DOWN);
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
} else if (symbol == arrowNext && this._text.position == -1) {
|
} else if (symbol === arrowNext && this._text.position === -1) {
|
||||||
this._searchResults.navigateFocus(nextDirection);
|
this._searchResults.navigateFocus(nextDirection);
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
} else if (symbol === Clutter.KEY_Return || symbol === Clutter.KEY_KP_Enter) {
|
} else if (symbol === Clutter.KEY_Return || symbol === Clutter.KEY_KP_Enter) {
|
||||||
@ -311,11 +313,11 @@ var SearchController = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onCapturedEvent(actor, event) {
|
_onCapturedEvent(actor, event) {
|
||||||
if (event.type() == Clutter.EventType.BUTTON_PRESS) {
|
if (event.type() === Clutter.EventType.BUTTON_PRESS) {
|
||||||
let source = event.get_source();
|
let source = event.get_source();
|
||||||
if (source != this._text &&
|
if (source !== this._text &&
|
||||||
this._text.has_key_focus() &&
|
this._text.has_key_focus() &&
|
||||||
this._text.text == '' &&
|
this._text.text === '' &&
|
||||||
!this._text.has_preedit() &&
|
!this._text.has_preedit() &&
|
||||||
!Main.layoutManager.keyboardBox.contains(source)) {
|
!Main.layoutManager.keyboardBox.contains(source)) {
|
||||||
// the user clicked outside after activating the entry, but
|
// the user clicked outside after activating the entry, but
|
||||||
|
Loading…
Reference in New Issue
Block a user