Skip to content

Focus on composition area when pressing a key - #4998

Open
n-gao wants to merge 2 commits into
signalapp:mainfrom
n-gao:focus_compose
Open

Focus on composition area when pressing a key#4998
n-gao wants to merge 2 commits into
signalapp:mainfrom
n-gao:focus_compose

Conversation

@n-gao

@n-gao n-gao commented Feb 5, 2021

Copy link
Copy Markdown

First time contributor checklist:

Contributor checklist:

Description

At the moment, a user has to specifically focus on the composition field to write a message. However, it is often more convenient to just click somewhere into the application and start typing with the application automatically moving the focus.
Other chat applications do this too.

So, this PR enables that. The focus is only moved for printable characters and not for control characters and does not move the focus if another input field is currently selected.

Demo:
test

@xashyar

xashyar commented Feb 8, 2021

Copy link
Copy Markdown
Contributor

Currently (1.40.0-beta.4), closing the reply dialogue loses the focus on composition area, would this prevent that too?

@n-gao

n-gao commented Feb 8, 2021

Copy link
Copy Markdown
Author

@xashyar Well, the focus is still lost. However, you can still continue to type and the composition area gains focus automatically (also no characters are lost). So, whether it fixes it depends on your definition since the composition area still loses focus but it does not impact your typing.

@larstobi

larstobi commented Apr 6, 2021

Copy link
Copy Markdown

I think this PR would be really beneficial. Currently, I often have to click inside the text input area to be able to type, and it is getting slightly annoying. I'm not sure what causes the text input area to lose focus. I often just start typing and sometimes nothing appears, because focus is lost.

@n-gao

n-gao commented Nov 26, 2021

Copy link
Copy Markdown
Author

@EvanHahn-Signal is there any plan on merging this? I guess quite a lot of people are unsatisfied with the current typing behavior.

@josh-signal

Copy link
Copy Markdown
Contributor

@n-gao sorry we marked this as "needs review" to keep stale bot away when we added stale bot. Not sure if we actually want to do this though, I mean it seems fine on the surface but:

  1. There's already an explicit way to focus the composition area via keyboard.
  2. There are potential privacy concerns if the app has input focus but is not visible on the screen, doing so you could potentially enter text and send a message by mistake.

We're also worried about the implementation, there will now be a global keydown listener and that'll need to be maintained, seems like it could be a recipe for potential disaster if any of the other pieces that it needs to short-circuit on change and this code isn't updated to reflect that.

I'm happy to hear counterpoints to this -- I sometimes experience this issue and start typing but the composition area isn't in focus. I usually quickly realize and just focus it with cmd+shift+t

@larstobi

larstobi commented Dec 3, 2021

Copy link
Copy Markdown

cmd+shift+t seems undocumented to me. I wasn't aware it existed, and I cannot find the shortcut in the menu bar or in preferences. Now that I know of it: neat! I will test if this is sufficient for me. I sometimes find it surprising that the focus is not in the text input field, not sure why it is not sometimes.

@awaitlink

Copy link
Copy Markdown
Contributor

cmd+shift+t seems undocumented to me. I wasn't aware it existed, and I cannot find the shortcut in the menu bar or in preferences

I wasn't aware of it either, but it does appear to be documented in both the +/ popup and the respective support article under the name "Focus composer".

@n-gao

n-gao commented Dec 3, 2021

Copy link
Copy Markdown
Author

@josh-signal The comments by @u32i64 and @larstobi illustrate the difficulty of having to rely on hotkeys. Most people (including me) are not aware of these and for them, it is mostly an annoyance having to click on the composing box. Imho, hotkeys are always heavy user-oriented.

Is having Signal outside of your screen and the composer focused an actual issue? Right now, I could also have been typing and then moving the window outside of my screen (not sure why anyone would do that) and the focus on the composer would stay. If the window is minimized it automatically loses focus (at least on windows but I would be surprised if other OS's keep the focus if you minimized a window) and you can't type. Furthermore, other chat clients like WhatsApp or Telegram decided it not being a real issue and include this feature.

Regarding the global observer, I see your concerns. This is why it's not a global observer (like hotkeys) but restricted to the composition area. I think that the composing area is a good compromise since it's easy to hit without affecting parts of the application where it definitely should not trigger. If the focus is on the contact pane the focus obviously should not switch to the composer.

@josh-signal

josh-signal commented Dec 3, 2021

Copy link
Copy Markdown
Contributor

Yeah the shortcuts aren't intuitive which is why this PR exists. edit: But glad ya'll are aware of them now 😄

Is having Signal outside of your screen and the composer focused an actual issue?

In most cases I'm guessing no, but it is a possibility so I raised it as a concern.

This is why it's not a global observer

It's adding the event listener to document so yeah it's grabbing all input. Perhaps a better safer approach would be to figure out what node is focused and listen to keypress on that node? I think we can test the "in focus" issue using something like macOS' spaces.

}

