[gnome-shell-extensions/wip/fmuellner/window-list-scrolling: 2/3] window-list: Minor clean-up
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/fmuellner/window-list-scrolling: 2/3] window-list: Minor clean-up
- Date: Sat, 6 Oct 2018 16:05:59 +0000 (UTC)
commit d424b0f645366b75a945f1bbc6678e7dd735df39
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Oct 6 17:43:23 2018 +0200
window-list: Minor clean-up
Modern javascript has explicit methods for locating the first
element of an array that meets a certain condition, use those
instead of manually looping over the array.
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/78
extensions/window-list/extension.js | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
---
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
index 8257eac..dd165af 100644
--- a/extensions/window-list/extension.js
+++ b/extensions/window-list/extension.js
@@ -899,16 +899,9 @@ class WindowList {
return;
let children = this._windowList.get_children().map(a => a._delegate);
- let active = 0;
- for (let i = 0; i < children.length; i++) {
- if (children[i].active) {
- active = i;
- break;
- }
- }
-
- active = Math.max(0, Math.min(active + diff, children.length-1));
- children[active].activate();
+ let active = children.findIndex(c => c.active);
+ let newActive = Math.max(0, Math.min(active + diff, children.length-1));
+ children[newActive].activate();
}
_updatePosition() {
@@ -1023,12 +1016,9 @@ class WindowList {
_removeApp(app) {
let children = this._windowList.get_children();
- for (let i = 0; i < children.length; i++) {
- if (children[i]._delegate.app == app) {
- children[i].destroy();
- return;
- }
- }
+ let child = children.find(c => c._delegate.app == app);
+ if (child)
+ child.destroy();
}
_onWindowAdded(ws, win) {
@@ -1042,10 +1032,8 @@ class WindowList {
return;
let children = this._windowList.get_children();
- for (let i = 0; i < children.length; i++) {
- if (children[i]._delegate.metaWindow == win)
- return;
- }
+ if (children.find(c => c._delegate.metaWindow == win))
+ return;
let button = new WindowButton(win, this._perMonitor, this._monitor.index);
this._windowList.layout_manager.pack(button.actor,
@@ -1065,12 +1053,9 @@ class WindowList {
return; // not actually removed, just moved to another workspace
let children = this._windowList.get_children();
- for (let i = 0; i < children.length; i++) {
- if (children[i]._delegate.metaWindow == win) {
- children[i].destroy();
- return;
- }
- }
+ let child = children.find(c => c._delegate.metaWindow == win);
+ if (child)
+ child.destroy();
}
_onWorkspacesChanged() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]