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

Use Markdown in AI Summary tab implemented #12266

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

mulla028
Copy link
Contributor

@mulla028 mulla028 commented Dec 5, 2024

Closes #12233

Description (UPDATED)

As it was pre-requested, I've implemented an option when user is able, using checkbox, to change the formation of the AI Summary. If user checks it, WebView with formatted into html markdown appears, otherwise text stays raw. It is pretty useful new feature that makes AI Summary user-friendly for those, who loves to see formatted text, instead of raw markdown that besides the text contains "weird", in user's opinion characters.

How Code Changed and Why?

  1. In the issue discussion, I asked questions, and maintainers came up with an idea that we need a simple toggle, so I decided to add into org/jabref/gui/ai/components/summary/SummaryShowingComponent.fxml a CheckBox that appears one the left below the AI Summary
  2. This toggle handled in org/jabref/gui/ai/components/summary/SummaryShowingComponent.javafile's method onMarkdownToggle(). Once user checks the CheckBox the TextArea disappears, and WebView come us.
  3. TextArea was wrapped in StackPane to simplify managing and layering of that component.
  4. WebView programmatically implemented (lazy initialization) to avoid findMissingLocalizationKeys and findObsoleteLocalizationKeys tests failure.
  5. To formate raw text into markdown I used org/jabref/logic/layout/format/MarkdownFormatter.java that has been already implemented.

How to Copy Formatted Content?

Press anywhere in WebView component press ctrl + a/cmd + a then ctrl + c/cmd + c, and paste it in the desired place ^_^

Screenshots

  • Markdown CheckBox checked:
image
  • Markdown CheckBox unchecked:
image

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

@calixtus
Copy link
Member

calixtus commented Dec 6, 2024

Well, right now the checkbox looks quite ugly. Please place it somewhere else...

@calixtus
Copy link
Member

calixtus commented Dec 6, 2024

It's not good style to mix fxmls and hard coded creation of ui elements except in some edge cases. Please place both the text area and the Web view in a StackPane.

@mulla028
Copy link
Contributor Author

mulla028 commented Dec 6, 2024

It's not good style to mix fxmls and hard coded creation of ui elements except in some edge cases. Please place both the text area and the Web view in a StackPane.

I tried not to mix them, but I came up with hard coded WebView, otherwise it wasn't passing unit tests

@subhramit
Copy link
Member

I tried not to mix them, but I came up with hard coded WebView, otherwise it wasn't passing unit tests

Which unit tests?

@mulla028
Copy link
Contributor Author

mulla028 commented Dec 7, 2024

I tried not to mix them, but I came up with hard coded WebView, otherwise it wasn't passing unit tests

Which unit tests?

In LocalizationConsistencyTest two tests didn't pass using WebView via .fxml: findObsoleteLocalizationKeys() and findMissingLocalizationKeys(). However, adding WebView to the UI programmatically, all tests pass.

@subhramit
Copy link
Member

subhramit commented Dec 7, 2024

In LocalizationConsistencyTest two tests didn't pass using WebView via .fxml: findObsoleteLocalizationKeys() and findMissingLocalizationKeys(). However, adding WebView to the UI programmatically, all tests pass.

Revert it, let us take a look. We'll help you with the tests.

@mulla028
Copy link
Contributor Author

mulla028 commented Dec 7, 2024

@subhramit just reverted it, you will witness that 2 unit-tests are not going to pass

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

I have requested a few changes.

For the failing localization tests, go through:
https://devdocs.jabref.org/code-howtos/faq.html#orgjabreflogicl10nlocalizationconsistencytest-findmissinglocalizationkeys-failed and the one below it.

Please also avoid force-pushing your changes.

@subhramit subhramit requested a review from koppor December 7, 2024 19:04
@calixtus
Copy link
Member

calixtus commented Dec 7, 2024

I thought about it a bit. It is actually not the worst idea to lazy load the WebView for performance reasons. Please place the TextArea inside a StackPane and add the WebView on demand. That way all the managed and visible stuff can be avoided.

@calixtus
Copy link
Member

calixtus commented Dec 7, 2024

And please move.the checkbox somewhere else.

@mulla028
Copy link
Contributor Author