// We don't want to switch focus if another panel is up
const panels = document.querySelectorAll('.conversation .panel');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also these kind of class lookups are brittle, if we ever change conversation | panel this would fall apart. I think ideally redux would know about panel state and we can just query that selector if there are panels active or not.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this information already saved in a Redux store somewhere? Or are you implying that it should be added? (And if you're suggesting it be added, where would be your suggestion for where to add this?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, seems like this already has precedent in the codebase:

const panels = document.querySelectorAll('.conversation .panel');
if (panels && panels.length > 1) {
return;
}

Maybe refactoring this could be done in a different PR?

@karlhorky

Copy link
Copy Markdown

@n-gao do you think that you will be able to get back to this sometime soon? This is a feature that every other desktop messenger client has, so it's a big UX drawback that this doesn't already exist.

return;
}

// We don't want to take focus away of input fields

@karlhorky karlhorky Oct 30, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarity:

Suggested change
// We don't want to take focus away of input fields
// Avoid stealing focus from focused input fields

Comment on lines +377 to +378
const { activeElement } = document;
if (activeElement?.nodeName.toLowerCase() === 'input') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Avoid extra identifier in scope

Suggested change
const { activeElement } = document;
if (activeElement?.nodeName.toLowerCase() === 'input') {
if (document.activeElement?.nodeName.toLowerCase() === 'input') {

};
}, [setLarge]);

// Listen to any key in the conversation panel to

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Listen to any key in the conversation panel to
// Focus message composition input when key is pressed

return;
}

inputApiRef.current?.focus();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the focusInput callback instead?

If yes, then:

Suggested change
inputApiRef.current?.focus();
focusInput();

Comment on lines +385 to +388
document.addEventListener('keydown', handler);
return () => {
document.removeEventListener('keydown', handler);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surfacing @josh-signal's comment here in a conversation:

It's adding the event listener to document so yeah it's grabbing all input. Perhaps a better safer approach would be to figure out what node is focused and listen to keypress on that node? I think we can test the "in focus" issue using something like macOS' spaces.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josh-signal to be clear, you're suggesting this change?

Suggested change
document.addEventListener('keydown', handler);
return () => {
document.removeEventListener('keydown', handler);
};
document.activeElement.addEventListener('keypress', handler);
return () => {
document.activeElement.removeEventListener('keypress', handler);
};

Not sure if this will work, but at least it's a starting place for the conversation.

}, [setLarge]);

// Listen to any key in the conversation panel to
React.useEffect(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEffect has now been imported as a named import

Suggested change
React.useEffect(() => {
useEffect(() => {

@karlhorky

karlhorky commented Oct 30, 2022

Copy link
Copy Markdown

For anyone else who doesn't want to wait for this to be accepted, I've created a patcher for the Signal desktop Electron app (macOS only for now):

https://github.com/karlhorky/electron-app-patcher

Just clone, install the dependencies and run yarn patch signal to add @n-gao's patch to your latest version of the official Signal Electron app 👍 Kind of like patch-package for Electron apps :)

Edit: Upgraded my patch for Signal 6.0.0: karlhorky/electron-app-patcher@6fbdffe

@karlhorky

karlhorky commented Dec 1, 2022

Copy link
Copy Markdown

@josh-signal or @jamiebuilds-signal would it be possible to get another review on this? Would love to get a version of this missing UX feature in the app finally.

@lockieluke

Copy link
Copy Markdown

why is this no merged already??

@karlhorky

Copy link
Copy Markdown

I updated my patch for Signal 6.3.0, which was released recently:

@karlhorky

karlhorky commented Mar 9, 2023

Copy link
Copy Markdown

No other patch changes have been necessary for the new versions up to Signal 6.9.0, although it is annoying to have to update every time an update comes out:

  1. Receive "failed update" notification in Signal - auto-update does not work with the patched Signal app
  2. Potentially have to wait for the Homebrew cask to get merged
  3. Upgrade via brew upgrade signal in the terminal
  4. Apply the patch using electron-app-patcher
  5. Re-allow the patched Signal app to start in Privacy & Security in System Settings
  6. Re-allow the patched Signal app to access the keychain

@karlhorky

Copy link
Copy Markdown

@indutny-signal any news on what it would take to get this merged? Or a timeline?

@karlhorky

karlhorky commented May 13, 2023

Copy link
Copy Markdown

Signal Patch Changelog

Version changelog for all of the fixes needed with the new versions of Signal:

Hopefully we can get this missing UX feature sometime soon, so that I don't need to keep maintaining this.

@karlhorky

Copy link
Copy Markdown

@scottnonnenberg-signal @indutny-signal @josh-signal friendly ping - would love to be able to get this missing feature in Signal.

Could someone from the Signal team respond here?

@lockieluke

Copy link
Copy Markdown

what's the major factor blocking this pr

@nobkd

nobkd commented Jun 19, 2024

Copy link
Copy Markdown

Having this feature would really help a lot.
Is there anything blocking this from being merged?

@Blooym

Blooym commented Jul 31, 2025

Copy link
Copy Markdown

Yearly nudge - what's blocking this? As it stands this is my one big problem with using Signal desktop as I frequently tab around my system and having to either hit a keybind or reach for my mouse to focus the input field slows me down to the point of wanting to use another app just for speed. Several other instant messaging platforms adopt this behaviour and it's kinda come to be expected as default.

@karlhorky

karlhorky commented Jul 31, 2025

Copy link
Copy Markdown

Yeah, I think this issue needs more publicity.

As of now, I think the most common triggers of the broken behavior, eg:

  1. a) click on link b) type something afterwards c) text doesn't appear 💥
  2. a) copy text from message b) type something afterwards c) text doesn't appear 💥

