Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add breadcrumbs bar to editor widget #6371

Closed

Conversation

corneliusludmann
Copy link
Contributor

What it does

This commit adds a breadcrumbs bar to the editor widget. It shows the path to the current file and outline information as breadcrumbs. A click of breadcrumbs allows to switch to siblings.

This fixes #5475.

How to test

Open an editor shows the breadcrumbs on top of the editor. Folders with files are clickable. A popup allows to select a file that will be opened immediately. Outline information are added to the breadcrumbs as well.

Review checklist

Reminder for reviewers

@AlexTugarev
Copy link
Contributor

@corneliusludmann please make sure you've signed an ECA https://accounts.eclipse.org/user/eca

@corneliusludmann
Copy link
Contributor Author

@corneliusludmann please make sure you've signed an ECA https://accounts.eclipse.org/user/eca

Currently working on it … ::-)

@vitaliy-guliy
Copy link
Contributor

@corneliusludmann could you attach few screenshots?

@corneliusludmann
Copy link
Contributor Author

@corneliusludmann could you attach few screenshots?

Sure. This GIF shows the breadcrumbs in action:

Peek 2019-10-10 22-12

@corneliusludmann
Copy link
Contributor Author

Attention: I came across with an issue that occurs when opening the Preferences widget after this commit as described here: #6377. I proposed an solution there: #6378. I suggest fixing that issue first and then rebase this PR.

@akosyakov akosyakov added the editor issues related to the editor label Oct 13, 2019
@akosyakov
Copy link
Member

How can one disable them? Can we have breadcrumbs.enabled as in VS Code?

@akosyakov
Copy link
Member

akosyakov commented Oct 13, 2019

  • It does not work like in VS Code: when one click on the part of a path VS Code allows to siblings files, not to chlid as in this PR.
  • for editor-widget.ts editor, editor segment is not clickable at all
  • when something opens it only allows to open files, not folders

});

// updateOutline and handleCurrentEditorChanged need to be called even when the outline view widget is closed
// in order to udpate breadcrumbs.
Copy link
Member

Choose a reason for hiding this comment

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

i don't understand it, if an editor is closed there should not be breadcrumbs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The removed condition does not check if an editor is open or closed it checks if the outline view is open or closed. Previously, the outline changes are propagated when the outline view is open only. Now we need the information even when the outline view is closed because the outline view is not the only one that uses this information anymore. The breadcrumbs need the information as well.

What we could do is to check whether the outline view is open OR the breadcrumbs are visible (by the preferences entry breadcrumbs.enabled). I don't know if it is really worth it.

