Skip to content

Commit 7275d35

Browse files
committed
Reworked Scroll into view (options page) and reformatted css
1 parent b429efd commit 7275d35

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

content_scripts/link_hints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class LinkHintsMode {
428428
if (hasPopoverSupport) {
429429
this.containerEl.popover = "manual";
430430
this.containerEl.showPopover();
431-
this.containerEl.classList.add("vimiumPopover");
431+
this.containerEl.classList.add("vimium-popover");
432432
}
433433

434434
this.setIndicator();

content_scripts/vimium.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ iframe.vimium-hud-frame {
196196
opacity: 0;
197197
}
198198

199-
.vimiumPopover {
200-
top: 0 !important;
201-
left: 0 !important;
202-
position: absolute !important;
203-
display: block !important;
204-
width: 100% !important;
205-
height: 100% !important;
206-
overflow: visible !important;
199+
div.vimium-popover {
200+
top: 0;
201+
left: 0;
202+
position: absolute;
203+
display: block;
204+
width: 100%;
205+
height: 100%;
206+
overflow: visible;
207207
}
208208

209209
body.vimium-find-mode ::selection {

pages/options.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,34 @@ const OptionsPage = {
243243
return result;
244244
},
245245

246+
isElementInView(element) {
247+
const rect = element.getBoundingClientRect();
248+
return (
249+
rect.top >= 0 &&
250+
rect.left >= 0 &&
251+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
252+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
253+
);
254+
},
255+
246256
async saveOptions() {
257+
// If no fields with validation errors are in view, scroll one of them into view
258+
// so it's clear what the issue is.
259+
247260
const hasErrors = this.showValidationErrors();
248261
if (hasErrors) {
249-
const error = document.querySelector(".validation-error");
262+
const errors = Array.from(document.querySelectorAll(".validation-error"));
250263

251-
error?.scrollIntoView();
264+
let isAnyElementInView = errors.some((element) => this.isElementInView(element) == true);
265+
266+
if (isAnyElementInView) {
267+
return;
268+
}
269+
270+
errors[0]?.scrollIntoView({
271+
behavior: "smooth",
272+
block: "start",
273+
});
252274

253275
return;
254276
}

0 commit comments

Comments
 (0)