mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
LivePreview: smart live preview for online PlantUML
This commit is contained in:
parent
62c0f218df
commit
3b2852aa67
@ -1625,6 +1625,10 @@ var htmlToText = function(identifier, id, timeStamp, html) {
|
|||||||
content.htmlToTextCB(identifier, id, timeStamp, markdown);
|
content.htmlToTextCB(identifier, id, timeStamp, markdown);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var printRect = function(rect) {
|
||||||
|
content.setLog('rect ' + rect.left + ' ' + rect.top + ' ' + rect.width + ' ' + rect.height);
|
||||||
|
};
|
||||||
|
|
||||||
var performSmartLivePreview = function(lang, text, hints, isRegex) {
|
var performSmartLivePreview = function(lang, text, hints, isRegex) {
|
||||||
if (previewDiv.style.display == 'none'
|
if (previewDiv.style.display == 'none'
|
||||||
|| document.getSelection().type == 'Range') {
|
|| document.getSelection().type == 'Range') {
|
||||||
@ -1635,11 +1639,25 @@ var performSmartLivePreview = function(lang, text, hints, isRegex) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var previewNode = previewDiv;
|
||||||
|
var trectOffset = null;
|
||||||
|
try {
|
||||||
|
var objs = previewNode.getElementsByTagName('object');
|
||||||
|
if (objs.length > 0) {
|
||||||
|
var obj = objs[0];
|
||||||
|
previewNode = obj.contentDocument.children[0];
|
||||||
|
trectOffset = obj.getBoundingClientRect();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
content.setLog("err: " + err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// PlantUML.
|
// PlantUML.
|
||||||
var targetNode = null;
|
var targetNode = null;
|
||||||
if (hints.indexOf('id') >= 0) {
|
if (hints.indexOf('id') >= 0) {
|
||||||
// isRegex is ignored.
|
// isRegex is ignored.
|
||||||
var result = findNodeWithText(previewDiv,
|
var result = findNodeWithText(previewNode,
|
||||||
text,
|
text,
|
||||||
function (node, text) {
|
function (node, text) {
|
||||||
if (node.id && node.id == text) {
|
if (node.id && node.id == text) {
|
||||||
@ -1660,7 +1678,7 @@ var performSmartLivePreview = function(lang, text, hints, isRegex) {
|
|||||||
var result;
|
var result;
|
||||||
if (isRegex) {
|
if (isRegex) {
|
||||||
var nodeReg = new RegExp(text);
|
var nodeReg = new RegExp(text);
|
||||||
result = findNodeWithText(previewDiv,
|
result = findNodeWithText(previewNode,
|
||||||
text,
|
text,
|
||||||
function(node, text) {
|
function(node, text) {
|
||||||
var se = nodeReg.exec(node.textContent);
|
var se = nodeReg.exec(node.textContent);
|
||||||
@ -1677,7 +1695,7 @@ var performSmartLivePreview = function(lang, text, hints, isRegex) {
|
|||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
result = findNodeWithText(previewDiv,
|
result = findNodeWithText(previewNode,
|
||||||
text,
|
text,
|
||||||
function(node, text) {
|
function(node, text) {
|
||||||
var idx = node.textContent.indexOf(text);
|
var idx = node.textContent.indexOf(text);
|
||||||
@ -1704,7 +1722,13 @@ var performSmartLivePreview = function(lang, text, hints, isRegex) {
|
|||||||
|
|
||||||
// (left, top) is relative to the viewport.
|
// (left, top) is relative to the viewport.
|
||||||
// Should add window.scrollX and window.scrollY to get the real content offset.
|
// Should add window.scrollX and window.scrollY to get the real content offset.
|
||||||
var trect = targetNode.getBoundingClientRect();
|
var tbrect = targetNode.getBoundingClientRect();
|
||||||
|
var trect = {
|
||||||
|
left: tbrect.left + (trectOffset ? trectOffset.left : 0),
|
||||||
|
top: tbrect.top + (trectOffset ? trectOffset.top : 0),
|
||||||
|
width: tbrect.width,
|
||||||
|
height: tbrect.height
|
||||||
|
};
|
||||||
|
|
||||||
var vrect = {
|
var vrect = {
|
||||||
left: document.documentElement.scrollLeft || document.body.scrollLeft || window.pageXOffset,
|
left: document.documentElement.scrollLeft || document.body.scrollLeft || window.pageXOffset,
|
||||||
|
@ -540,11 +540,11 @@ void VLivePreviewHelper::performSmartLivePreview()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const CodeBlockPreviewInfo &cb = m_codeBlocks[m_cbIndex];
|
const CodeBlockPreviewInfo &cb = m_codeBlocks[m_cbIndex];
|
||||||
if (!cb.hasImageData()) {
|
const VCodeBlock &vcb = cb.codeBlock();
|
||||||
|
if (!cb.hasImageData() && !isOnlineLivePreview(vcb.m_lang)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VCodeBlock &vcb = cb.codeBlock();
|
|
||||||
const QTextBlock block = m_editor->textCursorW().block();
|
const QTextBlock block = m_editor->textCursorW().block();
|
||||||
if (block.blockNumber() <= vcb.m_startBlock
|
if (block.blockNumber() <= vcb.m_startBlock
|
||||||
|| block.blockNumber() >= vcb.m_endBlock) {
|
|| block.blockNumber() >= vcb.m_endBlock) {
|
||||||
@ -553,7 +553,7 @@ void VLivePreviewHelper::performSmartLivePreview()
|
|||||||
|
|
||||||
QString keyword, hints;
|
QString keyword, hints;
|
||||||
bool isRegex = false;
|
bool isRegex = false;
|
||||||
if (vcb.m_lang == "puml" && m_plantUMLMode == PlantUMLMode::LocalPlantUML) {
|
if (vcb.m_lang == "puml") {
|
||||||
keyword = VPlantUMLHelper::keywordForSmartLivePreview(block.text(),
|
keyword = VPlantUMLHelper::keywordForSmartLivePreview(block.text(),
|
||||||
hints,
|
hints,
|
||||||
isRegex);
|
isRegex);
|
||||||
@ -561,3 +561,13 @@ void VLivePreviewHelper::performSmartLivePreview()
|
|||||||
|
|
||||||
m_document->performSmartLivePreview(vcb.m_lang, keyword, hints, isRegex);
|
m_document->performSmartLivePreview(vcb.m_lang, keyword, hints, isRegex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VLivePreviewHelper::isOnlineLivePreview(const QString &p_lang) const
|
||||||
|
{
|
||||||
|
if (p_lang == "dot"
|
||||||
|
|| (p_lang == "puml" && m_plantUMLMode == PlantUMLMode::LocalPlantUML)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -266,6 +266,8 @@ private:
|
|||||||
|
|
||||||
void performSmartLivePreview();
|
void performSmartLivePreview();
|
||||||
|
|
||||||
|
bool isOnlineLivePreview(const QString &p_lang) const;
|
||||||
|
|
||||||
// Sorted by m_startBlock in ascending order.
|
// Sorted by m_startBlock in ascending order.
|
||||||
QVector<CodeBlockPreviewInfo> m_codeBlocks;
|
QVector<CodeBlockPreviewInfo> m_codeBlocks;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user