<commit_before>#include "noteeditorlogic.h"
#include "customDocument.h"
#include "markdownhighlighter.h"
#include "dbmanager.h"
#include "taglistview.h"
#include "taglistmodel.h"
#include "tagpool.h"
#include "taglistdelegate.h"
#include <QScrollBar>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QDebug>
#include <QCursor>

#define FIRST_LINE_MAX 80


NoteEditorLogic::NoteEditorLogic(CustomDocument *textEdit,
                                 QLabel* editorDateLabel,
                                 QLineEdit* searchEdit,
                                 TagListView *tagListView, TagPool *tagPool,
                                 DBManager *dbManager,
                                 QObject *parent) : QObject(parent),
    m_textEdit{textEdit},
    m_editorDateLabel{editorDateLabel},
    m_searchEdit{searchEdit},
    m_tagListView{tagListView},
    m_dbManager{dbManager},
    m_isContentModified{false},
    m_spacerColor{26, 26, 26}
{
    m_highlighter = new MarkdownHighlighter(m_textEdit->document());
    connect(m_textEdit, &QTextEdit::textChanged, this, &NoteEditorLogic::onTextEditTextChanged);
    connect(m_textEdit, &CustomDocument::resized, this, &NoteEditorLogic::editorResized);
    connect(this, &NoteEditorLogic::requestCreateUpdateNote,
            m_dbManager, &DBManager::onCreateUpdateRequestedNoteContent, Qt::QueuedConnection);
    // auto save timer
    m_autoSaveTimer.setSingleShot(true);
    m_autoSaveTimer.setInterval(50);
    connect(&m_autoSaveTimer, &QTimer::timeout, this, [this]() {
        saveNoteToDB();
    });
    m_tagListModel = new TagListModel{this};
    m_tagListModel->setTagPool(tagPool);
    m_tagListView->setModel(m_tagListModel);
    m_tagListDelegate = new TagListDelegate{this};
    m_tagListView->setItemDelegate(m_tagListDelegate);
    connect(tagPool, &TagPool::dataUpdated, this, [this] (int) {
        showTagListForCurrentNote();
    });
}

bool NoteEditorLogic::markdownEnabled() const
{
    return m_highlighter == nullptr;
}

void NoteEditorLogic::setMarkdownEnabled(bool newMarkdownEnabled)
{
    if (markdownEnabled()) {
        delete m_highlighter;
        m_highlighter = nullptr;
    }
    if (newMarkdownEnabled) {
        m_highlighter = new MarkdownHighlighter(m_textEdit->document());
    } else {
        delete m_highlighter;
        m_highlighter = nullptr;
    }
}

