mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Editor: support highlighting tabs
This commit is contained in:
parent
f9820cf709
commit
68dc2425a9
@ -289,6 +289,9 @@ enable_smart_im_in_vim_mode=true
|
|||||||
; Should be one character long
|
; Should be one character long
|
||||||
vim_leader_key=" "
|
vim_leader_key=" "
|
||||||
|
|
||||||
|
; Enable tab highlight
|
||||||
|
enable_tab_highlight=false
|
||||||
|
|
||||||
[export]
|
[export]
|
||||||
; Path of the wkhtmltopdf tool
|
; Path of the wkhtmltopdf tool
|
||||||
wkhtmltopdf=wkhtmltopdf
|
wkhtmltopdf=wkhtmltopdf
|
||||||
|
@ -353,6 +353,10 @@ void VConfigManager::initEditorConfigs()
|
|||||||
m_vimLeaderKey = QChar(' ');
|
m_vimLeaderKey = QChar(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_enableTabHighlight = getConfigFromSettings("editor",
|
||||||
|
"enable_tab_highlight").toBool();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::initSettings()
|
void VConfigManager::initSettings()
|
||||||
|
@ -314,6 +314,9 @@ public:
|
|||||||
bool getEnableTrailingSpaceHighlight() const;
|
bool getEnableTrailingSpaceHighlight() const;
|
||||||
void setEnableTrailingSapceHighlight(bool p_enabled);
|
void setEnableTrailingSapceHighlight(bool p_enabled);
|
||||||
|
|
||||||
|
bool getEnableTabHighlight() const;
|
||||||
|
void setEnableTabHighlight(bool p_enabled);
|
||||||
|
|
||||||
KeyMode getKeyMode() const;
|
KeyMode getKeyMode() const;
|
||||||
void setKeyMode(KeyMode p_mode);
|
void setKeyMode(KeyMode p_mode);
|
||||||
|
|
||||||
@ -804,6 +807,9 @@ private:
|
|||||||
// Enable trailing-space highlight.
|
// Enable trailing-space highlight.
|
||||||
bool m_enableTrailingSpaceHighlight;
|
bool m_enableTrailingSpaceHighlight;
|
||||||
|
|
||||||
|
// Enable tab highlight.
|
||||||
|
bool m_enableTabHighlight;
|
||||||
|
|
||||||
// Editor key mode.
|
// Editor key mode.
|
||||||
KeyMode m_keyMode;
|
KeyMode m_keyMode;
|
||||||
|
|
||||||
@ -1818,6 +1824,23 @@ inline void VConfigManager::setEnableTrailingSapceHighlight(bool p_enabled)
|
|||||||
m_enableTrailingSpaceHighlight);
|
m_enableTrailingSpaceHighlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool VConfigManager::getEnableTabHighlight() const
|
||||||
|
{
|
||||||
|
return m_enableTabHighlight;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VConfigManager::setEnableTabHighlight(bool p_enabled)
|
||||||
|
{
|
||||||
|
if (m_enableTabHighlight == p_enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_enableTabHighlight = p_enabled;
|
||||||
|
setConfigToSettings("editor",
|
||||||
|
"enable_tab_highlight",
|
||||||
|
m_enableTabHighlight);
|
||||||
|
}
|
||||||
|
|
||||||
inline KeyMode VConfigManager::getKeyMode() const
|
inline KeyMode VConfigManager::getKeyMode() const
|
||||||
{
|
{
|
||||||
return m_keyMode;
|
return m_keyMode;
|
||||||
|
@ -604,7 +604,7 @@ static void trailingSpaceFilter(VEdit *p_editor, QList<QTextEdit::ExtraSelection
|
|||||||
void VEdit::highlightTrailingSpace()
|
void VEdit::highlightTrailingSpace()
|
||||||
{
|
{
|
||||||
if (!g_config->getEnableTrailingSpaceHighlight()) {
|
if (!g_config->getEnableTrailingSpaceHighlight()) {
|
||||||
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::TrailingSapce];
|
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::TrailingSpace];
|
||||||
if (!selects.isEmpty()) {
|
if (!selects.isEmpty()) {
|
||||||
selects.clear();
|
selects.clear();
|
||||||
highlightExtraSelections(true);
|
highlightExtraSelections(true);
|
||||||
@ -616,7 +616,7 @@ void VEdit::highlightTrailingSpace()
|
|||||||
format.setBackground(m_trailingSpaceColor);
|
format.setBackground(m_trailingSpaceColor);
|
||||||
QString text("\\s+$");
|
QString text("\\s+$");
|
||||||
highlightTextAll(text, FindOption::RegularExpression,
|
highlightTextAll(text, FindOption::RegularExpression,
|
||||||
SelectionId::TrailingSapce, format,
|
SelectionId::TrailingSpace, format,
|
||||||
trailingSpaceFilter);
|
trailingSpaceFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@ VEditor::VEditor(VFile *p_file,
|
|||||||
m_enableInputMethod(true),
|
m_enableInputMethod(true),
|
||||||
m_timeStamp(0),
|
m_timeStamp(0),
|
||||||
m_trailingSpaceSelectionTS(0),
|
m_trailingSpaceSelectionTS(0),
|
||||||
m_completer(p_completer)
|
m_completer(p_completer),
|
||||||
|
m_trailingSpaceHighlightEnabled(false),
|
||||||
|
m_tabHighlightEnabled(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +75,8 @@ void VEditor::init()
|
|||||||
|
|
||||||
m_trailingSpaceColor = QColor(g_config->getEditorTrailingSpaceBg());
|
m_trailingSpaceColor = QColor(g_config->getEditorTrailingSpaceBg());
|
||||||
|
|
||||||
|
m_tabColor = g_config->getMdEditPalette().color(QPalette::Text);
|
||||||
|
|
||||||
QPixmap wrapPixmap(":/resources/icons/search_wrap.svg");
|
QPixmap wrapPixmap(":/resources/icons/search_wrap.svg");
|
||||||
m_wrapLabel = new QLabel(m_editor);
|
m_wrapLabel = new QLabel(m_editor);
|
||||||
m_wrapLabel->setPixmap(wrapPixmap.scaled(labelSize, labelSize));
|
m_wrapLabel->setPixmap(wrapPixmap.scaled(labelSize, labelSize));
|
||||||
@ -93,7 +97,7 @@ void VEditor::init()
|
|||||||
m_trailingSpaceTimer->setSingleShot(true);
|
m_trailingSpaceTimer->setSingleShot(true);
|
||||||
m_trailingSpaceTimer->setInterval(trailingSpaceUpdateTimer);
|
m_trailingSpaceTimer->setInterval(trailingSpaceUpdateTimer);
|
||||||
QObject::connect(m_trailingSpaceTimer, &QTimer::timeout,
|
QObject::connect(m_trailingSpaceTimer, &QTimer::timeout,
|
||||||
m_object, &VEditorObject::doUpdateTrailingSpaceHighlights);
|
m_object, &VEditorObject::doUpdateTrailingSpaceAndTabHighlights);
|
||||||
|
|
||||||
m_extraSelections.resize((int)SelectionId::MaxSelection);
|
m_extraSelections.resize((int)SelectionId::MaxSelection);
|
||||||
|
|
||||||
@ -108,9 +112,31 @@ void VEditor::labelTimerTimeout()
|
|||||||
m_wrapLabel->hide();
|
m_wrapLabel->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditor::updateTrailingSpaceHighlights()
|
bool VEditor::needUpdateTrailingSpaceAndTabHighlights()
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
|
bool space = g_config->getEnableTrailingSpaceHighlight();
|
||||||
|
if (m_trailingSpaceHighlightEnabled != space) {
|
||||||
|
m_trailingSpaceHighlightEnabled = space;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tab = g_config->getEnableTabHighlight();
|
||||||
|
if (m_tabHighlightEnabled != tab) {
|
||||||
|
m_tabHighlightEnabled = tab;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_trailingSpaceSelectionTS != m_timeStamp) {
|
if (m_trailingSpaceSelectionTS != m_timeStamp) {
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VEditor::updateTrailingSpaceAndTabHighlights()
|
||||||
|
{
|
||||||
|
if (needUpdateTrailingSpaceAndTabHighlights()) {
|
||||||
m_trailingSpaceTimer->start();
|
m_trailingSpaceTimer->start();
|
||||||
} else {
|
} else {
|
||||||
highlightExtraSelections(false);
|
highlightExtraSelections(false);
|
||||||
@ -123,7 +149,7 @@ void VEditor::doHighlightExtraSelections()
|
|||||||
Q_ASSERT(nrExtra == (int)SelectionId::MaxSelection);
|
Q_ASSERT(nrExtra == (int)SelectionId::MaxSelection);
|
||||||
QList<QTextEdit::ExtraSelection> extraSelects;
|
QList<QTextEdit::ExtraSelection> extraSelects;
|
||||||
for (int i = 0; i < nrExtra; ++i) {
|
for (int i = 0; i < nrExtra; ++i) {
|
||||||
if (i == (int)SelectionId::TrailingSapce) {
|
if (i == (int)SelectionId::TrailingSpace) {
|
||||||
filterTrailingSpace(extraSelects, m_extraSelections[i]);
|
filterTrailingSpace(extraSelects, m_extraSelections[i]);
|
||||||
} else {
|
} else {
|
||||||
extraSelects.append(m_extraSelections[i]);
|
extraSelects.append(m_extraSelections[i]);
|
||||||
@ -133,29 +159,51 @@ void VEditor::doHighlightExtraSelections()
|
|||||||
setExtraSelectionsW(extraSelects);
|
setExtraSelectionsW(extraSelects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditor::doUpdateTrailingSpaceHighlights()
|
void VEditor::doUpdateTrailingSpaceAndTabHighlights()
|
||||||
{
|
{
|
||||||
if (!g_config->getEnableTrailingSpaceHighlight()) {
|
bool needHighlight = false;
|
||||||
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::TrailingSapce];
|
|
||||||
|
// Trailing space.
|
||||||
|
if (!m_trailingSpaceHighlightEnabled) {
|
||||||
|
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::TrailingSpace];
|
||||||
if (!selects.isEmpty()) {
|
if (!selects.isEmpty()) {
|
||||||
selects.clear();
|
selects.clear();
|
||||||
highlightExtraSelections(true);
|
needHighlight = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
m_trailingSpaceSelectionTS = m_timeStamp;
|
needHighlight = true;
|
||||||
return;
|
QTextCharFormat format;
|
||||||
|
format.setBackground(m_trailingSpaceColor);
|
||||||
|
QString text("\\s+$");
|
||||||
|
highlightTextAll(text,
|
||||||
|
FindOption::RegularExpression,
|
||||||
|
SelectionId::TrailingSpace,
|
||||||
|
format);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat format;
|
// Tab.
|
||||||
format.setBackground(m_trailingSpaceColor);
|
if (!m_tabHighlightEnabled) {
|
||||||
QString text("\\s+$");
|
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::Tab];
|
||||||
highlightTextAll(text,
|
if (!selects.isEmpty()) {
|
||||||
FindOption::RegularExpression,
|
selects.clear();
|
||||||
SelectionId::TrailingSapce,
|
needHighlight = true;
|
||||||
format);
|
}
|
||||||
|
} else {
|
||||||
|
needHighlight = true;
|
||||||
|
QTextCharFormat format;
|
||||||
|
format.setBackground(m_tabColor);
|
||||||
|
QString text("\\t");
|
||||||
|
highlightTextAll(text,
|
||||||
|
FindOption::RegularExpression,
|
||||||
|
SelectionId::Tab,
|
||||||
|
format);
|
||||||
|
}
|
||||||
|
|
||||||
m_trailingSpaceSelectionTS = m_timeStamp;
|
m_trailingSpaceSelectionTS = m_timeStamp;
|
||||||
highlightExtraSelections(true);
|
|
||||||
|
if (needHighlight) {
|
||||||
|
highlightExtraSelections(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditor::updateEditConfig()
|
void VEditor::updateEditConfig()
|
||||||
@ -175,7 +223,7 @@ void VEditor::highlightOnCursorPositionChanged()
|
|||||||
|
|
||||||
QTextCursor cursor = textCursorW();
|
QTextCursor cursor = textCursorW();
|
||||||
if (lastCursor.isNull() || cursor.blockNumber() != lastCursor.blockNumber()) {
|
if (lastCursor.isNull() || cursor.blockNumber() != lastCursor.blockNumber()) {
|
||||||
updateTrailingSpaceHighlights();
|
updateTrailingSpaceAndTabHighlights();
|
||||||
highlightCurrentLine();
|
highlightCurrentLine();
|
||||||
} else {
|
} else {
|
||||||
// Judge whether we have trailing space at current line.
|
// Judge whether we have trailing space at current line.
|
||||||
@ -196,7 +244,7 @@ void VEditor::highlightOnCursorPositionChanged()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
updateTrailingSpaceHighlights();
|
updateTrailingSpaceAndTabHighlights();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@ enum class SelectionId {
|
|||||||
SearchedKeyword,
|
SearchedKeyword,
|
||||||
SearchedKeywordUnderCursor,
|
SearchedKeywordUnderCursor,
|
||||||
IncrementalSearchedKeyword,
|
IncrementalSearchedKeyword,
|
||||||
TrailingSapce,
|
TrailingSpace,
|
||||||
|
Tab,
|
||||||
MaxSelection
|
MaxSelection
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -490,6 +491,10 @@ private:
|
|||||||
int p_start = 0,
|
int p_start = 0,
|
||||||
int p_end = -1);
|
int p_end = -1);
|
||||||
|
|
||||||
|
void updateTrailingSpaceAndTabHighlights();
|
||||||
|
|
||||||
|
bool needUpdateTrailingSpaceAndTabHighlights();
|
||||||
|
|
||||||
QLabel *m_wrapLabel;
|
QLabel *m_wrapLabel;
|
||||||
QTimer *m_labelTimer;
|
QTimer *m_labelTimer;
|
||||||
|
|
||||||
@ -512,6 +517,7 @@ private:
|
|||||||
QColor m_incrementalSearchedWordBg;
|
QColor m_incrementalSearchedWordBg;
|
||||||
|
|
||||||
QColor m_trailingSpaceColor;
|
QColor m_trailingSpaceColor;
|
||||||
|
QColor m_tabColor;
|
||||||
|
|
||||||
// Timer for extra selections highlight.
|
// Timer for extra selections highlight.
|
||||||
QTimer *m_highlightTimer;
|
QTimer *m_highlightTimer;
|
||||||
@ -538,6 +544,9 @@ private:
|
|||||||
|
|
||||||
FindInfo m_findInfo;
|
FindInfo m_findInfo;
|
||||||
|
|
||||||
|
bool m_trailingSpaceHighlightEnabled;
|
||||||
|
bool m_tabHighlightEnabled;
|
||||||
|
|
||||||
// Functions for private slots.
|
// Functions for private slots.
|
||||||
private:
|
private:
|
||||||
void labelTimerTimeout();
|
void labelTimerTimeout();
|
||||||
@ -545,9 +554,7 @@ private:
|
|||||||
// Do the real work to highlight extra selections.
|
// Do the real work to highlight extra selections.
|
||||||
void doHighlightExtraSelections();
|
void doHighlightExtraSelections();
|
||||||
|
|
||||||
void updateTrailingSpaceHighlights();
|
void doUpdateTrailingSpaceAndTabHighlights();
|
||||||
|
|
||||||
void doUpdateTrailingSpaceHighlights();
|
|
||||||
|
|
||||||
void clearFindCache();
|
void clearFindCache();
|
||||||
};
|
};
|
||||||
@ -615,9 +622,9 @@ private slots:
|
|||||||
m_editor->doHighlightExtraSelections();
|
m_editor->doHighlightExtraSelections();
|
||||||
}
|
}
|
||||||
|
|
||||||
void doUpdateTrailingSpaceHighlights()
|
void doUpdateTrailingSpaceAndTabHighlights()
|
||||||
{
|
{
|
||||||
m_editor->doUpdateTrailingSpaceHighlights();
|
m_editor->doUpdateTrailingSpaceAndTabHighlights();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearFindCache()
|
void clearFindCache()
|
||||||
|
@ -1236,6 +1236,15 @@ void VMainWindow::initEditMenu()
|
|||||||
connect(trailingSapceAct, &QAction::triggered,
|
connect(trailingSapceAct, &QAction::triggered,
|
||||||
this, &VMainWindow::changeHighlightTrailingSapce);
|
this, &VMainWindow::changeHighlightTrailingSapce);
|
||||||
|
|
||||||
|
// Highlight tab.
|
||||||
|
QAction *tabAct = new QAction(tr("Highlight Tabs"), this);
|
||||||
|
tabAct->setToolTip(tr("Highlight all the tabs"));
|
||||||
|
tabAct->setCheckable(true);
|
||||||
|
connect(tabAct, &QAction::triggered,
|
||||||
|
this, [this](bool p_checked) {
|
||||||
|
g_config->setEnableTabHighlight(p_checked);
|
||||||
|
});
|
||||||
|
|
||||||
QMenu *findReplaceMenu = editMenu->addMenu(tr("Find/Replace"));
|
QMenu *findReplaceMenu = editMenu->addMenu(tr("Find/Replace"));
|
||||||
findReplaceMenu->setToolTipsVisible(true);
|
findReplaceMenu->setToolTipsVisible(true);
|
||||||
findReplaceMenu->addAction(m_findReplaceAct);
|
findReplaceMenu->addAction(m_findReplaceAct);
|
||||||
@ -1311,6 +1320,9 @@ void VMainWindow::initEditMenu()
|
|||||||
|
|
||||||
editMenu->addAction(trailingSapceAct);
|
editMenu->addAction(trailingSapceAct);
|
||||||
trailingSapceAct->setChecked(g_config->getEnableTrailingSpaceHighlight());
|
trailingSapceAct->setChecked(g_config->getEnableTrailingSpaceHighlight());
|
||||||
|
|
||||||
|
editMenu->addAction(tabAct);
|
||||||
|
tabAct->setChecked(g_config->getEnableTabHighlight());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::initDockWindows()
|
void VMainWindow::initDockWindows()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user