1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-10 20:35: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"], mappings.add([modes.NORMAL], ["gu"],
"Go to parent directory", "Go to parent directory",
function (count) { 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); count = Math.max(count, 1);
let url = util.newURI(buffer.URL);
let path = url.path;
let url = buffer.URL; while (count-- && path != "/")
for (let i = 0; i < count; i++) { path = path.replace(/[^\/]+\/?$/, "")
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
if (url == buffer.URL) let newUrl = url.prePath + path
dactyl.beep();
if (newUrl != buffer.URL)
dactyl.open(newUrl);
else else
dactyl.open(url); dactyl.beep();
}, },
{ count: true }); { count: true });