Show highlighted text in right panel

This commit is contained in:
SiriusXT 2023-06-03 14:43:20 +08:00
parent 463d145cb7
commit 33fdad5159
2 changed files with 18 additions and 11 deletions

View File

@ -28,6 +28,8 @@ const TPL = `<div class="highlighted-text-widget">
margin-bottom: 3px; margin-bottom: 3px;
text-align: justify; text-align: justify;
text-justify: distribute; text-justify: distribute;
word-wrap: break-word;
hyphens: auto;
} }
.highlighted-text li:hover { .highlighted-text li:hover {
@ -149,26 +151,27 @@ export default class HighlightTextWidget extends RightPanelWidget {
findSubStr = findSubStr.substring(1) findSubStr = findSubStr.substring(1)
combinedRegexStr = `(` + combinedRegexStr.substring(1) + `)`; combinedRegexStr = `(` + combinedRegexStr.substring(1) + `)`;
const combinedRegex = new RegExp(combinedRegexStr, 'gi'); const combinedRegex = new RegExp(combinedRegexStr, 'gi');
var $hlt = $("<ol>"); let $hlt = $("<ol>");
var hltLiCount = 0; let prevEndIndex = -1, hltLiCount = 0;
let prevEndIndex = -1;
for (let match = null, hltIndex=0; ((match = combinedRegex.exec(html)) !== null); hltIndex++) { for (let match = null, hltIndex=0; ((match = combinedRegex.exec(html)) !== null); hltIndex++) {
var subHtml = match[0]; var subHtml = match[0];
const startIndex = match.index; const startIndex = match.index;
const endIndex = combinedRegex.lastIndex; const endIndex = combinedRegex.lastIndex;
hltLiCount++;
if (prevEndIndex != -1 && startIndex === prevEndIndex) { if (prevEndIndex != -1 && startIndex === prevEndIndex) {
$hlt.children().last().append(subHtml); $hlt.children().last().append(subHtml);
} else { } else {
if ([...subHtml.matchAll(/(?<=^|>)[^><]+?(?=<|$)/g)].map(matchTmp => matchTmp[0]).join('').trim() != ""){
var $li = $('<li>'); var $li = $('<li>');
$li.html(subHtml); $li.html(subHtml);
if ($li.text().trim() == "") { $li.css("display", "none"); }
$li.on("click", () => this.jumpToHlt(findSubStr,hltIndex)); $li.on("click", () => this.jumpToHlt(findSubStr,hltIndex));
$hlt.append($li); $hlt.append($li);
hltLiCount++;
}else{
continue
}
} }
prevEndIndex = endIndex; prevEndIndex = endIndex;
} }
return { return {
$hlt, $hlt,
hltLiCount hltLiCount

View File

@ -38,6 +38,10 @@ const TPL = `<div class="toc-widget">
.toc li { .toc li {
cursor: pointer; cursor: pointer;
text-align: justify;
text-justify: distribute;
word-wrap: break-word;
hyphens: auto;
} }
.toc li:hover { .toc li:hover {