support single quote for PreviewHtml

This commit is contained in:
lsv 2026-03-04 15:34:39 +05:00
parent 613c392361
commit 9571d4527a
2 changed files with 22 additions and 3 deletions

View file

@ -193,6 +193,23 @@ public:
if (event.GetKeyCode() == WXK_HOME) htmlWindow->ScrollPages(-1000); if (event.GetKeyCode() == WXK_HOME) htmlWindow->ScrollPages(-1000);
if (event.GetKeyCode() == WXK_END) htmlWindow->ScrollPages(1000); if (event.GetKeyCode() == WXK_END) htmlWindow->ScrollPages(1000);
//std::cout << "key code " << event.GetKeyCode() << " " << std::endl; //std::cout << "key code " << event.GetKeyCode() << " " << std::endl;
if (event.GetKeyCode() == 'C') {
if (hist.size()>0 && wxTheClipboard->Open())
{
wxString h=hist[hist.size()-1];
// Добавляем данные (можно добавить несколько форматов, если нужно)
wxDataObjectComposite* dataobj = new wxDataObjectComposite();
dataobj->Add(new wxHTMLDataObject(h));
wxTheClipboard->SetData(dataobj);
wxTheClipboard->Close();
}
else
{
wxLogError("No open clipboard.");
}
}
if (event.GetKeyCode() == 'S') { if (event.GetKeyCode() == 'S') {
wxSize clientSize = this->GetClientSize(); wxSize clientSize = this->GetClientSize();
// Создаём битмап того же размера // Создаём битмап того же размера

View file

@ -117,7 +117,7 @@ wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
int flag = 0; int flag = 0;
tokens.clear(); tokens.clear();
bool quote = false; bool quote = false;
wxUniChar prevchar; wxUniChar prevchar,quotechar;
int startstr = -1; int startstr = -1;
while (pos < len) { while (pos < len) {
c = tmpstr[pos++]; c = tmpstr[pos++];
@ -130,18 +130,20 @@ wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
html+=c; html+=c;
continue; continue;
} }
bool isquote = c == '"'; if (!quote && (c=='"' || c=='\'')) quotechar = c;
bool isquote = c == quotechar;
if (quote) { if (quote) {
if (prevchar == c && isquote) { if (prevchar == c && isquote) {
// repeat quote // repeat quote
prevchar = '\0'; prevchar = '\0';
continue; continue;
} }
if (prevchar == '"' && !isquote) { if (prevchar == quotechar && !isquote) {
// end quote string // end quote string
wxString tmp = tmpstr.Mid(startstr, pos - startstr - 1); wxString tmp = tmpstr.Mid(startstr, pos - startstr - 1);
saveTokenIfNotEmpty(tmp, PREVIEW_QUOTE); saveTokenIfNotEmpty(tmp, PREVIEW_QUOTE);
quote = false; quote = false;
quotechar='\0';
} }
else { else {
prevchar = c; prevchar = c;