Commits

Anonymous committed e43cdab

More work on 'ignore group position' sorting.

  • Participants
  • Parent commits 9c3cb63

Comments (0)

Files changed (2)

chrome/content/gst.event.js

 		if (tabIdx === -1) return;
 		let tab = gBrowser.tabs[tabIdx];
 		
+		// onTitleChange seems to fire sometimes with document.title being "" when
+		// the tab label itself clearly has a value, and nothing particularly strange going on
+		// is this natural, or some kind of bug?
 		let title = document.title;
-		GST.sortedList.update(tab, GST.sort.TITLE, title);		// TITLE
+		if (title || !tab.gstTitle)
+			GST.sortedList.update(tab, GST.sort.TITLE, title);		// TITLE
 	},
 	
 	ssOpenedObserver : {

chrome/content/gst.list.js

 	}
 	
 	function addPosTab(tab) {
-		if (tab.gstPosGroup && tab.gstPosGroup.length === 2)
+		function getMatchingTab(tab) {
+			GST.assert(tab.gstSortGroup, "missing gstSortGroup; addTab() not called before addPosTab()?");
+			GST.assert(tab.gstSortGroup.length > 0, "zero-length sort group");
+			if (tab.gstSortGroup.length === 1) return null;
+			for (let i = 0; i < tab.gstSortGroup.length; i++) {
+				let similarTab = tab.gstSortGroup[i];
+				if (similarTab === tab) continue;
+				if (similarTab.gstPosGroup) return similarTab;
+			}
+			return null;
+		}
+		
+		let isSingleTab = (tab.gstPosGroup && tab.gstPosGroup.length === 2);
+		if (isSingleTab)
 			tab.gstPosGroup.gstIsUniform = false;
 		removeTab(tab, posList);
+		
+		let matchTab = getMatchingTab(tab);
+		let lastGroup, matchGroup;
+		if (posList.length > 0)
+			lastGroup = posList[posList.length - 1];
 
-		if (posList.length === 0) {
-			posList.push([tab]);
-			tab.gstPosGroup = posList[0];
+		if (!lastGroup || !matchTab && lastGroup.gstIsUniform) {
+			let group = [tab];
+			posList.push(group);
+			tab.gstPosGroup = group;
 			return;
 		}
 		
-		let lastGroup = posList[posList.length - 1];
-		let lastTab = lastGroup[lastGroup.length - 1];
-		let groupByProp = GST.groupBy.getProp(tab);
-		let isMatch = (lastTab[groupByProp] === tab[groupByProp]);
-		
-		let group = null;
-		if (lastGroup.gstIsUniform && !isMatch) {
-			group = [tab];
-			posList.push(group);
-		} else if (isMatch && !lastGroup.gstIsUniform) {
-			group = [lastGroup.pop(), tab];
-			if (lastGroup.length === 0) posList.pop();
-			doSortList(group, getSort());
-			posList.push(group);
-			group.gstIsUniform = true;
+		if (matchTab) matchGroup = matchTab.gstPosGroup;
+		if (matchTab && !matchGroup.gstIsUniform) {
+			let leftGroup, rightGroup;
+			let matchTabIdx = matchGroup.indexOf(matchTab);
+			let midGroup = matchGroup.splice(matchTabIdx, 1);
+			if (matchTabIdx < matchGroup.length)	// remember our length is now - 1
+				rightGroup = matchGroup.splice(matchTabIdx);
+			if (matchTabIdx > 0)
+				leftGroup = matchGroup;
+
+			midGroup.push(tab);
+			matchTab.gstPosGroup = midGroup;
+			tab.gstPosGroup = midGroup;
+			doSortList(midGroup, GST.sortBy.getSort());
+			midGroup.gstIsUniform = true;
+			
+			let matchGroupIdx = posList.indexOf(matchGroup);
+			posList.splice(matchGroupIdx, 1, midGroup);
+			if (rightGroup) posList.splice(matchGroupIdx + 1, 0, rightGroup);
+			if (leftGroup) posList.splice(matchGroupIdx, 0, leftGroup);
+			return;
 		}
 		
+		let group;
 		// add matching tabs to homogenous groups,
 		// and non-matching tabs to heterogenous groups
-		if (isMatch === lastGroup.gstIsUniform) {
+		if (matchTab && matchGroup.gstIsUniform)
+			group = matchGroup;
+		else if (!matchTab && !lastGroup.gstIsUniform)
 			group = lastGroup;
-			group.push(tab);
-			doSortList(group, getSort());
-		}
+		else return;
+
+		group.push(tab);
 		tab.gstPosGroup = group;
+		doSortList(group, GST.sortBy.getSort());
 	}
 	
 	function removeTab(tab, list) {
 		},
 		
 		fullSort : function() {
+			clearLists();
+			
 			let queue = [];
-			for (let i = 0; i < gBrowser.tabs.length; i++)
-				queue.push(gBrowser.tabs[i]);
-
-			clearLists();				
-			let list = getList();
-			for (let i = queue.length - 1; i >= 0; i--) {
-				let tab = queue[i];
+			for (let i = 0; i < gBrowser.tabs.length; i++) {
+				let tab = gBrowser.tabs[i];
 				tab.gstSortGroup = null;
 				tab.gstPosGroup = null;
 				addTab(tab)
+				queue.push(tab);
+			}
+
+			let list = getList();
+			for (let i = 0; i < queue.length; i++) {
+				let tab = queue[i];
 				addPosTab(tab);
 				positionTab(tab, list);
 			}