Theia: [scm] the order of icon in scm is different in Chrom and Firefox

Created on 2 Jul 2019  路  8Comments  路  Source: eclipse-theia/theia

Description

the order of command icon in scm is different in Chrom and Firefox
git action icon diff in firefox chrome

Reproduction Steps

  • open instance in chrome and firefox
  • open scm

OS and Theia version:

  • OS: ubuntu18
  • chrome: 75.0.3770.100
  • firefox: 60.7.2esr
  • theia :latest
    Diagnostics:
bug shell

Most helpful comment

Also, I have managed to "break it" on Chrome:
Screen Shot 2019-07-02 at 15 11 25

All 8 comments

@kpge Will you have chance to investigate the cause? PRs are welcomed if they don't involve big structural changes.

It doesn't look like a problem for the scm widget but generally to all toolbar items.
It looks like chrome and firefox differ from the priority and will be reverses of each other.

For example, in the search-in-workspace widget:

Firefox
image

Chrome
image

I think the problem is here :
image

the sort funtion in Chrome and Firefox has diffenrent behavior

  • Chrome:
    image
  • Firefox:
    image

Isn鈥檛 the comparator function the strange? Assuming I have left and right with the following items:

"{"id":"search-in-workspace.refresh","command":"search-in-workspace.refresh","tooltip":"Refresh","priority":0}"
"{"id":"search-in-workspace.clear-all","command":"search-in-workspace.clear-all","tooltip":"Clear Search Results","priority":1}"



md5-30b14c34c2f09f06208bbac20128726e



        if (left.group === undefined || left.group === 'navigation') {
            return 1;
        }

Meaning that left is greater than right, hence it should come after right, but the priority is the other way and ignored.

Also, I have managed to "break it" on Chrome:
Screen Shot 2019-07-02 at 15 11 25

Could someone look at the comparator? It seems to be relatively easy fix. The logic should be following:

  • items should be compare by groups first
  • navigator group is special and always have the higher priority
  • undefined group is navigator group as well
  • if items have the same group then priority should be used for comparison within the group

It seems that the last point is not true for items within the navigator group.

diff --git a/packages/core/src/browser/shell/tab-bar-toolbar.tsx b/packages/core/src/browser/shell/tab-bar-toolbar.tsx
index 8978286cc..a6caeaccd 100644
--- a/packages/core/src/browser/shell/tab-bar-toolbar.tsx
+++ b/packages/core/src/browser/shell/tab-bar-toolbar.tsx
@@ -292,26 +292,18 @@ export namespace TabBarToolbarItem {
      */
     export const PRIORITY_COMPARATOR = (left: TabBarToolbarItem, right: TabBarToolbarItem) => {
         // The navigation group is special as it will always be sorted to the top/beginning of a menu.
-        if (left.group === undefined || left.group === 'navigation') {
-            return 1;
-        }
-        if (right.group === undefined || right.group === 'navigation') {
-            return -1;
-        }
-        if (left.group && right.group) {
-            if (left.group < right.group) {
-                return -1;
-            } else if (left.group > right.group) {
-                return 1;
-            } else {
-                return 0;
+        const compareGroup = (leftGroup: string | undefined = 'navigation', rightGroup: string | undefined = 'navigation') => {
+            if (leftGroup === 'navigation') {
+                return rightGroup === 'navigation' ? 0 : -1;
             }
-        }
-        if (left.group) {
-            return -1;
-        }
-        if (right.group) {
-            return 1;
+            if (rightGroup === 'navigation') {
+                return leftGroup === 'navigation' ? 0 : 1;
+            }
+            return leftGroup.localeCompare(rightGroup);
+        };
+        const result = compareGroup(left.group, right.group);
+        if (result !== 0) {
+            return result;
         }
         return (left.priority || 0) - (right.priority || 0);
     };

?

I will take care of it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jankeromnes picture jankeromnes  路  3Comments

akosyakov picture akosyakov  路  3Comments

kittaakos picture kittaakos  路  3Comments

Beetix picture Beetix  路  3Comments

vinokurig picture vinokurig  路  3Comments