mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
change cursorline color in Vim mode
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
72fdf399bc
commit
059e8dacd2
@ -27,6 +27,9 @@ public:
|
|||||||
virtual bool handleKeyPressEvent(QKeyEvent *p_event) = 0;
|
virtual bool handleKeyPressEvent(QKeyEvent *p_event) = 0;
|
||||||
void updateTabSettings();
|
void updateTabSettings();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void keyStateChanged(KeyState p_state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void insertTextAtCurPos(const QString &p_text);
|
void insertTextAtCurPos(const QString &p_text);
|
||||||
|
|
||||||
|
@ -12,11 +12,16 @@ extern VNote *g_vnote;
|
|||||||
|
|
||||||
enum ImageProperty { ImagePath = 1 };
|
enum ImageProperty { ImagePath = 1 };
|
||||||
|
|
||||||
|
const QString VMdEdit::c_cursorLineColor = "Indigo1";
|
||||||
|
const QString VMdEdit::c_cursorLineColorVim = "Green2";
|
||||||
|
|
||||||
VMdEdit::VMdEdit(VFile *p_file, QWidget *p_parent)
|
VMdEdit::VMdEdit(VFile *p_file, QWidget *p_parent)
|
||||||
: VEdit(p_file, p_parent), m_mdHighlighter(NULL)
|
: VEdit(p_file, p_parent), m_mdHighlighter(NULL)
|
||||||
{
|
{
|
||||||
Q_ASSERT(p_file->getDocType() == DocType::Markdown);
|
Q_ASSERT(p_file->getDocType() == DocType::Markdown);
|
||||||
|
|
||||||
|
m_cursorLineColor = QColor(g_vnote->getColorFromPalette(c_cursorLineColor));
|
||||||
|
|
||||||
setAcceptRichText(false);
|
setAcceptRichText(false);
|
||||||
m_mdHighlighter = new HGMarkdownHighlighter(vconfig.getMdHighlightingStyles(),
|
m_mdHighlighter = new HGMarkdownHighlighter(vconfig.getMdHighlightingStyles(),
|
||||||
500, document());
|
500, document());
|
||||||
@ -25,6 +30,8 @@ VMdEdit::VMdEdit(VFile *p_file, QWidget *p_parent)
|
|||||||
connect(m_mdHighlighter, &HGMarkdownHighlighter::imageBlocksUpdated,
|
connect(m_mdHighlighter, &HGMarkdownHighlighter::imageBlocksUpdated,
|
||||||
this, &VMdEdit::updateImageBlocks);
|
this, &VMdEdit::updateImageBlocks);
|
||||||
m_editOps = new VMdEditOperations(this, m_file);
|
m_editOps = new VMdEditOperations(this, m_file);
|
||||||
|
connect(m_editOps, &VEditOperations::keyStateChanged,
|
||||||
|
this, &VMdEdit::handleEditStateChanged);
|
||||||
|
|
||||||
connect(this, &VMdEdit::cursorPositionChanged,
|
connect(this, &VMdEdit::cursorPositionChanged,
|
||||||
this, &VMdEdit::updateCurHeader);
|
this, &VMdEdit::updateCurHeader);
|
||||||
@ -460,13 +467,12 @@ int VMdEdit::removeObjectReplacementLine(QString &p_text, int p_index) const
|
|||||||
|
|
||||||
void VMdEdit::highlightCurrentLine()
|
void VMdEdit::highlightCurrentLine()
|
||||||
{
|
{
|
||||||
static QColor lineColor = QColor(g_vnote->getColorFromPalette("Indigo1"));
|
|
||||||
QList<QTextEdit::ExtraSelection> extraSelects;
|
QList<QTextEdit::ExtraSelection> extraSelects;
|
||||||
|
|
||||||
if (!isReadOnly()) {
|
if (!isReadOnly()) {
|
||||||
QTextEdit::ExtraSelection select;
|
QTextEdit::ExtraSelection select;
|
||||||
|
|
||||||
select.format.setBackground(lineColor);
|
select.format.setBackground(m_cursorLineColor);
|
||||||
select.format.setProperty(QTextFormat::FullWidthSelection, true);
|
select.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
select.cursor = textCursor();
|
select.cursor = textCursor();
|
||||||
select.cursor.clearSelection();
|
select.cursor.clearSelection();
|
||||||
@ -474,3 +480,14 @@ void VMdEdit::highlightCurrentLine()
|
|||||||
}
|
}
|
||||||
setExtraSelections(extraSelects);
|
setExtraSelections(extraSelects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMdEdit::handleEditStateChanged(KeyState p_state)
|
||||||
|
{
|
||||||
|
qDebug() << "edit state" << (int)p_state;
|
||||||
|
if (p_state == KeyState::Normal) {
|
||||||
|
m_cursorLineColor = QColor(g_vnote->getColorFromPalette(c_cursorLineColor));
|
||||||
|
} else {
|
||||||
|
m_cursorLineColor = QColor(g_vnote->getColorFromPalette(c_cursorLineColorVim));
|
||||||
|
}
|
||||||
|
highlightCurrentLine();
|
||||||
|
}
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include "vedit.h"
|
#include "vedit.h"
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QColor>
|
||||||
#include "vtoc.h"
|
#include "vtoc.h"
|
||||||
|
#include "veditoperations.h"
|
||||||
|
|
||||||
class HGMarkdownHighlighter;
|
class HGMarkdownHighlighter;
|
||||||
|
|
||||||
@ -37,6 +39,7 @@ private slots:
|
|||||||
// Update block list containing image links.
|
// Update block list containing image links.
|
||||||
void updateImageBlocks(QSet<int> p_imageBlocks);
|
void updateImageBlocks(QSet<int> p_imageBlocks);
|
||||||
void highlightCurrentLine();
|
void highlightCurrentLine();
|
||||||
|
void handleEditStateChanged(KeyState p_state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
||||||
@ -71,6 +74,10 @@ private:
|
|||||||
QVector<QString> m_insertedImages;
|
QVector<QString> m_insertedImages;
|
||||||
QVector<QString> m_initImages;
|
QVector<QString> m_initImages;
|
||||||
QVector<VHeader> m_headers;
|
QVector<VHeader> m_headers;
|
||||||
|
QColor m_cursorLineColor;
|
||||||
|
|
||||||
|
static const QString c_cursorLineColor;
|
||||||
|
static const QString c_cursorLineColorVim;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VMDEDIT_H
|
#endif // VMDEDIT_H
|
||||||
|
@ -414,7 +414,7 @@ bool VMdEditOperations::handleKeyD(QKeyEvent *p_event)
|
|||||||
if (p_event->modifiers() == Qt::ControlModifier) {
|
if (p_event->modifiers() == Qt::ControlModifier) {
|
||||||
// Ctrl+D, enter Vim-pending mode.
|
// Ctrl+D, enter Vim-pending mode.
|
||||||
// Will accept the key stroke in m_pendingTime as Vim normal command.
|
// Will accept the key stroke in m_pendingTime as Vim normal command.
|
||||||
m_keyState = KeyState::Vim;
|
setKeyState(KeyState::Vim);
|
||||||
m_pendingTimer->stop();
|
m_pendingTimer->stop();
|
||||||
m_pendingTimer->start();
|
m_pendingTimer->start();
|
||||||
p_event->accept();
|
p_event->accept();
|
||||||
@ -526,7 +526,7 @@ bool VMdEditOperations::handleKeyEsc(QKeyEvent *p_event)
|
|||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
|
|
||||||
m_pendingTimer->stop();
|
m_pendingTimer->stop();
|
||||||
m_keyState = KeyState::Normal;
|
setKeyState(KeyState::Normal);
|
||||||
m_pendingKey.clear();
|
m_pendingKey.clear();
|
||||||
|
|
||||||
p_event->accept();
|
p_event->accept();
|
||||||
@ -804,7 +804,7 @@ bool VMdEditOperations::handleKeyPressVim(QKeyEvent *p_event)
|
|||||||
if (modifiers == Qt::NoModifier) {
|
if (modifiers == Qt::NoModifier) {
|
||||||
// V to enter visual mode.
|
// V to enter visual mode.
|
||||||
if (m_pendingKey.isEmpty() && m_keyState != KeyState::VimVisual) {
|
if (m_pendingKey.isEmpty() && m_keyState != KeyState::VimVisual) {
|
||||||
m_keyState = KeyState::VimVisual;
|
setKeyState(KeyState::VimVisual);
|
||||||
goto pending;
|
goto pending;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -863,7 +863,7 @@ bool VMdEditOperations::handleKeyPressVim(QKeyEvent *p_event)
|
|||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
m_keyState = KeyState::Normal;
|
setKeyState(KeyState::Normal);
|
||||||
m_pendingKey.clear();
|
m_pendingKey.clear();
|
||||||
p_event->accept();
|
p_event->accept();
|
||||||
return true;
|
return true;
|
||||||
@ -900,7 +900,7 @@ void VMdEditOperations::pendingTimerTimeout()
|
|||||||
m_pendingTimer->start();
|
m_pendingTimer->start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_keyState = KeyState::Normal;
|
setKeyState(KeyState::Normal);
|
||||||
m_pendingKey.clear();
|
m_pendingKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,3 +917,12 @@ bool VMdEditOperations::suffixNumAllowed(const QList<QString> &p_seq)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMdEditOperations::setKeyState(KeyState p_state)
|
||||||
|
{
|
||||||
|
if (m_keyState == p_state) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_keyState = p_state;
|
||||||
|
emit keyStateChanged(m_keyState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ private:
|
|||||||
bool insertImageFromURL(const QUrl &imageUrl);
|
bool insertImageFromURL(const QUrl &imageUrl);
|
||||||
void insertImageFromPath(const QString &title, const QString &path, const QString &oriImagePath);
|
void insertImageFromPath(const QString &title, const QString &path, const QString &oriImagePath);
|
||||||
void insertImageFromQImage(const QString &title, const QString &path, const QImage &image);
|
void insertImageFromQImage(const QString &title, const QString &path, const QImage &image);
|
||||||
|
void setKeyState(KeyState p_state);
|
||||||
|
|
||||||
// Key press handlers.
|
// Key press handlers.
|
||||||
bool handleKeyTab(QKeyEvent *p_event);
|
bool handleKeyTab(QKeyEvent *p_event);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user