bind(BreadcrumbsRendererFactory).toFactory(ctx =>
(editor: TextEditor) => {
const childContainer = ctx.container.createChild();
childContainer.bind('TextEditor').toConstantValue(editor);
Copy link
Member

@akosyakov akosyakov Oct 13, 2019

Choose a reason for hiding this comment

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

please use a symbol, if there are duplicate extensions installed, they can pick a bogus instance by a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@akosyakov
Copy link
Member

akosyakov commented Oct 13, 2019

Why don't we reuse file and outline tree widgets to open URIs? We have already them, have to create new instances and render on click?

I would also prefer if we have something like BreadcrumbService and BreadcrumbContribution in core which are URI and DOM event based, so:

  • editor extension is using it to open a URI from breadcrumbs, i.e. BreadcrumbService.open(uri, {x, y})
  • filesystem extension implements BreadcrumbContribution to open a new file tree widget for the given
    URI
  • workspace extension overrides FileSystemBreadcrumbContribution in order to customize some bits
  • outline implement BreadcrumbContribution to open a new outline tree widget for the given URI if it has ... as a fragment

@akosyakov akosyakov added filesystem issues related to the filesystem outline issues related to the outline labels Oct 13, 2019
@lmcbout
Copy link
Contributor

lmcbout commented Oct 15, 2019

Note: using Theia in the workspace
Close all editors, then open package.json

Found some issues when playing with this PR:

1- No folders available from the breadcrumbs pull down
2- First click in the editor does not expand the breadcrumbs menu, need to click on another line to expand it
3-  In VSCode, there is "..." appearing at the end when opening the file when there is no selection
    In VSCode: When selecting at the end of the line for "name" , three dots shows for the selection, 
    In Theia, navigating to the Name  keeps the last structure selection, i.e. engines | devDependencies 
    when selecting after the last char of the line, no refresh.

VSCode:
VSCode_breadcrumbs

Theia:
Theia_breadcrumbs

@corneliusludmann
Copy link
Contributor Author

Found some issues when playing with this PR:

Thank you for your helpful feedback.

1- No folders available from the breadcrumbs pull down

Yes, that is a limitation I forgot to mention in the PR description. I currently working on adding the existing file tree view in the popup. I had it planned as the next evolutionary step. Sorry I didn't mention it.

2- First click in the editor does not expand the breadcrumbs menu, need to click on another line to expand it

That seems to be a bug in the existing outline view implementation. When you carefully observe the outline view you will see that on first click the outline is rendered without highlighting the current selection. Only after the second click the selection is highlighted. Thus, fixing this will fix this issue as well. I gonna file an issue for that if not already exist.

3- In VSCode, there is "..." appearing at the end when opening the file when there is no selection

Seems to be another limitation I was not aware of. Consider to implement this as well.

In VSCode: When selecting at the end of the line for "name" , three dots shows for the selection,
In Theia, navigating to the Name keeps the last structure selection, i.e. engines | devDependencies
when selecting after the last char of the line, no refresh.

Oh, yes, you're right. Outline breadcrumbs are not removed when there is no selection. Gonna fix this.

@lmcbout
Copy link
Contributor

lmcbout commented Oct 15, 2019

2- First click in the editor does not expand the breadcrumbs menu, need to click on another line to expand it

That seems to be a bug in the existing outline view implementation. When you carefully observe the outline view you will see that on first click the outline is rendered without highlighting the current selection. Only after the second click the selection is highlighted. Thus, fixing this will fix this issue as well. I gonna file an issue for that if not already exist.

There might be a bug in the outline view implementation, but I think it is more than that, If you look at the following video, After opening the file, I selected "@types/chai" On the first click, we can see the blue bar on top of the editor and the data being displayed in the outline view, but keeping to select the same item over and over does not amend the breadcrumbs until I select another item or double click on the current selection.
Theia_breadcrumbs2

@corneliusludmann
Copy link
Contributor Author

I would also prefer if we have something like BreadcrumbService and BreadcrumbContribution in core which are URI and DOM event based, so:

  • editor extension is using it to open a URI from breadcrumbs, i.e. BreadcrumbService.open(uri, {x, y})
  • filesystem extension implements BreadcrumbContribution to open a new file tree widget for the given
    URI
  • workspace extension overrides FileSystemBreadcrumbContribution in order to customize some bits
  • outline implement BreadcrumbContribution to open a new outline tree widget for the given URI if it has ... as a fragment

I refactored the code with commit 03eb644 which introduces BreadcrumbService and BreadcrumbContribution. Fell free to make your comments.

I will squash the commits once I implemented all suggested changes.

@corneliusludmann
Copy link
Contributor Author

How can one disable them? Can we have breadcrumbs.enabled as in VS Code?

Done with commit 3dee5ec.

I will squash the commits once I implemented all suggested changes.

@corneliusludmann
Copy link
Contributor Author

Why don't we reuse file and outline tree widgets to open URIs? We have already them, have to create new instances and render on click?

For the file tree widget, I currently working on it. For the outline tree widget it seems not possible yet because the tree is not easily reusable yet.

@corneliusludmann
Copy link
Contributor Author

In VSCode: When selecting at the end of the line for "name" , three dots shows for the selection,
In Theia, navigating to the Name keeps the last structure selection, i.e. engines | devDependencies
when selecting after the last char of the line, no refresh.

Oh, yes, you're right. Outline breadcrumbs are not removed when there is no selection. Gonna fix this.

Should be fixed with commit 03eb644.

@corneliusludmann
Copy link
Contributor Author

2- First click in the editor does not expand the breadcrumbs menu, need to click on another line to expand it

That seems to be a bug in the existing outline view implementation. When you carefully observe the outline view you will see that on first click the outline is rendered without highlighting the current selection. Only after the second click the selection is highlighted. Thus, fixing this will fix this issue as well. I gonna file an issue for that if not already exist.

There might be a bug in the outline view implementation, but I think it is more than that, If you look at the following video, After opening the file, I selected "@types/chai" On the first click, we can see the blue bar on top of the editor and the data being displayed in the outline view, but keeping to select the same item over and over does not amend the breadcrumbs until I select another item or double click on the current selection.

Hmm. At first, when I look at your video, the moment when the breadcrumbs appear is in sync with the highlighting of the tree item in the outline view. Therefore, I still think it is an general issue with the outline view. Second, when I try to reproduce your steps I realized that it does not have to do with a single or double click, it is just a delay. When I open an editor, click once, wait a few seconds and do a second click the breadcrumbs appear immediately (same with the highlighting of the outline tree item). Sometimes it needs more than a few seconds. However, in my tests, it is always in sync with the outline view highlighting.

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

I've started reviewing code, but then stopped after realizing that refactoring to reuse trees is not finished yet.

* Subscribe to this event emitter to be notifed when the breadcrumbs have changed.
* The URI is the URI of the editor the breadcrumbs have changed for.
*/
get onBreadcrumbsChange(): Event<URI> {
Copy link
Member

Choose a reason for hiding this comment

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

onDidChangeBreadcrumbs or onBreadcrumbsChanged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* Notifies that the breadcrumbs for the given URI have changed and should be re-rendered.
* This fires an `onBreadcrumsChange` event.
*/
breadcrumbsChanges(uri: URI): void {
Copy link
Member

Choose a reason for hiding this comment

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

firing events should be an implementation detail, i.e. BreadcrumbsContribution should have onDidChange instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I don't get it. But it sounds that this would make it more complicated without any substantial benefit since the breadcrumbs renderer has to subscribe to all breadcrumb contributions then.

/**
* The breadcrumb type. Breadcrumbs returned by `#computeBreadcrumbs(uri)` should have this as `Breadcrumb#type`.
*/
type: symbol;
Copy link
Member

Choose a reason for hiding this comment

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

readonly ? the same about priority

/**
* Opens a popup for the given breadcrumb at the given position. `parent` is used as the host element for the newly created popup element.
*/
async openPopup(breadcrumb: Breadcrumb, position: { x: number, y: number }, parent: HTMLElement): Promise<BreadcrumbPopup | undefined> {
Copy link
Member

Choose a reason for hiding this comment

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

just open?

import { BreadcrumbPopup } from './breadcrumb-popup';

export const BreadcrumbPopupContainerRenderer = Symbol('BreadcrumbPopupContainerRenderer');
export interface BreadcrumbPopupContainerRenderer {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need interface, symbol and a class? Should not BreadcrumbPopupContainerRenderer be enough? Please see https://github.com/eclipse-theia/theia/wiki/Coding-Guidelines#classes-over-interfaces

This commit adds a breadcrumbs bar to the editor widget. It shows the path to the current file and outline information as breadcrumbs. A click of breadcrumbs allows to jump to other files or to code sections.

Fixes eclipse-theia#5475

Signed-off-by: Cornelius A. Ludmann <cornelius.ludmann@typefox.io>
@corneliusludmann
Copy link
Contributor Author

I updated this PR with the file tree for file breadcrumbs and a '…' breadcrumb for outline breadcrumbs. There are still some minor flaws with the outline breadcrumbs that are in sync with flaws in the outline itself. These need to be fixed in the outline implementation. (E.g. selecting a non-collapsed outline element does not collapse the tree in the outline view and does not set the correct breadcrumb.)

Peek 2019-11-12 12-16

From my point of view, this PR is ready for another review.

@akosyakov
Copy link
Member

@jbicker jbicker mentioned this pull request Dec 9, 2019
77 tasks
@lmcbout
Copy link
Contributor

lmcbout commented Dec 9, 2019

I was looking to get a second review, But there are merge conflicts :(

@akosyakov
Copy link
Member

akosyakov commented Dec 10, 2019

  • Breadcrumb should be contributed to the toolbar of a tab bar group and be updated based on the current widget. It should be enabled for any navigatable widget, at least file parts.

@paulalexwilson
Copy link

I was excited by this PR. Do we plan to merge it at some point or is it no-longer being considered?

@lmcbout
Copy link
Contributor

lmcbout commented Mar 10, 2020

I am interested by this PR as well, but there was some unresolved and merging issues , they are not resolved yet

@corneliusludmann
Copy link
Contributor Author

I could resolve the merge conflicts and rebase the branch. However @akosyakov raised two requests that need to be implemented before merging:

Currently I do not have the time to take care of it. If someone else is willing to contribute to this work feel free to push to this branch or to fork this branch. I'm happy to provide assistance when needed.

@colin-grant-work
Copy link
Contributor

@corneliusludmann, my colleague @kenneth-marut-work and I were thinking of finishing this PR up, unless you were planning on returning to it?

@corneliusludmann
Copy link
Contributor Author

@colin-grant-work, unfortunately, I don't. I would be very happy if you would take over the work on this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor issues related to the editor filesystem issues related to the filesystem outline issues related to the outline
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Breadcrumb to Theia
8 participants