Commit 028e1f7a authored by pythongosssss's avatar pythongosssss
Browse files

Fix scaled position when filtering

Add esc to close
parent 1a322ca6
...@@ -43,6 +43,17 @@ app.registerExtension({ ...@@ -43,6 +43,17 @@ app.registerExtension({
} }
} }
const positionList = () => {
const rect = this.root.getBoundingClientRect();
// If the top is off screen then shift the element with scaling applied
if (rect.top < 0) {
const scale = 1 - this.root.getBoundingClientRect().height / this.root.clientHeight;
const shift = (this.root.clientHeight * scale) / 2;
this.root.style.top = -shift + "px";
}
}
updateSelected(); updateSelected();
// Arrow up/down to select items // Arrow up/down to select items
...@@ -65,6 +76,8 @@ app.registerExtension({ ...@@ -65,6 +76,8 @@ app.registerExtension({
e.preventDefault(); e.preventDefault();
} else if ((selectedItem && e.key === "Enter") || e.keyCode === 13 || e.keyCode === 10) { } else if ((selectedItem && e.key === "Enter") || e.keyCode === 13 || e.keyCode === 10) {
selectedItem.click(); selectedItem.click();
} else if(e.key === "Escape") {
this.close();
} }
}); });
...@@ -104,6 +117,7 @@ app.registerExtension({ ...@@ -104,6 +117,7 @@ app.registerExtension({
} }
this.root.style.top = top + "px"; this.root.style.top = top + "px";
positionList();
} }
}); });
...@@ -111,14 +125,7 @@ app.registerExtension({ ...@@ -111,14 +125,7 @@ app.registerExtension({
// Focus the filter box when opening // Focus the filter box when opening
filter.focus(); filter.focus();
const rect = this.root.getBoundingClientRect(); positionList();
// If the top is off screen then shift the element with scaling applied
if (rect.top < 0) {
const scale = 1 - this.root.getBoundingClientRect().height / this.root.clientHeight;
const shift = (this.root.clientHeight * scale) / 2;
this.root.style.top = -shift + "px";
}
}); });
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment