# Pressing Ctrl+F twice on topic search should close the Discourse search window

**URL:** https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649
**Category:** Feature
**Created:** [4 בספטמבר,‏ 2014,‏ 8:36pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649 "2014-09-04T20:36:51Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [4 בספטמבר,‏ 2014,‏ 8:36pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/1 "2014-09-04T20:36:51Z")

</div>

I sometimes want to use the browser search window within topics since the Discourse search function jumps only to posts and not the exact position of the search term. Pressing Ctrl+F works quite well.

However, the Discourse search window doesn’t close automatically when I use the browser’s search function. The first few search results therefore are often within the search window. That’s quite annoying.

 ![](https://global.discourse-cdn.com/meta/original/3X/b/4/b4270a9aff431294b09a7e419504b912cfe43d52.png) 

Expected behaviour: When I press Ctrl+F the second time, the Discourse search window should close automatically.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [4 בספטמבר,‏ 2014,‏ 8:45pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/2 "2014-09-04T20:45:06Z")

</div>

Hmm… That may be easier said than done. As by default the keyboard keypress framework that Discourse uses, doesn’t capture keypresses that are made in input boxes (which is why pressing it twice works).

So there is nothing capturing the second pressing of it. And if we did, you’d have us capturing it instead of the browser responding to it… So its a bit of catch-22 here.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [4 בספטמבר,‏ 2014,‏ 8:56pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/3 "2014-09-04T20:56:57Z")

</div>

After a quick look at the documentation of Mousetrap it looks like the following could work:

- Add `class="mousetrap"` to the [input field](http://craig.is/killing/mice#api.bind.text-fields).
- Close the search window when Ctrl+F is pressed
- Do _not_ stop the [default behaviour](http://craig.is/killing/mice#api.bind.default) (return `true` instead of `false` in the event handler)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [4 בספטמבר,‏ 2014,‏ 9:01pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/4 "2014-09-04T21:01:07Z")

</div>

I’ve starred this, so I’ll take a look when I get around to it. If it works and doesn’t have any side effects, I’ll submit the PR for it.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [5 בספטמבר,‏ 2014,‏ 2:03am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/5 "2014-09-05T02:03:23Z")

</div>

I want to add that I am very happy you have adopted the keyboard bits! Be the change you want to see, and you are doing exactly that. Kudos.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [12 ביוני,‏ 2015,‏ 5:28am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/6 "2015-06-12T05:28:37Z")

</div>

I submitted a PR for it if anyone would like to take a look and review 😺

[https://github.com/discourse/discourse/pull/3546](https://github.com/discourse/discourse/pull/3546)

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [18 ביוני,‏ 2015,‏ 6:12pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/7 "2015-06-18T18:12:21Z")

</div>

Thanks for your PR. Unfortunately it doesn’t work the way I imagined, but I guess that’s because I didn’t exactly describe the behavior I wanted. I’ll clarify it:

**Expected behavior** : When I press Ctrl+F the second time, the Discourse search window should close automatically and the browser’s search window should be visible and have focus.

Current behavior **without the PR** : When I press Ctrl+F the second time, the Discourse search window stays open and the browser’s search window is visible and has focus.

Behavior **with the PR** : When I press Ctrl+F the second time, the Discourse search window closes, but there is now browser search window.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [19 ביוני,‏ 2015,‏ 11:15am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/8 "2015-06-19T11:15:42Z")

</div>

@gerhard thanks for clarifying 😄 I do find the proposed behavior to be confusing for users as I’m not sure how we can clearly bring across the behavior to users that pressing `Ctrl + f` twice will first bring up Discourse search and then the browser’s search.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [19 ביוני,‏ 2015,‏ 11:22am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/9 "2015-06-19T11:22:58Z")

</div>

> [@tgxworld](#):
>
> pressing Ctrl + f twice will first bring up Discourse search and then the browser’s search

But that is exactly what is happening if you press Ctrl+F in a topic with lots of posts. Try it out yourself by pressing it inside a topic with more than 20 posts.

And it is good that this is happening since I want to be able to search using my browser. It has a better search experience. My problem right now is that the Discourse search window stays visible and I get lots of search results from the browser that are within Discourse’s search results. See my screenshot in the [first post](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649).

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [19 ביוני,‏ 2015,‏ 11:26am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/10 "2015-06-19T11:26:17Z")

</div>

I do understand what you mean and I believe the browser’s search appearing is a bug since Discourse has made the decision to hijack the search on the first ctrl+f.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [19 ביוני,‏ 2015,‏ 11:33am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/11 "2015-06-19T11:33:33Z")

</div>

No, it’s not a bug. That is intentional. You can read about it in older discussions:

> [@Discourse taking over Ctrl-F](https://meta.discourse.org/t/discourse-taking-over-ctrl-f/16190):
>
> Ctrl-F is for searching the page, for example specific text in a conversation (huge use case). Discourse seems to think it knows better and wants to search other conversations for the text. Thus leaving one no way to search the actual page you’re on for text. Taking over and changing browser functionality is very bad. This is happening on Chrome.

> [@Options to disable hijack of CMD+F / CTRL+F and "/" keys for search?](https://meta.discourse.org/t/options-to-disable-hijack-of-cmd-f-ctrl-f-and-keys-for-search/16875):
>
> I’m not sure why anyone thought it was a good idea to hijack the universally accepted “Find” functionality of the browser to open the search box… it’s nothing but frustrating when you’re trying to find text on the page. I noticed whoever implemented also decided they would be clever by also hijacking the less common “/” (vi-style) key shortcut for this as well. Please at least offer a user-configurable option to disable and an admin-configurable default setting.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [19 ביוני,‏ 2015,‏ 3:55pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/12 "2015-06-19T15:55:23Z")

</div>

> [@gerhard](#):
>
> No, it’s not a bug. That is intentional. You can read about it in older discussions:

I prefer to call it a happy little accident.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [19 ביוני,‏ 2015,‏ 9:17pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/13 "2015-06-19T21:17:32Z")

</div>

I submitted a PR that implements the expected behavior:

> [@gerhard](#):
>
> When I press Ctrl+F the second time, the Discourse search window should close automatically and the browser’s search window should be visible and have focus.

[https://github.com/discourse/discourse/pull/3559](https://github.com/discourse/discourse/pull/3559)

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [21 ביוני,‏ 2015,‏ 9:14am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/14 "2015-06-21T09:14:17Z")

</div>

@gerhard I just tested your PR out 😄 Looks good to me and definitely a better experience.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [23 בספטמבר,‏ 2015,‏ 1:13pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/15 "2015-09-23T13:13:37Z")

</div>



---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [17 בנובמבר,‏ 2015,‏ 3:40pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/16 "2015-11-17T15:40:05Z")

</div>



---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [17 בנובמבר,‏ 2015,‏ 3:42pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/17 "2015-11-17T15:42:07Z")

</div>

This has regressed on meta ☹ 🐈

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [17 בנובמבר,‏ 2015,‏ 7:39pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/18 "2015-11-17T19:39:42Z")

</div>

Well, it worked for nearly three weeks since [my last fix](https://github.com/discourse/discourse/pull/3844).  
Let’s see how long this one will last. 😉

[https://github.com/discourse/discourse/pull/3903](https://github.com/discourse/discourse/pull/3903)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [17 בנובמבר,‏ 2015,‏ 9:39pm UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/19 "2015-11-17T21:39:31Z")

</div>

> [@gerhard](#):
>
> Let’s see how long this one will last.

Should we start an office pool? 😆

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [19 בנובמבר,‏ 2015,‏ 8:20am UTC](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649/20 "2015-11-19T08:20:48Z")

</div>

Perhaps a test just to make sure on a long topic, Ctrl + f twice will at least close the search header.

I wasn’t sure how to send a Ctrl + f in the tests but @eviltrout solved it yesterday 😄

> <https://github.com/discourse/discourse/blob/84a50a1260c228ad71a1d3dcbe17b50b36507663/test/javascripts/acceptance/composer-test.js.es6#L47-L53>

[Next page](https://meta.discourse.org/t/pressing-ctrl-f-twice-on-topic-search-should-close-the-discourse-search-window/19649.md?page=2)
