mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-22 22:05:03 +08:00
Clear URL hash when the user clicks outside the element (#1089)
This commit is contained in:
parent
1cdc9f7f70
commit
17a0893809
1 changed files with 20 additions and 4 deletions
|
@ -471,6 +471,22 @@ const Session = {
|
||||||
if (event.target.closest(`[data-el-enable-insert-mode-button]`)) {
|
if (event.target.closest(`[data-el-enable-insert-mode-button]`)) {
|
||||||
this.setInsertMode(true);
|
this.setInsertMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hash = window.location.hash;
|
||||||
|
|
||||||
|
if (hash) {
|
||||||
|
const htmlId = hash.replace(/^#/, "");
|
||||||
|
const hashEl = document.getElementById(htmlId);
|
||||||
|
|
||||||
|
// Remove hash from the URL when the user clicks somewhere else on the page
|
||||||
|
if (!hashEl.contains(event.target) && !event.target.closest(`a`)) {
|
||||||
|
history.pushState(
|
||||||
|
null,
|
||||||
|
document.title,
|
||||||
|
window.location.pathname + window.location.search
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -575,17 +591,17 @@ const Session = {
|
||||||
|
|
||||||
if (hash) {
|
if (hash) {
|
||||||
const htmlId = hash.replace(/^#/, "");
|
const htmlId = hash.replace(/^#/, "");
|
||||||
const element = document.getElementById(htmlId);
|
const hashEl = document.getElementById(htmlId);
|
||||||
|
|
||||||
if (element) {
|
if (hashEl) {
|
||||||
const focusableEl = element.closest("[data-focusable-id]");
|
const focusableEl = hashEl.closest("[data-focusable-id]");
|
||||||
|
|
||||||
if (focusableEl) {
|
if (focusableEl) {
|
||||||
this.setFocusedEl(focusableEl.dataset.focusableId);
|
this.setFocusedEl(focusableEl.dataset.focusableId);
|
||||||
} else {
|
} else {
|
||||||
// Explicitly scroll to the target element
|
// Explicitly scroll to the target element
|
||||||
// after the loading finishes
|
// after the loading finishes
|
||||||
element.scrollIntoView();
|
hashEl.scrollIntoView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.props.autofocusCellId) {
|
} else if (this.props.autofocusCellId) {
|
||||||
|
|
Loading…
Reference in a new issue