1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-05 11:15:46 +01:00

Refactor the gu mapping action.

This commit is contained in:
Doug Kearns
2010-10-16 22:30:37 +11:00
parent e38b856829
commit e879395cb2

View File

@@ -110,32 +110,19 @@ const Browser = Module("browser", {
mappings.add([modes.NORMAL], ["gu"],
"Go to parent directory",
function (count) {
function isDirectory(url) {
if (/^file:\/|^\//.test(url)) {
let file = io.File(url);
return file.exists() && file.isDirectory();
}
else {
// for all other locations just check if the URL ends with /
return /\/$/.test(url);
}
}
count = Math.max(count, 1);
let url = util.newURI(buffer.URL);
let path = url.path;
let url = buffer.URL;
for (let i = 0; i < count; i++) {
if (isDirectory(url))
url = url.replace(/^(.*?:)(.*?)([^\/]+\/*)$/, "$1$2/");
else
url = url.replace(/^(.*?:)(.*?)(\/+[^\/]+)$/, "$1$2/");
}
url = url.replace(/^(.*:\/+.*?)\/+$/, "$1/"); // get rid of more than 1 / at the end
while (count-- && path != "/")
path = path.replace(/[^\/]+\/?$/, "")
if (url == buffer.URL)
dactyl.beep();
let newUrl = url.prePath + path
if (newUrl != buffer.URL)
dactyl.open(newUrl);
else
dactyl.open(url);
dactyl.beep();
},
{ count: true });