-
-
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?
Changes from all commits
202af9c
eda59fb
6d6fd96
a24adc8
875b1b2
2d4ff2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import java.net.MalformedURLException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import javafx.beans.InvalidationListener; | ||
import javafx.beans.Observable; | ||
|
@@ -52,7 +53,6 @@ | |
public class PreviewViewer extends ScrollPane implements InvalidationListener { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PreviewViewer.class); | ||
|
||
// https://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div/5670825#5670825 | ||
private static final String JS_GET_SELECTION_HTML_SCRIPT = """ | ||
function getSelectionHtml() { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Does one really need an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looked more into it and its not required. using normal bool now |
||
|
||
public PreviewViewer(DialogService dialogService, | ||
GuiPreferences preferences, | ||
|
@@ -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 commentThe 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). |
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
LOGGER.debug("Preview Height {}", actualHeight); | ||
previewView.setMaxHeight(actualHeight + 10); | ||
previewView.setPrefHeight(actualHeight + 10); | ||
} | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Please comment why you need There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) |
||
double actualWidth = (widthVal).doubleValue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
double updatedWidth = actualWidth + 350; | ||
|
||
LOGGER.debug("Preview Width {}", actualWidth); | ||
previewView.setPrefWidth(Math.min(updatedWidth, 500)); | ||
widthSet.set(true); | ||
} | ||
|
||
// https://stackoverflow.com/questions/15555510/javafx-stop-opening-url-in-webview-open-in-browser-instead | ||
NodeList anchorList = previewView.getEngine().getDocument().getElementsByTagName("a"); | ||
for (int i = 0; i < anchorList.getLength(); i++) { | ||
|
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!