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

Entry preview lose formating if search field is used #5069

Open
buhtzz opened this issue Jun 20, 2019 · 8 comments
Open

Entry preview lose formating if search field is used #5069

buhtzz opened this issue Jun 20, 2019 · 8 comments · data-hydro-click="{"event_type":"issue_cross_references.click","payload":{"reference_location":"ISSUE_HEADER","user_id":null,"issue_id":458695409,"pull_request_id":329444375,"originating_url":"https://github.com/JabRef/jabref/issues/5069"}}" data-hydro-click-hmac="ea49006810392e12b09f4ae6fa029ec2398e34539ad0b1a87b34a7bd203b20c6" data-hovercard-type="pull_request" data-hovercard-url="/JabRef/jabref/pull/5472/hovercard">#5472
Labels
entry-preview search type: bug 🐛 Confirmed bugs or reports that are very likely to be bugs
Projects
Milestone

Comments

@buhtzz
Copy link

buhtzz commented Jun 20, 2019

Tried with current 5.* dev on Windows 10.

Entry preview looks nice.
snapshot

But when I use the search field e.g. keywords=lesen or author=nord then it looks like this.
copy-paste

@Siedlerchr
Copy link
Member

Siedlerchr commented Jun 20, 2019

Issues is from the search highlighting of the search term. When you stop searching it's back to normal

@Siedlerchr Siedlerchr added type: bug 🐛 Confirmed bugs or reports that are very likely to be bugs search entry-preview labels Jul 6, 2019
@Siedlerchr Siedlerchr added this to Needs triage in Bugs via automation Jul 6, 2019
@Siedlerchr
Copy link
Member

Siedlerchr commented Jul 6, 2019

The highlighting is handled by this simple javascript code:

private static final String JS_HIGHLIGHT_FUNCTION = " <script type=\"text/javascript\">\r\n" +
" function highlight(text) {\r\n" +
" var innertxt = document.body.innerText;\r\n" +
" var response = innertxt.replace(new RegExp(text, 'gi'), str => `<span style='background-color:red'>${str}</span>`);\r\n" +
" document.body.innerHTML = response;\r\n" +
" }\r\n" +
" </script>";

@buhtzz
Copy link
Author

buhtzz commented Jul 10, 2019

I know nothing about JS.
What does your last post mean? It is easy to fix or the opposite?

@tobiasdiez tobiasdiez moved this from Needs triage to Normal priority in Bugs Aug 25, 2019
@TomasLukac
Copy link

TomasLukac commented Oct 7, 2019

I have tried if this issue still remains in the master branch and not only does it lose formatting, it also jumps to the Author field automatically, so I am rewriting my Author after search finds a result.
The formatting goes back to normal when I click to other article, not after finishing search, as @Siedlerchr said.

I would like to look at this issue and fix it.

@tobiasdiez
Copy link
Member

tobiasdiez commented Oct 7, 2019

The problem is probably that we read the inner text (i.e everything without formatting) and then set it as the inner html. Should work if document.body.innerText is replaced by document.body.innerHtml

@tobiasdiez tobiasdiez added this to the v5.0 milestone Oct 7, 2019
@Siedlerchr
Copy link
Member

Siedlerchr commented Oct 7, 2019

@tobiasdiez It is not that easy. That's what I did before. The problem is then that it displays and searches matches in html tags

@tobiasdiez
Copy link
Member

tobiasdiez commented Oct 17, 2019

This should be fixed in the latest development version. Could you please check the build from http://builds.jabref.org/master/. Thanks! Please remember to make a backup of your library before trying-out this version.

@buhtzz
Copy link
Author

buhtzz commented Oct 19, 2019

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

Successfully merging a pull request may close this issue.

4 participants