Skip to content

Commit b3bba62

Browse files
committed
Fixed preview showing last focused instead of user hovered while holding Ctrl; serialize lastAccessed along with everything else; and more changes...
- Removed old `animation-name` for the CSS for `-tui-list-manual-filter-indicator` - More colors for future theming use - Some more utility functions in `polyfill.js` -- `t_tryParseJSONObject`: try to parse a JSON object, rejecting primitives and invalid JSON -- `t_sanitizeXMLTags`: replace XML brackets with `<` and `>` -- `t_errorToString`: quickly turns a JS error to a pretty string with the error message and the stack trace - Fix issue where holding `Ctrl` while hovering over tabs for a preview will quickly alternate between the correct preview and the last multiselected tab's preview. This was caused by `keydown` events being passed to items even though the event might not have been on an item being hovered over, as indicated by the `-tui-list-hover` class - `verboseValue` getter on `WindowName` for getting a display value containing everything - Serialize `lastAccessed` as well on tabs
1 parent aa5c565 commit b3bba62

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

dist/popup/popup.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ html, body {
597597
.-tui-list-manual-filter-indicator {
598598
position: absolute;
599599
border-radius: 4px;
600-
animation-name: pop;
601600
animation-duration: .5s;
602601
pointer-events: none;
603602
}

dist/stylesheets/theming.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
--selected-2: rgb(37, 81, 224);
2727
--highlight-1: #ff9500;
2828
--highlight-1-translucent: #ff835426;
29+
--highlight-2: #fde50b;
30+
--highlight-2-translucent: #fdee4926;
31+
--subtitle: cyan;
2932

3033
--input-focus90: #e791ec; /*currently unused*/
3134
--input-focus90t: #ea4af260; /*currently unused*/
@@ -70,6 +73,9 @@
7073
--selected-2: #dce9ff;
7174
--highlight-1: #ff9500;
7275
--highlight-1-translucent: #ff835426;
76+
--highlight-2: #fde50b;
77+
--highlight-2-translucent: #fdee4926;
78+
--subtitle: darkblue;
7379

7480
--input-focus90: #e791ec; /*currently unused*/
7581
--input-focus90t: #ea4af260; /*currently unused*/

src/polyfill.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,38 @@ globalScope["t_resetAnimation"] = function (el) {
312312
el.style.animation = null;
313313
};
314314

315+
// https://stackoverflow.com/questions/3710204/how-to-check-if-a-string-is-a-valid-json-string
316+
/**
317+
* If you don't care about primitives and only objects then this function
318+
* is for you, otherwise look elsewhere.
319+
* This function will return `false` for any valid json primitive.
320+
* EG, 'true' -> false
321+
* '123' -> false
322+
* 'null' -> false
323+
* '"I'm a string"' -> false
324+
*/
325+
globalScope["t_tryParseJSONObject"] = function (jsonString) {
326+
try {
327+
var o = JSON.parse(jsonString);
328+
329+
// Handle non-exception-throwing cases:
330+
// Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
331+
// but... JSON.parse(null) returns null, and typeof null === "object",
332+
// so we must check for that, too. Thankfully, null is falsey, so this suffices:
333+
if (o && typeof o === "object") {
334+
return o;
335+
}
336+
}
337+
catch (e) { }
338+
339+
return false;
340+
};
341+
342+
globalScope["t_sanitizeXMLTags"] = function (text) {
343+
return text.replace(/<\/?([a-zA-Z0-9]+)>/g, match => {
344+
return match.replace('<', '&lt;').replace('>', '&gt;');
345+
});
346+
};
347+
348+
globalScope["t_errorToString"] = error => `${error.toString()}\n${error.stack || 'No stack trace available.'}`;
349+

src/popup/popup.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,13 @@ class TUIList {
702702
});
703703
// The key down event is also artificially activated by ArrowDown and ArrowUp listeners
704704
e.addEventListener("keydown", (evt) => {
705-
onSelection(e, evt);
706-
this.dataInterpret.handleClick(e, this.root.getElementsByClassName("-tui-list-selected"), evt);
705+
// Make sure that the key down event's target matches the current hover, which should be the keydown focus theoretically.
706+
// Otherwise, it is likely that the item was focused but not hovered over, and -tui-list-hover takes precedence over browser hover.
707+
let lastHover = this.root.querySelector(".-tui-list-hover");
708+
if (evt.target.isSameNode(lastHover)) {
709+
onSelection(e, evt);
710+
this.dataInterpret.handleClick(e, this.root.getElementsByClassName("-tui-list-selected"), evt);
711+
}
707712
});
708713
let setHoverToNearest = (reason) => {
709714
// Set hover to another element
@@ -1382,6 +1387,13 @@ class WindowName extends TUIEditableLabel {
13821387
return `${this.__currentValue} (${this.windowOrder})`;
13831388
}
13841389
}
1390+
get verboseValue() {
1391+
if (this.__currentValue.trim() === "") {
1392+
return this.__initialWindowName;
1393+
} else {
1394+
return `${this.__currentValue} (Window ${this.windowOrder})`;
1395+
}
1396+
}
13851397
get value() {
13861398
return this.__currentValue;
13871399
}
@@ -1509,10 +1521,12 @@ class TUITabsList extends TUIListDataInterpret {
15091521

15101522
tmp = document.createElement("div");
15111523
tmp.className = "title-wrapper";
1524+
15121525
let tmp2 = document.createElement("span");
15131526
tmp2.className = "title";
15141527
tmp2.innerText = data.title;
15151528
tmp.appendChild(tmp2);
1529+
15161530
entry.appendChild(tmp);
15171531

15181532
if (data.discarded) entry.setAttribute("data-discarded", "");

src/tapi/ttab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const TTAB_TRACK_UNCHANGING = ["cookieStoreId", "incognito", "openerTabId
1010
export const TTAB_TRACK = TTAB_TRACK_ONUPDATED.concat(TTAB_TRACK_ONUPDATED_MANUAL, TTAB_TRACK_ONACTIVATED, TTAB_TRACK_ONMOVED, TTAB_TRACK_ONATTACHED, TTAB_TRACK_UNCHANGING);
1111

1212
export const TTAB_SERIALIZE = ["favIconUrl", "isArticle", "mutedInfo", "pinned", "title", "url", "hidden", "discarded",
13-
"isInReaderMode",
13+
"isInReaderMode", "lastAccessed",
1414
"active",
1515
"windowId",
1616
"cookieStoreId", "incognito", "openerTabId"];
@@ -150,7 +150,7 @@ export class TTab {
150150
static toTab(ttab, windowId, cookieStoreId) {
151151
// ============= FOR REFERENCE =============
152152
// export const TTAB_SERIALIZE = ["favIconUrl", "isArticle", "mutedInfo", "pinned", "title", "url", "hidden", "discarded",
153-
// "isInReaderMode",
153+
// "isInReaderMode", "lastAccessed",
154154
// "active",
155155
// "windowId",
156156
// "cookieStoreId", "incognito", "openerTabId"]; "hidden" is currently not recovered, "openerTabId" must be done separately later

0 commit comments

Comments
 (0)