# Search keyboard shortcuts hijacked?

**URL:** https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859
**Category:** Bug
**Tags:** keyboard-shortcuts
**Created:** [2017 年1 月 16 日 18:46 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859 "2017-01-16T18:46:51Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### 作者： ![ntadej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ntadej/32/116716_2.png) [@ntadej](https://meta.discourse.org/u/ntadej)
#### 发布日期： [2017 年1 月 16 日 18:46 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/1 "2017-01-16T18:46:51Z")

</div>

Not sure if this is a bug or a feature (it looks new to me anyhow, move accordingly if wrong):

I usually search for content inside posts (e.g. today I wanted to search something about development on macOS inside the first long post). Now it seems that Ctrl+F/CMD+F are mapped to opening the search input set to search current thread. There are some issues/possible improvements:

- this didn’t work in all threads
- pressing enter 2 times on same query just hides the results, to get them back, query needs to be changed
- possible fixes for long posts:
- search results should be highlighted
- add ability to fallback to browser search
- cycle through found words

I hope search didn’t fail me and no thread about this exists yet 🙂

---

<div class="post-metadata">

### 作者： ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### 发布日期： [2017 年1 月 16 日 18:48 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/2 "2017-01-16T18:48:29Z")

</div>

This is intentional. You can press CTRL+F twice to get back to the browser built-in search on long topics.

> [@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.

And plenty more topics on the matter  
[https://meta.discourse.org/search?q=ctrl%2Bf](https://meta.discourse.org/search?q=ctrl%2Bf)

---

<div class="post-metadata">

### 作者： ![ntadej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ntadej/32/116716_2.png) [@ntadej](https://meta.discourse.org/u/ntadej)
#### 发布日期： [2017 年1 月 16 日 18:51 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/3 "2017-01-16T18:51:31Z")

</div>

Oh, I didn’t realise this before. 😟

Still, there is a bug with 2xEnter I guess 🙂

---

<div class="post-metadata">

### 作者： ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### 发布日期： [2017 年1 月 16 日 18:53 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/4 "2017-01-16T18:53:07Z")

</div>

> [@ntadej](#):
>
> pressing enter 2 times on same query just hides the results, to get them back, query needs to be changed

That is indeed interesting, might be a feature request, what should it do when you press Enter a second time?

> [@ntadej](#):
>
> search results should be highlighted

This seems to have regressed

> [@No indication if an in-page CTRL-F search is returning results](https://meta.discourse.org/t/no-indication-if-an-in-page-ctrl-f-search-is-returning-results/16371/3):
>
> You have to click or tap the search results to get navigated to the match, like so, here I did the following Clicked search icon Typed “list” without the quotes Clicked the first match

---

<div class="post-metadata">

### 作者： ![ntadej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ntadej/32/116716_2.png) [@ntadej](https://meta.discourse.org/u/ntadej)
#### 发布日期： [2017 年1 月 16 日 18:56 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/5 "2017-01-16T18:56:41Z")

</div>

> [@cpradio](#):
>
> That is indeed interesting, might be a feature request, what should it do when you press Enter a second time?

I guess it should just refresh the results and not hide the search input. This would be a bug fix.

An improvement would be to cycle through the results (a new feature).

---

<div class="post-metadata">

### 作者： ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### 发布日期： [2017 年1 月 16 日 23:49 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/6 "2017-01-16T23:49:38Z")

</div>

@tgxworld can you check and make sure search results are highlighted, that this has not regressed?

---

<div class="post-metadata">

### 作者： ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### 发布日期： [2017 年1 月 17 日 04:49 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/7 "2017-01-17T04:49:02Z")

</div>

Both bugs are valid and I’ve fixed them in

[https://github.com/discourse/discourse/commit/ee58c4cd94d58047ec4096440fa3d6d8c4aadbc9](https://github.com/discourse/discourse/commit/ee58c4cd94d58047ec4096440fa3d6d8c4aadbc9)  
[https://github.com/discourse/discourse/commit/de6ca4f736b91d57b0b0e60f86669a9eb7bece66](https://github.com/discourse/discourse/commit/de6ca4f736b91d57b0b0e60f86669a9eb7bece66)

---

<div class="post-metadata">

### 作者： ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### 发布日期： [2017 年1 月 17 日 04:49 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/8 "2017-01-17T04:49:40Z")

</div>



---

<div class="post-metadata">

### 作者： ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### 发布日期： [2017 年1 月 17 日 05:04 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/9 "2017-01-17T05:04:17Z")

</div>



---

<div class="post-metadata">

### 作者： ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### 发布日期： [2017 年1 月 17 日 05:05 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/10 "2017-01-17T05:05:52Z")

</div>

@eviltrout I was looking into adding an acceptance test but I can’t quite figure out why the search menu closes in test but not in development 🤔

> <https://gist.github.com/tgxworld/0a32269987440f7bdeae2df7ee88e98e>

---

<div class="post-metadata">

### 作者： ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### 发布日期： [2017 年1 月 17 日 11:14 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/11 "2017-01-17T11:14:44Z")

</div>

@tgxworld, this seems to be impacting Notifications. I can’t click on my notifications and get to the post anymore.  
[https://github.com/discourse/discourse/commit/ee58c4cd94d58047ec4096440fa3d6d8c4aadbc9](https://github.com/discourse/discourse/commit/ee58c4cd94d58047ec4096440fa3d6d8c4aadbc9)

Repro Steps  
Click on User Profile Avatar, click any notification, fails to navigate to post, throws error

```plaintext
Uncaught TypeError: Cannot read property 'searchContextEnabled' of undefined
    at t.linkClickedEvent (_application-ab1012b….js:44622)
    at _application-ab1012b….js:49145
    at t.value (_application-ab1012b….js:49127)
    at t.value (_application-ab1012b….js:49142)
    at t.click (_application-ab1012b….js:45204)
    at _application-ab1012b….js:44913
    at _application-ab1012b….js:44849
    at t.value (_application-ab1012b….js:49127)
    at s (_application-ab1012b….js:44848)
    at HTMLDocument.<anonymous> (_application-ab1012b….js:44912)

```

---

<div class="post-metadata">

### 作者： ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### 发布日期： [2017 年1 月 17 日 11:17 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/12 "2017-01-17T11:17:06Z")

</div>

Can confirm, affecting me on both Windows (Chrome) and Android 7.1 (Chrome).

---

<div class="post-metadata">

### 作者： ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### 发布日期： [2017 年1 月 17 日 11:35 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/13 "2017-01-17T11:35:25Z")

</div>

Fixed in

[https://github.com/discourse/discourse/commit/fc52624aac658eef63f5b61bb1846463216d49e6](https://github.com/discourse/discourse/commit/fc52624aac658eef63f5b61bb1846463216d49e6)

Our build was broken for awhile so I couldn’t deploy stuff

---

<div class="post-metadata">

### 作者： ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### 发布日期： [2017 年1 月 19 日 15:40 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/14 "2017-01-19T15:40:14Z")

</div>

I am not sure off the top of my head, would require a bit more in depth tracing through the app.

Having said that, I am not sure I love defining pretender stuff in the test like that. It discourages reuse across tests in the suite, and you can’t even embed it here because it takes up so much space that I can’t see anything else 😛

It would be one thing if it was just a short stub of a response, but if using a fixture I really think it works better in its own file!

---

<div class="post-metadata">

### 作者： ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### 发布日期： [2017 年1 月 20 日 00:50 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/15 "2017-01-20T00:50:26Z")

</div>

> [@eviltrout](#):
>
> I am not sure I love defining pretender stuff in the test like that. It discourages reuse across tests in the suite,

I guess using fixtures is the easiest way to get our JS acceptance tests going but one of the downsides that I find with fixtures is that they are usually too specific to a single use case and makes it hard to be reuse. In addition, fixtures are so huge that a new developer wouldn’t be able to easily understand why a fixture was added unless given the right context. That is why I prefer to add fixtures at the file level or embedded them within each individual test if you need the same route to return a different fixture. Just some thoughts I have after fighting with acceptance tests quite abit 😛

---

<div class="post-metadata">

### 作者： ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### 发布日期： [2017 年1 月 20 日 00:53 UTC](https://meta.discourse.org/t/search-keyboard-shortcuts-hijacked/55859/16 "2017-01-20T00:53:34Z")

</div>