...for most users will just lead to a weird feeling of discomfort, as if Signal desktop doesn't work properly. And most users won't know where to look or report the problem.

So a (new) central public GitHub issue which we can direct a lot of community attention and publicity to would be a good start, I think.

The Signal team hasn't prioritized it yet, but hopefully seeing a large amount of their userbase pushing for a public issue (instead of it getting lost and ignored in the PRs here) would cause them to change this stance on fixing this important UX bug.

@Blooym

Blooym commented Jul 31, 2025

Copy link
Copy Markdown

There was #1096 tracking this prior to the community forums, but that's now been moved to https://community.signalusers.org/t/desktop-focus-to-input-field-on-window-click/8930, there's also https://community.signalusers.org/t/allow-typing-when-chatbox-isnt-focused/62163. Unfortunately neither of these have seen much movement either - so it'd probably be best to push for comments there + general social platforms.

Really hope to see this change land sooner rather than later, it's been 8 years since the original request was made for something I'd argue is rather simple (and even could just be a toggle).

@karlhorky

Copy link
Copy Markdown

Looks like more users @AlterNezKo @performancer and @SteveDinn reporting the same problem over in a more recent issue (Aug 2024, Sep 2024):

(issue was closed by @jamiebuilds-signal for a reason unrelated to the original issue description)

There appears to be already a very high number of users who have reported this, across the various resources we've seen so far. And judging by typical open source contribution patterns, many more than that who are affected and do not like it but do not know where to report.

@biskweet

biskweet commented Feb 5, 2026

Copy link
Copy Markdown

Bumping the issue. It's been open for 5 years and still nothing! What could be preventing merge?

@karlhorky

karlhorky commented Feb 10, 2026

Copy link
Copy Markdown

The thing that is preventing merge are a deep look at possible edge cases that are related to this feature and adding tests, so that this doesn't turn into a long tail of bug reports after it's added.

@scottnonnenberg-signal: deep competitive research including specific investigation into all edge cases, and handle them

@josh-signal in comment 984929854: We're also worried about the implementation, there will now be a global keydown listener and that'll need to be maintained, seems like it could be a recipe for potential disaster if any of the other pieces that it needs to short-circuit on change and this code isn't updated to reflect that.

And also, in another PR from 2018 (one other similar focus issue reported in 2017, since the focus bugs have been going on for a long time):

@scottnonnenberg-signal in comment 480936124: Really, what I'm looking for is testing. Contributing.md should help you get a staging app up and running, and then you can do exhaustive testing on this. I don't think we can merge this until you've done testing and summarized your findings here.

So it looks like the Signal team:

  1. Doesn't set priority on this UX bug
  2. Would need a lot of deep research on competition
  3. Would need a lot of deep research on edge cases, and how this interacts with the entire Signal desktop web app
  4. Would need exhaustive tests

If anyone would have the possibility of doing a deep dive (in a new PR / issue) on that, to fix this broken UX between Signal desktop and pretty much every other messenger, then I will try to support with testing!

AlexProgrammerDE added a commit to AlexProgrammerDE/Signal-Desktop that referenced this pull request Feb 18, 2026
Add auto-focus behavior that moves focus to the message composition
input when a printable key is pressed, matching the UX of other
major desktop messengers.

Includes a user-facing toggle in Settings > Chats (default: on)
and comprehensive guards against focus stealing from other inputs,
keyboard shortcut interference, and non-printable keys.

Supersedes signalapp#4998.
@AlexProgrammerDE

AlexProgrammerDE commented Feb 18, 2026

Copy link
Copy Markdown

@karlhorky Hi, I've decided to give this PR a fresh shot. Seems this one has merge conflicts and is dead. The new PR should fix most of the original criticisms of privacy and not using idiomatic calls. Link: #7722
This is one of the main reasons I cannot use Signal over WhatsApp or Discord right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.