Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mjren23
Copy link
Collaborator

@mjren23 mjren23 commented Oct 11, 2023

  • add styling and logic so that when serverstatehandler updates the path of the current notebook, the notebook is highlighted in the left sidebar (or its containing folder is highlighted, if not expanded)
  • add a button to find the current notebook, expanding folders as necessary. similar to intellij crosshairs button

Screenshot 2023-10-11 at 9 08 50 AM

find-file-demo

closes #1417

* Will only return a nonempty string for n >= 1.
* E.g. if called with "hello/world" where n = 1 and pattern = "/", will return "hello"
*/
export function getUpToNthOccurrence(str: string, n: number, pattern: string): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's different? What I was specifically looking for (and which I didn't make very clear from the comment) is to also return the pattern in the string. Traversing the file tree, I needed to get everything up to a certain slash, so for example, wanting to get the first few folders in a path like root/folder/inner-folder/file.ipynb, we might want root/folder or root/folder/inner-folder.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm missing something. I think this does what you want?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

.....oops, yeah, that does exactly what I want. Will refactor, thank you!

if (!currentState || !isBranch(currentState) || !currentState.children[piece]) {
currentUpdate.fullPath = currentPath;
currentUpdate.value = piece;
currentUpdate.isOrHasCurrentNotebook = currentNotebook === path;
Copy link
Collaborator

Choose a reason for hiding this comment

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

does currentNotebook have to be updated here? I wonder whether it'd be updated anyways after the path is added (doesn't the state update selecting the current notebook happen after the state update adding a new path? Or am I misremembering?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just stepping through in devtools, I'm seeing some instances where branchHandler.addPath gets called after branchHandler.updateCurrentNotebook - not sure where the logic for ordering the state updates lives but it doesn't seem like the behavior is always "add path and then update current notebook."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Under what situation do you see that addPath gets called after updateCurrentNotebook? I wasn't able to reproduce.

The last step of the process to create a new notebook is to select it so I think things should happen in the order I mentioned earlier: https://github.com/polynote/polynote/blob/megan/highlight-current-notebook/polynote-frontend/polynote/messaging/dispatcher.ts#L379

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was able to kind of repro when renaming a notebook, I think. But it's hard to tell because we have a bug with that 😅 #1422

If that's the only way to repro I think we should fix that problem: in general, selecting the current notebook should be the very last thing that happens; and notebook shouldn't be selected before it "exists" if that makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like when reopening the current notebooks (e.g. create a notebook and refresh the page with the notebook still open), the frontend is loading the notebooks and then also getting a message from the server (of type ListNotebooks), triggering another state update and causing addPath to get called again.

@jonathanindig
Copy link
Collaborator

Thanks for the screenshot! Can you show how the "target" button works? (maybe a gif or movie?)

@mjren23
Copy link
Collaborator Author

mjren23 commented Oct 11, 2023

Thanks for the screenshot! Can you show how the "target" button works? (maybe a gif or movie?)

Good call, just added to the original PR description

@jonathanindig
Copy link
Collaborator

Thanks for the screenshot! Can you show how the "target" button works? (maybe a gif or movie?)

Good call, just added to the original PR description

Thanks! I see there's both a gray highlight and a blue highlight. What is the difference between the two? Do we need both?

@mjren23
Copy link
Collaborator Author

mjren23 commented Oct 13, 2023

Thanks for the screenshot! Can you show how the "target" button works? (maybe a gif or movie?)

Good call, just added to the original PR description

Thanks! I see there's both a gray highlight and a blue highlight. What is the difference between the two? Do we need both?

The blue highlight is the focus, which I think should probably be distinct from being highlighted (primarily for the use case of using arrow keys to navigate the file tree)? I was using .focus to scroll to the current notebook upon clicking the crosshairs, but I agree that it's kind of weird. How do you feel about this instead? There's still a brief blue flash when initially selecting the notebook, unfortunately.

find-file-demo-2

@jonathanindig
Copy link
Collaborator

jonathanindig commented Oct 16, 2023

Thanks for the screenshot! Can you show how the "target" button works? (maybe a gif or movie?)

Good call, just added to the original PR description

Thanks! I see there's both a gray highlight and a blue highlight. What is the difference between the two? Do we need both?

The blue highlight is the focus, which I think should probably be distinct from being highlighted (primarily for the use case of using arrow keys to navigate the file tree)? I was using .focus to scroll to the current notebook upon clicking the crosshairs, but I agree that it's kind of weird. How do you feel about this instead? There's still a brief blue flash when initially selecting the notebook, unfortunately.

find-file-demo-2

Huh, I totally forgot we supported using the arrow keys to navigate the file tree 😅

That looks great to me! I even think the blue flash makes sense.

isOrHasCurrentNotebook: false,
children: {}
});
currentNotebookPath = "nonsense.ipynb";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Collaborator

@jonathanindig jonathanindig left a comment

Choose a reason for hiding this comment

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

Hm, I'm still suspicious there's something weird going on with the state updates and handling elsewhere but I think this is fine to merge and we'll untangle that when we come to it.

Thanks and sorry for the delay in reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight/Emphasize the currently selected notebook in the left hand folder panel
2 participants