mulla028 commented Dec 7, 2024

And please move.the checkbox somewhere else.

Before I forced push, the previous commit had the changed position of CheckBox

@koppor
Copy link
Member

koppor commented Dec 8, 2024

And please move.the checkbox somewhere else.

Before I forced push, the previous commit had the changed position of CheckBox

Therefore, no force push.

Either try to resurrect the commit with "git reflog" or try to re-do it.

@mulla028
Copy link
Contributor Author

mulla028 commented Dec 9, 2024

@koppor
Reset commit. Sorry for doing it, I can see how it's driven everyone crazy 😆

@mulla028
Copy link
Contributor Author

mulla028 commented Dec 9, 2024

@calixtus
Now, I think it looks way better. CheckBox doesn't seam that ugly(check updated description). May be you have any suggestions on it?

Copy link
Collaborator

@InAnYan InAnYan left a comment

Choose a reason for hiding this comment

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

Great! Summary looks so much nicer now!

I was thinking: what if we could get rid of TextArea whatsoever?

Can you implement only one WebView that would have different HTMLs: one in plain mode, and other is rendered Markdown? This would greatly simplify the logic.

I also noticed 3 small problems:

image

  • Text is not wrapped.
  • WebView does not shrink.
  • Text is not styled with JabRef's main font. Can you look at how it's implemented in entry preview? The default font is Sans, but the summary in WebView is Serif.

@mulla028 mulla028 requested a review from InAnYan December 9, 2024 23:09
@mulla028
Copy link
Contributor Author

mulla028 commented Dec 9, 2024

@InAnYan
I don't know how to make a plain text shrink there. However, Markdown is getting shrink well!

Copy link
Collaborator

@InAnYan InAnYan left a comment

Choose a reason for hiding this comment

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

Good, you used WebView for both plain-text mode and rendered Markdown, looks better (however, there is a slight remain of TextArea 😄). Overall, I see these problems:

  • It doesn't wrap text in plain text mode. That's strange, because in rendered Markdown mode there is some wrapping (maybe, because of the <pre> tag?)
  • In rendered Markdown mode, it wraps the text, but only if the width is bigger than some limit. What I mean is: wrapping doesn't work for all possible width changes. Maybe that's a JavaFX problem, or you need to know a lot of JavaFX internals to solve this problems. If you couldn't find the issue and fix it, it's okay to skip it. (But don't forget about wrapping in plain-text mode).

image

  • Fonts are not handled properly.

@mulla028 mulla028 requested a review from InAnYan December 10, 2024 18:17
@mulla028
Copy link
Contributor Author

@koppor @subhramit @calixtus
How do you like it now ?

@mulla028
Copy link
Contributor Author

@InAnYan
Talking about the text wrapper, and it's limit. I think this is JavaFX issue. Unfortunately, it has nothing to do with my changes.

@@ -49,6 +49,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- By double clicking on a local citation in the Citation Relations Tab you can now jump the linked entry. [#11955](https://github.com/JabRef/jabref/pull/11955)
- We use the menu icon for background tasks as a progress indicator to visualise an import's progress when dragging and dropping several PDF files into the main table. [#12072](https://github.com/JabRef/jabref/pull/12072)
- The PDF content importer now supports importing title from upto the second page of the PDF. [#12139](https://github.com/JabRef/jabref/issues/12139)
- We added support of `Markdown` in `AI Summary` tab by using the `CheckBox` next to `Regenerate` button. [#12266](https://github.com/JabRef/jabref/pull/12266)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As AI features are not currently released, we don't put them in CHANGLELOG.md

contentWebView = WebViewStore.get();
VBox.setVgrow(contentWebView, Priority.ALWAYS);

themeManager.installCss(contentWebView.getEngine());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately, this doesn't work..

@calixtus, @koppor is there any way for browser to use JabRef's style? Font family and size specifically? Or should we leave the default font in WebView (I guess it's some Serif)?

@InAnYan
Copy link
Collaborator

InAnYan commented Dec 14, 2024

Overall, I think this PR is ready to be merged, just an annoying problem with Fonts

Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Just one more comment from my side.

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.

Use Markdown in AI Summary tab
5 participants