-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Area of preview on hover should be shrink to the size of the text displayed #13555
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xIshanSandhux Ever tried this?
There should not be any horizontal scroll bar

Could be wider

White area should not be shown

Applied the suggestion, but i did try this before, and i was getting the same result so.. currently the issue is that with each hover the width keeps changing so I am trying to figure out why and where is that happening. |
fixing height to not have scroll bar
@@ -125,6 +125,16 @@ private void configurePreviewView(ThemeManager themeManager) { | |||
return; | |||
} | |||
|
|||
if (previewView.getEngine().executeScript("document.getElementById('content').scrollHeight") instanceof java.lang.Number heightVal) { | |||
double actualHeight = (heightVal).doubleValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
if (previewView.getEngine().executeScript("document.getElementById('content').scrollWidth") instanceof java.lang.Number widthVal) { | ||
double actualWidth = (widthVal).doubleValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@trag-bot didn't find any issues in the code! ✅✨ |
Your code currently does not meet JabRef's code guidelines. We use OpenRewrite to ensure "modern" Java coding practices. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Tests / OpenRewrite (pull_request)" and click on it. The issues found can be automatically fixed. Please execute the gradle task |
@koppor could you please check it out and let me know if it works now. This is what I am getting now. I have tested using the entries provided in the example library. ![]() If it works, I will update the PR so that its compliant Jabref's code guidelines and will update the status to "ready for review". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
previewView.getEngine().executeScript("document.body.style.overflow='hidden';"); | ||
|
||
if (previewView.getEngine().executeScript("document.getElementById('content').scrollWidth") instanceof java.lang.Number widthVal && !widthSet.get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment why you need widthSet
and not heightSet
@@ -87,6 +87,7 @@ function getSelectionHtml() { | |||
private @Nullable BibEntry entry; | |||
private PreviewLayout layout; | |||
private String layoutText; | |||
private final AtomicBoolean widthSet = new AtomicBoolean(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does one really need an AtomicBoolean
here? If the method is executed concurrently multiple times, there is a bigger flaw in the architecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looked more into it and its not required. using normal bool now
@@ -52,7 +53,6 @@ | |||
public class PreviewViewer extends ScrollPane implements InvalidationListener { | |||
|
|||
private static final Logger LOGGER = LoggerFactory.getLogger(PreviewViewer.class); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the empty line as the thing which follow these multiple lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
@trag-bot didn't find any issues in the code! ✅✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bug is present, and some alternative approaches should be encouraged. I am pretty sure the EntryEditor's preview also got introduced a bug as a results of this since, if you first preview a very small entry then go to a big one, this new implementation will unnaturally fold the preview (as it always records the first width of the first entry viewed as the width of all subsequent preview).
@@ -125,6 +126,25 @@ private void configurePreviewView(ThemeManager themeManager) { | |||
return; | |||
} | |||
|
|||
previewView.getEngine().executeScript("document.body.offsetHeight;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we looking at this? If the purpose is to force the webview layout the element, write out such intent (and say maybe there is a case that such forcing is necessary).
} | ||
previewView.getEngine().executeScript("document.body.style.overflow='hidden';"); | ||
|
||
if (previewView.getEngine().executeScript("document.getElementById('content').scrollWidth") instanceof java.lang.Number widthVal && !widthSet.get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that Previewer is only created once in the Tooltip and here after, the same instance of the Previewer is created. In that case, we are just being arbitrary to say, however wide the first entry it is, let's just it's width. And granted, what you are facing right now is basically impossible. You cannot possibly get the scroll height of an element without knowing/first confining to some set width.
With that, I felt maybe you could hardcode some width value for the MainTableToolTip use case rather than create the appearance of respecting element's natural width. Or, to handle cases with tooltip element that's actually just less than the predetermined width, maybe a bit of JS is needed, instead of Java :)
Closes #12351
The issue was basically the box height was not getting set based on the contents of the entry. The default height was always being used.
So currently I have updated the PreivewViewer.java file to get the current height based on the content of the entry. Initially I did not add any extra padding but then the last bit of the content was getting cut off. So as of now i have added extra 10 and it gives me the last bit content properly and lil extra room. I can reduce that if you want.
I have fixed 70% of the issue.
However still on the first render the old tooltip box height and width is being displayed but after that I am getting the correct box height and width based on the text. So after figuring out how to fix that I will change the status of the PR to "ready for review".
Current look with extra 10 padding (both height and width:
Steps to test
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)