Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/background/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@ export default class BackgroundProgram {
oneTimeWindowMessageToken: this.oneTimeWindowMessageToken,
mac: this.options.mac,
isPinned: tabState.isPinned,
blurFocusedElementOnActivation: this.options.values.blurFocusedElementOnActivation,
};

const getKeyboardShortcuts = (
Expand Down
35 changes: 35 additions & 0 deletions src/options/Program.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,41 @@ export default class OptionsProgram extends Component<Props, State> {
)}
/>

<Field
key="blurFocusedElementOnActivation"
id="blurFocusedElementOnActivation"
label="Blur focused element when activating hints"
description={
<p>
When enabled, any currently focused element (like input fields or
text areas) will be blurred when hints are activated. This can
prevent the focused element from capturing keyboard input that
should go to the link hints system.
</p>
}
changed={options.blurFocusedElementOnActivation !== defaults.blurFocusedElementOnActivation}
render={({ id }) => (
<span
className="ShrinkwrapChildren"
style={{ flex: "1 1 100%" }}
>
<label className="Spaced Spaced--center">
<input
type="checkbox"
id={id}
checked={options.blurFocusedElementOnActivation}
onChange={(event) => {
this.saveOptions({
blurFocusedElementOnActivation: event.currentTarget.checked,
});
}}
/>
<span>Enabled</span>
</label>
</span>
)}
/>

<Field
key="useKeyTranslations"
id="useKeyTranslations"
Expand Down
1 change: 1 addition & 0 deletions src/shared/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export type ToWorker =
oneTimeWindowMessageToken: string;
mac: boolean;
isPinned: boolean;
blurFocusedElementOnActivation: boolean;
}
| {
type: "UpdateElements";
Expand Down
2 changes: 2 additions & 0 deletions src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const Options = fieldsAuto({
keyTranslations: record(KeyPair),
normalKeyboardShortcuts: array(KeyboardMappingWithModifiers),
hintsKeyboardShortcuts: array(KeyboardMapping),
blurFocusedElementOnActivation: boolean,
});

const MIN_CHARS = 2;
Expand Down Expand Up @@ -126,6 +127,7 @@ export function getDefaults({ mac }: { mac: boolean }): Options {
logLevel: DEFAULT_LOG_LEVEL,
useKeyTranslations: false,
keyTranslations: EN_US_QWERTY_TRANSLATIONS,
blurFocusedElementOnActivation: false,
normalKeyboardShortcuts: [
{
shortcut: mainShortcut("j"),
Expand Down
15 changes: 15 additions & 0 deletions src/worker/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default class WorkerProgram {

mac = false;

blurFocusedElementOnActivation = false;

suppressNextKeyup: { key: string; code: string } | undefined = undefined;

resets = new Resets();
Expand Down Expand Up @@ -203,13 +205,26 @@ export default class WorkerProgram {
this.keyTranslations = message.keyTranslations;
this.oneTimeWindowMessageToken = message.oneTimeWindowMessageToken;
this.mac = message.mac;
this.blurFocusedElementOnActivation = message.blurFocusedElementOnActivation;

if (message.clearElements) {
this.clearCurrent();
}
break;

case "StartFindElements": {
// Blur focused element if option is enabled
if (this.blurFocusedElementOnActivation && document.activeElement) {
const activeElement = document.activeElement as HTMLElement;
if (activeElement.blur && (
activeElement.tagName === "INPUT" ||
activeElement.tagName === "TEXTAREA" ||
activeElement.contentEditable === "true"
)) {
activeElement.blur();
}
}

const run = (types: ElementTypes): void => {
const { oneTimeWindowMessageToken } = this;
if (oneTimeWindowMessageToken === undefined) {
Expand Down