sourcegraph/client/client-api
Ólafur Páll Geirsson 9cbd8312f4
Go to definition: push current location into browser history (#50349)
Previously, the behavior was different whether you clicked on the "Go to
definition" link in the popover or used cmd-click. When using the link,
the current location didn't get pushed into the browser history making
"Go back" jump to a surprising location. When using cmd-click to
navigate to a definition, we pushed the current location into the
browser history to replicate the experience of navigating code in the
editor where you can easily go up/down the "jump stack", which is the
list of locations you navigate from/to with "Go to definition".

Importantly, this PR preserves the HTML link in the popover so that
users can still right-click "Open link in new tab".

## Test plan

Manually tested with 
```
❯ SOURCEGRAPHDOTCOM_MODE=true SOURCEGRAPH_API_URL=https://sourcegraph.com sg start web-standalone
```

- Open URL
https://sourcegraph.test:3443/github.com/sourcegraph/sourcegraph/-/blob/cmd/gitserver/server/server.go?L1080
- Load popover for `serverContext` on line 1093
- Click "Go to definition"
- "Go back" in the browser history and verify that you go back to line
1093 (not 1080!)
- Load the popover again for `serverContext`
- Use cmd-click (or ctrl-click on Linux/Windows) on the "Go to
definition" *link* and verify that it opens the definition in a new
browser tab. Do the same for shift-click to open the link in a new
window.
- Load the popover again for `serverContext`
- Verify that you can right-click on the "Go to definition" *link* and
use "Open Link in New Tab" to open the definition location in a new
browser tab


Going back in history 
![CleanShot 2023-04-04 at 17 57
06](https://user-images.githubusercontent.com/1408093/229850120-1dc562c1-1a65-4b40-80ac-69fe75352a97.gif)



<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

## App preview:

- [Web](https://sg-web-olafurpg-definition-recover.onrender.com/search)

Check out the [client app preview
documentation](https://docs.sourcegraph.com/dev/how-to/client_pr_previews)
to learn more.

---------

Co-authored-by: Taras Yemets <yemets.taras@gmail.com>
2023-04-11 15:27:41 +00:00
..
src Go to definition: push current location into browser history (#50349) 2023-04-11 15:27:41 +00:00
.eslintignore Create a client-api package (#31151) 2022-03-17 01:17:26 -07:00
.eslintrc.js Create a client-api package (#31151) 2022-03-17 01:17:26 -07:00
babel.config.js Create a client-api package (#31151) 2022-03-17 01:17:26 -07:00
BUILD.bazel bazel: add bazel build,tests for client/* (#46193) 2023-02-28 20:46:03 -08:00
jest.config.js Create a client-api package (#31151) 2022-03-17 01:17:26 -07:00
package.json web: fix pnpm-lock issue (#47478) 2023-02-09 22:04:31 -08:00
README.md Create a client-api package (#31151) 2022-03-17 01:17:26 -07:00
tsconfig.json web: fix pnpm-lock issue (#47478) 2023-02-09 22:04:31 -08:00

Client API

Sourcegraph Client API