Skip to content

Commit

Permalink
fix mutual influence of different status in status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
brookhong committed Dec 28, 2023
1 parent 5d7efa5 commit ed062a4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/content_scripts/common/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Mode.showStatus = function() {
sl += " - frame: " + pathname[pathname.length - 1];
}
}
dispatchSKEvent('showStatus', [0, sl]);
dispatchSKEvent('showStatus', [[sl]]);
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/content_scripts/common/visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function createVisual(clipboard, hints) {
}
if (matches.length) {
currentOccurrence = matches.length - 1;
dispatchSKEvent('showStatus', [2, currentOccurrence + 1 + ' / ' + matches.length]);
dispatchSKEvent('showStatus', [[undefined, undefined, currentOccurrence + 1 + ' / ' + matches.length]]);
}
}
});
Expand All @@ -203,7 +203,7 @@ function createVisual(clipboard, hints) {
document.scrollingElement.scrollTop = 0;
currentOccurrence = 0;
if (matches.length) {
dispatchSKEvent('showStatus', [2, currentOccurrence + 1 + ' / ' + matches.length]);
dispatchSKEvent('showStatus', [[undefined, undefined, currentOccurrence + 1 + ' / ' + matches.length]]);
}

if (getBrowserName() !== "Firefox") {
Expand Down Expand Up @@ -586,7 +586,7 @@ function createVisual(clipboard, hints) {
break;
}
}
dispatchSKEvent('showStatus', [2, currentOccurrence + 1 + ' / ' + matches.length]);
dispatchSKEvent('showStatus', [[undefined, undefined, currentOccurrence + 1 + ' / ' + matches.length]]);
}
}

Expand All @@ -600,7 +600,7 @@ function createVisual(clipboard, hints) {
registeredScrollNodes = [];
setSanitizedContent(markHolder_, "");
markHolder_.remove();
dispatchSKEvent('showStatus', [2, '']);
dispatchSKEvent('showStatus', [[undefined, undefined, ""]]);
};

self.emptySelection = function() {
Expand Down Expand Up @@ -693,7 +693,7 @@ function createVisual(clipboard, hints) {
}
currentOccurrence = (backward ? (matches.length + currentOccurrence - 1) : (currentOccurrence + 1)) % matches.length;
select(matches[currentOccurrence]);
dispatchSKEvent('showStatus', [2, currentOccurrence + 1 + ' / ' + matches.length]);
dispatchSKEvent('showStatus', [[undefined, undefined, currentOccurrence + 1 + ' / ' + matches.length]]);
} else if (runtime.conf.lastQuery) {
highlight(new RegExp(runtime.conf.lastQuery, "g" + (runtime.getCaseSensitive(runtime.conf.lastQuery) ? "" : "i")));
self.visualEnter(runtime.conf.lastQuery);
Expand Down Expand Up @@ -771,7 +771,7 @@ function createVisual(clipboard, hints) {
self.enter();
select(matches[currentOccurrence]);
} else {
dispatchSKEvent('showStatus', [2, "Pattern not found: {0}".format(query), 1000]);
dispatchSKEvent('showStatus', [[undefined, undefined, "Pattern not found: {0}".format(query)], 1000]);
}
Mode.getScrollableElements().forEach(function(n) {
if (n !== document.scrollingElement) {
Expand Down
2 changes: 1 addition & 1 deletion src/content_scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function applySettings(api, normal, rs) {
if (["byhost", "always"].indexOf(rs.proxyMode) !== -1) {
proxyMode = "{0}: {1}".format(rs.proxyMode, rs.proxy);
}
dispatchSKEvent('showStatus', [3, proxyMode]);
dispatchSKEvent('showStatus', [[undefined, undefined, undefined, proxyMode]]);
}

RUNTIME('getState', {
Expand Down
7 changes: 3 additions & 4 deletions src/content_scripts/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,11 @@ function createFront(insert, normal, hints, visual, browser) {
self.showStatus(...evt.detail);
});

self.showStatus = function (pos, msg, duration) {
self.showStatus = function (msgs, duration) {
self.command({
action: "showStatus",
content: msg,
duration: duration,
position: pos
contents: msgs,
duration: duration
});
};
self.toggleStatus = function (visible) {
Expand Down
21 changes: 10 additions & 11 deletions src/content_scripts/ui/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ const Front = (function() {
};

_actions['showStatus'] = function(message) {
StatusBar.show(message.position, message.content, message.duration);
StatusBar.show(message.contents, message.duration);
};

document.addEventListener("surfingkeys:showStatus", function(evt) {
Expand Down Expand Up @@ -704,22 +704,21 @@ var StatusBar = (function() {
var timerHide = null;
var ui = Front.statusBar;

// 4 spans
// mode: 0
// search: 1
// searchResult: 2
// proxy: 3
self.show = function(n, content, duration) {
self.show = function(contents, duration) {
if (timerHide) {
clearTimeout(timerHide);
timerHide = null;
}
var span = ui.querySelectorAll('span');
if (n < 0) {
span.forEach(function(s) {
setSanitizedContent(s, "");
});
} else {
setSanitizedContent(span[n], content);
for (var i = 0; i < contents.length; i++) {
if (contents[i] !== undefined) {
setSanitizedContent(span[i], contents[i]);
}
}
var lastSpan = -1;
for (var i = 0; i < span.length; i++) {
Expand All @@ -741,7 +740,7 @@ var StatusBar = (function() {
Front.flush();
if (duration) {
timerHide = setTimeout(function() {
self.show(n, "");
self.show(["", "", "", ""]);
}, duration);
}
};
Expand All @@ -766,7 +765,7 @@ var Find = (function() {
var historyInc;
function reset() {
input = null;
StatusBar.show(1, "");
StatusBar.show(["", ""]);
self.exit();
}

Expand All @@ -780,7 +779,7 @@ var Find = (function() {
*/
self.open = function() {
historyInc = -1;
StatusBar.show(1, '<input id="sk_find" class="sk_theme"/>');
StatusBar.show(["/", '<input id="sk_find" class="sk_theme"/>']);
input = Front.statusBar.querySelector("input");
if (!getBrowserName().startsWith("Safari")) {
input.oninput = function() {
Expand Down

0 comments on commit ed062a4

Please sign in to comment.