void NoteEditorLogic::showNotesInEditor(const QVector<NodeData> &notes)
{
    if (notes.size() == 1 && notes[0].id() != SpecialNodeID::InvalidNodeId ) {
        auto currentId = currentEditingNoteId();
        if (currentId != SpecialNodeID::InvalidNodeId && notes[0].id() != currentId) {
            emit noteEditClosed(m_currentNotes[0]);
        }
        m_textEdit->blockSignals(true);
        m_textEdit->setVisible(true);
        m_currentNotes = notes;
        showTagListForCurrentNote();
        //     fixing bug #202
        m_textEdit->setTextBackgroundColor(QColor(247,247,247, 0));

        QString content = notes[0].content();
        QDateTime dateTime = notes[0].lastModificationdateTime();
        int scrollbarPos = notes[0].scrollBarPosition();

        // set text and date
        m_textEdit->setText(content);
        QString noteDate = dateTime.toString(Qt::ISODate);
        QString noteDateEditor = getNoteDateEditor(noteDate);
        m_editorDateLabel->setText(noteDateEditor);
        // set scrollbar position
        m_textEdit->verticalScrollBar()->setValue(scrollbarPos);
        m_textEdit->blockSignals(false);
        m_textEdit->setReadOnly(false);
        m_textEdit->setTextInteractionFlags(Qt::TextEditorInteraction);
        m_textEdit->setFocusPolicy(Qt::StrongFocus);
        highlightSearch();
    } else if (notes.size() > 1) {
        m_currentNotes = notes;
        m_tagListView->setVisible(false);
        m_textEdit->blockSignals(true);
        m_textEdit->clear();
        QPixmap sep(QSize{m_textEdit->width(), 19});
        sep.fill(Qt::transparent);
        QPainter painter(&sep);
        painter.setPen(m_spacerColor);
        painter.drawLine(0, 10, sep.width() - 100, 10);
        m_textEdit->document()->addResource(QTextDocument::ImageResource,
                                            QUrl("mydata://sep.png"),
                                            sep);
        for (int i = 0; i < notes.size(); ++i) {
            auto cursor = m_textEdit->textCursor();
            cursor.movePosition(QTextCursor::End);
            if (!notes[i].content().endsWith("\n")) {<commit_msg>fix note edit separator<commit_after>#include "noteeditorlogic.h"
#include "customDocument.h"
#include "markdownhighlighter.h"
#include "dbmanager.h"
#include "taglistview.h"
#include "taglistmodel.h"
#include "tagpool.h"
#include "taglistdelegate.h"
#include <QScrollBar>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QDebug>
#include <QCursor>

#define FIRST_LINE_MAX 80


NoteEditorLogic::NoteEditorLogic(CustomDocument *textEdit,
                                 QLabel* editorDateLabel,
                                 QLineEdit* searchEdit,
                                 TagListView *tagListView, TagPool *tagPool,
                                 DBManager *dbManager,
                                 QObject *parent) : QObject(parent),
    m_textEdit{textEdit},
    m_editorDateLabel{editorDateLabel},
    m_searchEdit{searchEdit},
    m_tagListView{tagListView},
    m_dbManager{dbManager},
    m_isContentModified{false},
    m_spacerColor{26, 26, 26}
{
    m_highlighter = new MarkdownHighlighter(m_textEdit->document());
    connect(m_textEdit, &QTextEdit::textChanged, this, &NoteEditorLogic::onTextEditTextChanged);
    connect(m_textEdit, &CustomDocument::resized, this, &NoteEditorLogic::editorResized);
    connect(this, &NoteEditorLogic::requestCreateUpdateNote,
            m_dbManager, &DBManager::onCreateUpdateRequestedNoteContent, Qt::QueuedConnection);
    // auto save timer
    m_autoSaveTimer.setSingleShot(true);
    m_autoSaveTimer.setInterval(50);
    connect(&m_autoSaveTimer, &QTimer::timeout, this, [this]() {
        saveNoteToDB();
    });
    m_tagListModel = new TagListModel{this};
    m_tagListModel->setTagPool(tagPool);
    m_tagListView->setModel(m_tagListModel);
    m_tagListDelegate = new TagListDelegate{this};
    m_tagListView->setItemDelegate(m_tagListDelegate);
    connect(tagPool, &TagPool::dataUpdated, this, [this] (int) {
        showTagListForCurrentNote();
    });
}

bool NoteEditorLogic::markdownEnabled() const
{
    return m_highlighter == nullptr;
}

void NoteEditorLogic::setMarkdownEnabled(bool newMarkdownEnabled)
{
    if (markdownEnabled()) {
        delete m_highlighter;
        m_highlighter = nullptr;
    }
    if (newMarkdownEnabled) {
        m_highlighter = new MarkdownHighlighter(m_textEdit->document());
    } else {
        delete m_highlighter;
        m_highlighter = nullptr;
    }
}

void NoteEditorLogic::showNotesInEditor(const QVector<NodeData> &notes)
{
    if (notes.size() == 1 && notes[0].id() != SpecialNodeID::InvalidNodeId ) {
        auto currentId = currentEditingNoteId();
        if (currentId != SpecialNodeID::InvalidNodeId && notes[0].id() != currentId) {
            emit noteEditClosed(m_currentNotes[0]);
        }
        m_textEdit->blockSignals(true);
        m_textEdit->setVisible(true);
        m_currentNotes = notes;
        showTagListForCurrentNote();
        //     fixing bug #202
        m_textEdit->setTextBackgroundColor(QColor(247,247,247, 0));

        QString content = notes[0].content();
        QDateTime dateTime = notes[0].lastModificationdateTime();
        int scrollbarPos = notes[0].scrollBarPosition();

        // set text and date
        m_textEdit->setText(content);
        QString noteDate = dateTime.toString(Qt::ISODate);
        QString noteDateEditor = getNoteDateEditor(noteDate);
        m_editorDateLabel->setText(noteDateEditor);
        // set scrollbar position
        m_textEdit->verticalScrollBar()->setValue(scrollbarPos);
        m_textEdit->blockSignals(false);
        m_textEdit->setReadOnly(false);
        m_textEdit->setTextInteractionFlags(Qt::TextEditorInteraction);
        m_textEdit->setFocusPolicy(Qt::StrongFocus);
        highlightSearch();
    } else if (notes.size() > 1) {
        m_currentNotes = notes;
        m_tagListView->setVisible(false);
        m_textEdit->blockSignals(true);
        m_textEdit->clear();
        QPixmap sep(QSize{m_textEdit->width() - 100, 19});
        sep.fill(Qt::transparent);
        QPainter painter(&sep);
        painter.setPen(m_spacerColor);
        painter.drawLine(0, 10, sep.width(), 10);
        m_textEdit->document()->addResource(QTextDocument::ImageResource,
                                            QUrl("mydata://sep.png"),
                                            sep);
        for (int i = 0; i < notes.size(); ++i) {
            auto cursor = m_textEdit->textCursor();
            cursor.movePosition(QTextCursor::End);
            if (!notes[i].content().endsWith("\n")) {
{'fraction_non_alphanumeric': 0.11933701657458563, 'fraction_numerical': 0.009281767955801105, 'mean_word_length': 3.0370205173951828, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2191740', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2693, 'n_words': 437}