Skip to content

Commit 4a0b64e

Browse files
committed
Add popAnchor option to goUp
1 parent 66f86b8 commit 4a0b64e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

background_scripts/all_commands.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ const allCommands = [
130130
desc: "Go up the URL hierarchy",
131131
group: "navigation",
132132
advanced: true,
133+
options: {
134+
popAnchor: "Remove the anchor/fragment/hash from the URL, if present.",
135+
},
133136
},
134137

135138
{

content_scripts/mode_normal.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,22 @@ const NormalModeCommands = {
134134
},
135135

136136
// Url manipulation.
137-
goUp(count) {
137+
goUp(count, { registryEntry }) {
138+
let c = count;
138139
const url = new URL(globalThis.location.href);
139140

141+
// Pop anchor.
142+
if (c > 0 && registryEntry.options.popAnchor && url.hash !== "") {
143+
url.hash = "";
144+
--c;
145+
}
146+
140147
// Pop path segments.
141-
if (url.pathname != "/") {
142-
url.pathname = url.pathname.split("/").slice(0, -count).join("/");
148+
if (c > 0 && url.pathname != "/") {
149+
url.pathname = url.pathname.split("/").slice(0, -c).join("/");
143150
url.search = "";
144151
url.hash = "";
152+
--c;
145153
}
146154

147155
if (globalThis.location.href !== url.toString()) {

0 commit comments

Comments
 (0)