Skip to content

Commit

Permalink
fix(interactive_credentials_provider): fix login triggered by datasou…
Browse files Browse the repository at this point in the history
…rce completions

Fixes #723.
  • Loading branch information
jbms committed Feb 11, 2025
1 parent b1fd298 commit 9a20ef0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
9 changes: 9 additions & 0 deletions src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ export const DEFAULT_STATUS_DELAY = 200;

export type Delay = boolean | number;

function setupStatusContainer(container: HTMLElement) {
container.addEventListener("mousedown", (event) => {
// Prevent focus changes due to clicking on status message.
event.preventDefault();
});
}

function getStatusContainer() {
if (statusContainer === undefined) {
statusContainer = document.createElement("ul");
setupStatusContainer(statusContainer);
statusContainer.id = "neuroglancer-status-container";
const el: HTMLElement | null = document.getElementById(
"neuroglancer-container",
Expand All @@ -47,6 +55,7 @@ function getStatusContainer() {
function getModalStatusContainer() {
if (modalStatusContainer === undefined) {
modalStatusContainer = document.createElement("ul");
setupStatusContainer(modalStatusContainer);
modalStatusContainer.id = "neuroglancer-status-container-modal";
const el: HTMLElement | null = document.getElementById(
"neuroglancer-container",
Expand Down
39 changes: 25 additions & 14 deletions src/widget/multiline_autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,32 @@ export class AutocompleteTextInput extends RefCounted {
this.debouncedUpdateHintState();
}
});
this.registerEventListener(this.inputElement, "blur", () => {
if (this.hasFocus) {
if (DEBUG_DROPDOWN) return;
this.hasFocus = false;
this.updateDropdown();
}
this.debouncedUpdateHintState();
const s = window.getSelection();
if (s !== null) {
if (s.containsNode(this.inputElement, true)) {
s.removeAllRanges();

// Debounce blur handling to avoid spuriously closing the completions.
const debouncedBlur = this.registerCancellable(
debounce(() => {
if (document.activeElement === this.inputElement) {
// Ignore spurious blur events, or blur events from the browser
// tab/window itself losing focus.
return;
}
}
this.onCommit.dispatch(this.value, false);
});
if (this.hasFocus) {
if (DEBUG_DROPDOWN) return;
this.hasFocus = false;
this.updateDropdown();
}
this.debouncedUpdateHintState();
const s = window.getSelection();
if (s !== null) {
if (s.containsNode(this.inputElement, true)) {
s.removeAllRanges();
}
}
this.onCommit.dispatch(this.value, false);
}),
);

this.registerEventListener(this.inputElement, "blur", debouncedBlur);
this.registerEventListener(window, "resize", () => {
this.dropdownStyleStale = true;
});
Expand Down

0 comments on commit 9a20ef0

Please sign in to comment.