forked from qt-creator/qt-creator
FakeVim: Streamline settings handling a bit
Change-Id: I6ab2c1643a5236525515ded296cd854933584603 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -25,8 +25,7 @@
|
|||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace FakeVim {
|
namespace FakeVim::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
#ifdef FAKEVIM_STANDALONE
|
#ifdef FAKEVIM_STANDALONE
|
||||||
FvBaseAspect::FvBaseAspect()
|
FvBaseAspect::FvBaseAspect()
|
||||||
@@ -72,9 +71,9 @@ void setAutoApply(bool ) {}
|
|||||||
|
|
||||||
static FakeVimSettings *s_settings;
|
static FakeVimSettings *s_settings;
|
||||||
|
|
||||||
FakeVimSettings *fakeVimSettings()
|
FakeVimSettings &settings()
|
||||||
{
|
{
|
||||||
return s_settings;
|
return *s_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeVimSettings::FakeVimSettings()
|
FakeVimSettings::FakeVimSettings()
|
||||||
@@ -327,5 +326,4 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
|
|||||||
m_nameToAspect[shortName] = aspect;
|
m_nameToAspect[shortName] = aspect;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // FakeVim::Internal
|
||||||
} // namespace FakeVim
|
|
||||||
|
|||||||
@@ -13,8 +13,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
namespace FakeVim {
|
namespace FakeVim::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
#ifdef FAKEVIM_STANDALONE
|
#ifdef FAKEVIM_STANDALONE
|
||||||
class FvBaseAspect
|
class FvBaseAspect
|
||||||
@@ -145,7 +144,6 @@ private:
|
|||||||
QHash<FvBaseAspect *, QString> m_aspectToName;
|
QHash<FvBaseAspect *, QString> m_aspectToName;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeVimSettings *fakeVimSettings();
|
FakeVimSettings &settings();
|
||||||
|
|
||||||
} // namespace Internal
|
} // FakeVim::Internal
|
||||||
} // namespace FakeVim
|
|
||||||
|
|||||||
@@ -408,9 +408,8 @@ static QRegularExpression vimPatternToQtPattern(const QString &needle)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// FIXME: Option smartcase should be used only if search was typed by user.
|
// FIXME: Option smartcase should be used only if search was typed by user.
|
||||||
const bool ignoreCaseOption = fakeVimSettings()->ignoreCase.value();
|
const bool smartCaseOption = settings().smartCase();
|
||||||
const bool smartCaseOption = fakeVimSettings()->smartCase.value();
|
const bool initialIgnoreCase = settings().ignoreCase()
|
||||||
const bool initialIgnoreCase = ignoreCaseOption
|
|
||||||
&& !(smartCaseOption && needle.contains(QRegularExpression("[A-Z]")));
|
&& !(smartCaseOption && needle.contains(QRegularExpression("[A-Z]")));
|
||||||
|
|
||||||
bool ignorecase = initialIgnoreCase;
|
bool ignorecase = initialIgnoreCase;
|
||||||
@@ -2373,7 +2372,7 @@ public:
|
|||||||
QString surroundFunction; // Used for storing the function name provided to ys{motion}f
|
QString surroundFunction; // Used for storing the function name provided to ys{motion}f
|
||||||
} g;
|
} g;
|
||||||
|
|
||||||
FakeVimSettings &s = *fakeVimSettings();
|
FakeVimSettings &s = settings();
|
||||||
};
|
};
|
||||||
|
|
||||||
static void initSingleShotTimer(QTimer *timer,
|
static void initSingleShotTimer(QTimer *timer,
|
||||||
@@ -2527,7 +2526,7 @@ void FakeVimHandler::Private::leaveFakeVim(bool needUpdate)
|
|||||||
|
|
||||||
// The command might have destroyed the editor.
|
// The command might have destroyed the editor.
|
||||||
if (m_textedit || m_plaintextedit) {
|
if (m_textedit || m_plaintextedit) {
|
||||||
if (s.showMarks.value())
|
if (s.showMarks())
|
||||||
updateSelection();
|
updateSelection();
|
||||||
|
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
@@ -2576,7 +2575,7 @@ bool FakeVimHandler::Private::wantsOverride(QKeyEvent *ev)
|
|||||||
|
|
||||||
// We are interested in overriding most Ctrl key combinations.
|
// We are interested in overriding most Ctrl key combinations.
|
||||||
if (isOnlyControlModifier(mods)
|
if (isOnlyControlModifier(mods)
|
||||||
&& !s.passControlKey.value()
|
&& !s.passControlKey()
|
||||||
&& ((key >= Key_A && key <= Key_Z && key != Key_K)
|
&& ((key >= Key_A && key <= Key_Z && key != Key_K)
|
||||||
|| key == Key_BracketLeft || key == Key_BracketRight)) {
|
|| key == Key_BracketLeft || key == Key_BracketRight)) {
|
||||||
// Ctrl-K is special as it is the Core's default notion of Locator
|
// Ctrl-K is special as it is the Core's default notion of Locator
|
||||||
@@ -3059,7 +3058,7 @@ void FakeVimHandler::Private::stopIncrementalFind()
|
|||||||
|
|
||||||
void FakeVimHandler::Private::updateFind(bool isComplete)
|
void FakeVimHandler::Private::updateFind(bool isComplete)
|
||||||
{
|
{
|
||||||
if (!isComplete && !s.incSearch.value())
|
if (!isComplete && !s.incSearch())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g.currentMessage.clear();
|
g.currentMessage.clear();
|
||||||
@@ -3161,7 +3160,7 @@ void FakeVimHandler::Private::pushUndoState(bool overwrite)
|
|||||||
pos = firstPositionInLine(lineForPosition(pos));
|
pos = firstPositionInLine(lineForPosition(pos));
|
||||||
else if (isVisualBlockMode())
|
else if (isVisualBlockMode())
|
||||||
pos = blockAt(pos).position() + qMin(columnAt(anchor()), columnAt(position()));
|
pos = blockAt(pos).position() + qMin(columnAt(anchor()), columnAt(position()));
|
||||||
} else if (g.movetype == MoveLineWise && s.startOfLine.value()) {
|
} else if (g.movetype == MoveLineWise && s.startOfLine()) {
|
||||||
QTextCursor tc = m_cursor;
|
QTextCursor tc = m_cursor;
|
||||||
if (g.submode == ShiftLeftSubMode || g.submode == ShiftRightSubMode
|
if (g.submode == ShiftLeftSubMode || g.submode == ShiftRightSubMode
|
||||||
|| g.submode == IndentSubMode) {
|
|| g.submode == IndentSubMode) {
|
||||||
@@ -3621,7 +3620,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement)
|
|||||||
return;
|
return;
|
||||||
} else if (g.submode == ExchangeSubMode) {
|
} else if (g.submode == ExchangeSubMode) {
|
||||||
exchangeRange(currentRange());
|
exchangeRange(currentRange());
|
||||||
} else if (g.submode == ReplaceWithRegisterSubMode && s.emulateReplaceWithRegister.value()) {
|
} else if (g.submode == ReplaceWithRegisterSubMode && s.emulateReplaceWithRegister()) {
|
||||||
pushUndoState(false);
|
pushUndoState(false);
|
||||||
beginEditBlock();
|
beginEditBlock();
|
||||||
replaceWithRegister(currentRange());
|
replaceWithRegister(currentRange());
|
||||||
@@ -3734,7 +3733,7 @@ void FakeVimHandler::Private::clearCurrentMode()
|
|||||||
void FakeVimHandler::Private::updateSelection()
|
void FakeVimHandler::Private::updateSelection()
|
||||||
{
|
{
|
||||||
QList<QTextEdit::ExtraSelection> selections = m_extraSelections;
|
QList<QTextEdit::ExtraSelection> selections = m_extraSelections;
|
||||||
if (s.showMarks.value()) {
|
if (s.showMarks()) {
|
||||||
for (auto it = m_buffer->marks.cbegin(), end = m_buffer->marks.cend(); it != end; ++it) {
|
for (auto it = m_buffer->marks.cbegin(), end = m_buffer->marks.cend(); it != end; ++it) {
|
||||||
QTextEdit::ExtraSelection sel;
|
QTextEdit::ExtraSelection sel;
|
||||||
sel.cursor = m_cursor;
|
sel.cursor = m_cursor;
|
||||||
@@ -3753,7 +3752,7 @@ void FakeVimHandler::Private::updateSelection()
|
|||||||
|
|
||||||
void FakeVimHandler::Private::updateHighlights()
|
void FakeVimHandler::Private::updateHighlights()
|
||||||
{
|
{
|
||||||
if (s.useCoreSearch.value() || !s.hlSearch.value() || g.highlightsCleared) {
|
if (s.useCoreSearch() || !s.hlSearch() || g.highlightsCleared) {
|
||||||
if (m_highlighted.isEmpty())
|
if (m_highlighted.isEmpty())
|
||||||
return;
|
return;
|
||||||
m_highlighted.clear();
|
m_highlighted.clear();
|
||||||
@@ -3800,7 +3799,7 @@ void FakeVimHandler::Private::updateMiniBuffer()
|
|||||||
} else if (!g.mapStates.isEmpty() && !g.mapStates.last().silent) {
|
} else if (!g.mapStates.isEmpty() && !g.mapStates.last().silent) {
|
||||||
// Do not reset previous message when after running a mapped command.
|
// Do not reset previous message when after running a mapped command.
|
||||||
return;
|
return;
|
||||||
} else if (g.mode == CommandMode && !g.currentCommand.isEmpty() && s.showCmd.value()) {
|
} else if (g.mode == CommandMode && !g.currentCommand.isEmpty() && s.showCmd()) {
|
||||||
msg = g.currentCommand;
|
msg = g.currentCommand;
|
||||||
messageLevel = MessageShowCmd;
|
messageLevel = MessageShowCmd;
|
||||||
} else if (g.mode == CommandMode && isVisualMode()) {
|
} else if (g.mode == CommandMode && isVisualMode()) {
|
||||||
@@ -3907,7 +3906,7 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
|
|||||||
handled = selectBlockTextObject(g.subsubdata.is('i'), '{', '}');
|
handled = selectBlockTextObject(g.subsubdata.is('i'), '{', '}');
|
||||||
else if (input.is('"') || input.is('\'') || input.is('`'))
|
else if (input.is('"') || input.is('\'') || input.is('`'))
|
||||||
handled = selectQuotedStringTextObject(g.subsubdata.is('i'), input.asChar());
|
handled = selectQuotedStringTextObject(g.subsubdata.is('i'), input.asChar());
|
||||||
else if (input.is('a') && s.emulateArgTextObj.value())
|
else if (input.is('a') && s.emulateArgTextObj())
|
||||||
handled = selectArgumentTextObject(g.subsubdata.is('i'));
|
handled = selectArgumentTextObject(g.subsubdata.is('i'));
|
||||||
else
|
else
|
||||||
handled = false;
|
handled = false;
|
||||||
@@ -4050,7 +4049,7 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
|
|||||||
g.subsubmode = NoSubSubMode;
|
g.subsubmode = NoSubSubMode;
|
||||||
} else if (input.is('/') || input.is('?')) {
|
} else if (input.is('/') || input.is('?')) {
|
||||||
g.lastSearchForward = input.is('/');
|
g.lastSearchForward = input.is('/');
|
||||||
if (s.useCoreSearch.value()) {
|
if (s.useCoreSearch()) {
|
||||||
// re-use the core dialog.
|
// re-use the core dialog.
|
||||||
g.findPending = true;
|
g.findPending = true;
|
||||||
m_findStartPosition = position();
|
m_findStartPosition = position();
|
||||||
@@ -4225,7 +4224,7 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
|
|||||||
m_cursor = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
|
m_cursor = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
|
||||||
handleStartOfLine();
|
handleStartOfLine();
|
||||||
} else if (input.is('n') || input.is('N')) {
|
} else if (input.is('n') || input.is('N')) {
|
||||||
if (s.useCoreSearch.value()) {
|
if (s.useCoreSearch()) {
|
||||||
bool forward = (input.is('n')) ? g.lastSearchForward : !g.lastSearchForward;
|
bool forward = (input.is('n')) ? g.lastSearchForward : !g.lastSearchForward;
|
||||||
int pos = position();
|
int pos = position();
|
||||||
q->findNextRequested(!forward);
|
q->findNextRequested(!forward);
|
||||||
@@ -4314,7 +4313,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
|
|||||||
handled = handleNoSubMode(input);
|
handled = handleNoSubMode(input);
|
||||||
} else if (g.submode == ExchangeSubMode) {
|
} else if (g.submode == ExchangeSubMode) {
|
||||||
handled = handleExchangeSubMode(input);
|
handled = handleExchangeSubMode(input);
|
||||||
} else if (g.submode == ChangeSubMode && input.is('x') && s.emulateExchange.value()) {
|
} else if (g.submode == ChangeSubMode && input.is('x') && s.emulateExchange()) {
|
||||||
// Exchange submode is "cx", so we need to switch over from ChangeSubMode here
|
// Exchange submode is "cx", so we need to switch over from ChangeSubMode here
|
||||||
g.submode = ExchangeSubMode;
|
g.submode = ExchangeSubMode;
|
||||||
handled = true;
|
handled = true;
|
||||||
@@ -4324,15 +4323,15 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
|
|||||||
} else if (g.submode == AddSurroundingSubMode) {
|
} else if (g.submode == AddSurroundingSubMode) {
|
||||||
handled = handleAddSurroundingSubMode(input);
|
handled = handleAddSurroundingSubMode(input);
|
||||||
} else if (g.submode == ChangeSubMode && (input.is('s') || input.is('S'))
|
} else if (g.submode == ChangeSubMode && (input.is('s') || input.is('S'))
|
||||||
&& s.emulateSurround.value()) {
|
&& s.emulateSurround()) {
|
||||||
g.submode = ChangeSurroundingSubMode;
|
g.submode = ChangeSurroundingSubMode;
|
||||||
g.surroundUpperCaseS = input.is('S');
|
g.surroundUpperCaseS = input.is('S');
|
||||||
handled = true;
|
handled = true;
|
||||||
} else if (g.submode == DeleteSubMode && input.is('s') && s.emulateSurround.value()) {
|
} else if (g.submode == DeleteSubMode && input.is('s') && s.emulateSurround()) {
|
||||||
g.submode = DeleteSurroundingSubMode;
|
g.submode = DeleteSurroundingSubMode;
|
||||||
handled = true;
|
handled = true;
|
||||||
} else if (g.submode == YankSubMode && (input.is('s') || input.is('S'))
|
} else if (g.submode == YankSubMode && (input.is('s') || input.is('S'))
|
||||||
&& s.emulateSurround.value()) {
|
&& s.emulateSurround()) {
|
||||||
g.submode = AddSurroundingSubMode;
|
g.submode = AddSurroundingSubMode;
|
||||||
g.movetype = MoveInclusive;
|
g.movetype = MoveInclusive;
|
||||||
g.surroundUpperCaseS = input.is('S');
|
g.surroundUpperCaseS = input.is('S');
|
||||||
@@ -4341,10 +4340,9 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
|
|||||||
|| g.submode == DeleteSubMode
|
|| g.submode == DeleteSubMode
|
||||||
|| g.submode == YankSubMode) {
|
|| g.submode == YankSubMode) {
|
||||||
handled = handleChangeDeleteYankSubModes(input);
|
handled = handleChangeDeleteYankSubModes(input);
|
||||||
} else if (g.submode == CommentSubMode && s.emulateVimCommentary.value()) {
|
} else if (g.submode == CommentSubMode && s.emulateVimCommentary()) {
|
||||||
handled = handleCommentSubMode(input);
|
handled = handleCommentSubMode(input);
|
||||||
} else if (g.submode == ReplaceWithRegisterSubMode
|
} else if (g.submode == ReplaceWithRegisterSubMode && s.emulateReplaceWithRegister()) {
|
||||||
&& s.emulateReplaceWithRegister.value()) {
|
|
||||||
handled = handleReplaceWithRegisterSubMode(input);
|
handled = handleReplaceWithRegisterSubMode(input);
|
||||||
} else if (g.submode == ReplaceSubMode) {
|
} else if (g.submode == ReplaceSubMode) {
|
||||||
handled = handleReplaceSubMode(input);
|
handled = handleReplaceSubMode(input);
|
||||||
@@ -4487,7 +4485,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
setTargetColumn();
|
setTargetColumn();
|
||||||
} else if (input.isControl('a')) {
|
} else if (input.isControl('a')) {
|
||||||
changeNumberTextObject(count());
|
changeNumberTextObject(count());
|
||||||
} else if (g.gflag && input.is('c') && s.emulateVimCommentary.value()) {
|
} else if (g.gflag && input.is('c') && s.emulateVimCommentary()) {
|
||||||
if (isVisualMode()) {
|
if (isVisualMode()) {
|
||||||
pushUndoState();
|
pushUndoState();
|
||||||
|
|
||||||
@@ -4512,7 +4510,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
pushUndoState();
|
pushUndoState();
|
||||||
setAnchor();
|
setAnchor();
|
||||||
}
|
}
|
||||||
} else if (g.gflag && input.is('r') && s.emulateReplaceWithRegister.value()) {
|
} else if (g.gflag && input.is('r') && s.emulateReplaceWithRegister()) {
|
||||||
g.submode = ReplaceWithRegisterSubMode;
|
g.submode = ReplaceWithRegisterSubMode;
|
||||||
if (isVisualMode()) {
|
if (isVisualMode()) {
|
||||||
dotCommand = visualDotCommand() + QString::number(count()) + "gr";
|
dotCommand = visualDotCommand() + QString::number(count()) + "gr";
|
||||||
@@ -4671,7 +4669,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
int repeat = count();
|
int repeat = count();
|
||||||
while (--repeat >= 0)
|
while (--repeat >= 0)
|
||||||
redo();
|
redo();
|
||||||
} else if (input.is('S') && isVisualMode() && s.emulateSurround.value()) {
|
} else if (input.is('S') && isVisualMode() && s.emulateSurround()) {
|
||||||
g.submode = AddSurroundingSubMode;
|
g.submode = AddSurroundingSubMode;
|
||||||
g.subsubmode = SurroundSubSubMode;
|
g.subsubmode = SurroundSubSubMode;
|
||||||
} else if (input.is('s')) {
|
} else if (input.is('s')) {
|
||||||
@@ -4756,7 +4754,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
if (isVisualMode()) {
|
if (isVisualMode()) {
|
||||||
leaveVisualMode();
|
leaveVisualMode();
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (g.gflag || (g.submode == InvertCaseSubMode && s.tildeOp.value())) {
|
} else if (g.gflag || (g.submode == InvertCaseSubMode && s.tildeOp())) {
|
||||||
if (atEndOfLine())
|
if (atEndOfLine())
|
||||||
moveLeft();
|
moveLeft();
|
||||||
setAnchor();
|
setAnchor();
|
||||||
@@ -5404,8 +5402,8 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
if (!handleInsertInEditor(Input(Qt::Key_Backspace, Qt::NoModifier))) {
|
if (!handleInsertInEditor(Input(Qt::Key_Backspace, Qt::NoModifier))) {
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
if (!m_buffer->lastInsertion.isEmpty()
|
if (!m_buffer->lastInsertion.isEmpty()
|
||||||
|| s.backspace.value().contains("start")
|
|| s.backspace().contains("start")
|
||||||
|| s.backspace.value().contains("2")) {
|
|| s.backspace().contains("2")) {
|
||||||
const int line = cursorLine() + 1;
|
const int line = cursorLine() + 1;
|
||||||
const Column col = cursorColumn();
|
const Column col = cursorColumn();
|
||||||
QString data = lineContents(line);
|
QString data = lineContents(line);
|
||||||
@@ -5438,7 +5436,7 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
} else if (input.isKey(Key_Tab)) {
|
} else if (input.isKey(Key_Tab)) {
|
||||||
if (q->tabPressedInInsertMode()) {
|
if (q->tabPressedInInsertMode()) {
|
||||||
m_buffer->insertState.insertingSpaces = true;
|
m_buffer->insertState.insertingSpaces = true;
|
||||||
if (s.expandTab.value()) {
|
if (s.expandTab()) {
|
||||||
const int ts = s.tabStop();
|
const int ts = s.tabStop();
|
||||||
const int col = logicalCursorColumn();
|
const int col = logicalCursorColumn();
|
||||||
QString str = QString(ts - col % ts, ' ');
|
QString str = QString(ts - col % ts, ' ');
|
||||||
@@ -5494,7 +5492,7 @@ void FakeVimHandler::Private::insertInInsertMode(const QString &text)
|
|||||||
{
|
{
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
insertText(text);
|
insertText(text);
|
||||||
if (s.smartIndent.value() && isElectricCharacter(text.at(0))) {
|
if (s.smartIndent() && isElectricCharacter(text.at(0))) {
|
||||||
const QString leftText = block().text()
|
const QString leftText = block().text()
|
||||||
.left(position() - 1 - block().position());
|
.left(position() - 1 - block().position());
|
||||||
if (leftText.simplified().isEmpty()) {
|
if (leftText.simplified().isEmpty()) {
|
||||||
@@ -6265,7 +6263,7 @@ bool FakeVimHandler::Private::handleExMoveCommand(const ExCommand &cmd)
|
|||||||
|
|
||||||
if (!insertAtEnd)
|
if (!insertAtEnd)
|
||||||
moveUp(1);
|
moveUp(1);
|
||||||
if (s.startOfLine.value())
|
if (s.startOfLine())
|
||||||
moveToFirstNonBlankOnLine();
|
moveToFirstNonBlankOnLine();
|
||||||
|
|
||||||
if (lastAnchor.line >= startLine && lastAnchor.line <= endLine)
|
if (lastAnchor.line >= startLine && lastAnchor.line <= endLine)
|
||||||
@@ -6794,7 +6792,7 @@ QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tc.isNull()) {
|
if (tc.isNull()) {
|
||||||
if (s.wrapScan.value()) {
|
if (s.wrapScan()) {
|
||||||
tc = QTextCursor(document());
|
tc = QTextCursor(document());
|
||||||
tc.movePosition(sd.forward ? StartOfDocument : EndOfDocument);
|
tc.movePosition(sd.forward ? StartOfDocument : EndOfDocument);
|
||||||
if (sd.forward)
|
if (sd.forward)
|
||||||
@@ -6954,7 +6952,7 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat)
|
|||||||
std::swap(beginLine, endLine);
|
std::swap(beginLine, endLine);
|
||||||
targetPos = position();
|
targetPos = position();
|
||||||
}
|
}
|
||||||
if (s.startOfLine.value())
|
if (s.startOfLine())
|
||||||
targetPos = firstPositionInLine(beginLine);
|
targetPos = firstPositionInLine(beginLine);
|
||||||
|
|
||||||
const int sw = s.shiftWidth();
|
const int sw = s.shiftWidth();
|
||||||
@@ -7106,7 +7104,7 @@ void FakeVimHandler::Private::setupCharClass()
|
|||||||
const QChar c = QLatin1Char(i);
|
const QChar c = QLatin1Char(i);
|
||||||
m_charClass[i] = c.isSpace() ? 0 : 1;
|
m_charClass[i] = c.isSpace() ? 0 : 1;
|
||||||
}
|
}
|
||||||
const QString conf = s.isKeyword.value();
|
const QString conf = s.isKeyword();
|
||||||
for (const QString &part : conf.split(',')) {
|
for (const QString &part : conf.split(',')) {
|
||||||
if (part.contains('-')) {
|
if (part.contains('-')) {
|
||||||
const int from = someInt(part.section('-', 0, 0));
|
const int from = someInt(part.section('-', 0, 0));
|
||||||
@@ -7594,7 +7592,7 @@ void FakeVimHandler::Private::transformText(const Range &range, const Transforma
|
|||||||
|
|
||||||
void FakeVimHandler::Private::insertText(QTextCursor &tc, const QString &text)
|
void FakeVimHandler::Private::insertText(QTextCursor &tc, const QString &text)
|
||||||
{
|
{
|
||||||
if (s.passKeys.value()) {
|
if (s.passKeys()) {
|
||||||
if (tc.hasSelection() && text.isEmpty()) {
|
if (tc.hasSelection() && text.isEmpty()) {
|
||||||
QKeyEvent event(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier, QString());
|
QKeyEvent event(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier, QString());
|
||||||
passEventToEditor(event, tc);
|
passEventToEditor(event, tc);
|
||||||
@@ -7937,7 +7935,7 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
|
|||||||
moveRight();
|
moveRight();
|
||||||
|
|
||||||
// If the line we started from is a comment, remove the comment string from the next line
|
// If the line we started from is a comment, remove the comment string from the next line
|
||||||
if (startingLineIsComment && s.formatOptions.value().contains('f')) {
|
if (startingLineIsComment && s.formatOptions().contains('f')) {
|
||||||
if (characterAtCursor() == '/' && characterAt(position() + 1) == '/')
|
if (characterAtCursor() == '/' && characterAt(position() + 1) == '/')
|
||||||
moveRight(2);
|
moveRight(2);
|
||||||
else if (characterAtCursor() == '*' || characterAtCursor() == '#')
|
else if (characterAtCursor() == '*' || characterAtCursor() == '#')
|
||||||
@@ -7955,7 +7953,7 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
|
|||||||
|
|
||||||
void FakeVimHandler::Private::insertNewLine()
|
void FakeVimHandler::Private::insertNewLine()
|
||||||
{
|
{
|
||||||
if (m_buffer->editBlockLevel <= 1 && s.passKeys.value()) {
|
if (m_buffer->editBlockLevel <= 1 && s.passKeys()) {
|
||||||
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "\n");
|
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "\n");
|
||||||
if (passEventToEditor(event, m_cursor))
|
if (passEventToEditor(event, m_cursor))
|
||||||
return;
|
return;
|
||||||
@@ -7967,7 +7965,7 @@ void FakeVimHandler::Private::insertNewLine()
|
|||||||
|
|
||||||
bool FakeVimHandler::Private::handleInsertInEditor(const Input &input)
|
bool FakeVimHandler::Private::handleInsertInEditor(const Input &input)
|
||||||
{
|
{
|
||||||
if (m_buffer->editBlockLevel > 0 || !s.passKeys.value())
|
if (m_buffer->editBlockLevel > 0 || !s.passKeys())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
@@ -8712,10 +8710,10 @@ QString FakeVimHandler::Private::tabExpand(int n) const
|
|||||||
|
|
||||||
void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool forceAutoIndent)
|
void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool forceAutoIndent)
|
||||||
{
|
{
|
||||||
if (!forceAutoIndent && !s.autoIndent.value() && !s.smartIndent.value())
|
if (!forceAutoIndent && !s.autoIndent() && !s.smartIndent())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (s.smartIndent.value()) {
|
if (s.smartIndent()) {
|
||||||
QTextBlock bl = block();
|
QTextBlock bl = block();
|
||||||
Range range(bl.position(), bl.position());
|
Range range(bl.position(), bl.position());
|
||||||
indentText(range, '\n');
|
indentText(range, '\n');
|
||||||
@@ -8734,7 +8732,7 @@ void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool fo
|
|||||||
|
|
||||||
void FakeVimHandler::Private::handleStartOfLine()
|
void FakeVimHandler::Private::handleStartOfLine()
|
||||||
{
|
{
|
||||||
if (s.startOfLine.value())
|
if (s.startOfLine())
|
||||||
moveToFirstNonBlankOnLine();
|
moveToFirstNonBlankOnLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9331,7 +9329,7 @@ void FakeVimHandler::Private::getRegisterType(int *reg, bool *isClipboard, bool
|
|||||||
*reg = c.toLower().unicode();
|
*reg = c.toLower().unicode();
|
||||||
|
|
||||||
if (c == '"') {
|
if (c == '"') {
|
||||||
QStringList list = s.clipboard.value().split(',');
|
QStringList list = s.clipboard().split(',');
|
||||||
clipboard = list.contains("unnamedplus");
|
clipboard = list.contains("unnamedplus");
|
||||||
selection = list.contains("unnamed");
|
selection = list.contains("unnamed");
|
||||||
} else if (c == '+') {
|
} else if (c == '+') {
|
||||||
@@ -9385,7 +9383,7 @@ void FakeVimHandler::updateGlobalMarksFilenames(const QString &oldFileName, cons
|
|||||||
bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
|
bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
|
||||||
{
|
{
|
||||||
#ifndef FAKEVIM_STANDALONE
|
#ifndef FAKEVIM_STANDALONE
|
||||||
if (!fakeVimSettings()->useFakeVim.value())
|
if (!settings().useFakeVim())
|
||||||
return QObject::eventFilter(ob, ev);
|
return QObject::eventFilter(ob, ev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -379,7 +379,6 @@ public:
|
|||||||
int cursorPos, int anchorPos, int messageLevel);
|
int cursorPos, int anchorPos, int messageLevel);
|
||||||
void handleExCommand(FakeVimHandler *handler, bool *handled, const ExCommand &cmd);
|
void handleExCommand(FakeVimHandler *handler, bool *handled, const ExCommand &cmd);
|
||||||
|
|
||||||
void writeSettings();
|
|
||||||
void readSettings();
|
void readSettings();
|
||||||
|
|
||||||
void handleDelayedQuitAll(bool forced);
|
void handleDelayedQuitAll(bool forced);
|
||||||
@@ -1051,7 +1050,7 @@ void FakeVimPluginPrivate::initialize()
|
|||||||
|
|
||||||
Command *cmd = nullptr;
|
Command *cmd = nullptr;
|
||||||
|
|
||||||
cmd = ActionManager::registerAction(fakeVimSettings()->useFakeVim.action(),
|
cmd = ActionManager::registerAction(settings().useFakeVim.action(),
|
||||||
INSTALL_HANDLER, Context(Core::Constants::C_GLOBAL), true);
|
INSTALL_HANDLER, Context(Core::Constants::C_GLOBAL), true);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+Y,Meta+Shift+Y")
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+Y,Meta+Shift+Y")
|
||||||
: Tr::tr("Alt+Y,Alt+Y")));
|
: Tr::tr("Alt+Y,Alt+Y")));
|
||||||
@@ -1089,7 +1088,7 @@ void FakeVimPluginPrivate::initialize()
|
|||||||
connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
|
connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
|
||||||
this, &FakeVimPluginPrivate::documentRenamed);
|
this, &FakeVimPluginPrivate::documentRenamed);
|
||||||
|
|
||||||
FakeVimSettings &s = *fakeVimSettings();
|
FakeVimSettings &s = settings();
|
||||||
connect(&s.useFakeVim, &FvBoolAspect::valueChanged,
|
connect(&s.useFakeVim, &FvBoolAspect::valueChanged,
|
||||||
this, &FakeVimPluginPrivate::setUseFakeVim);
|
this, &FakeVimPluginPrivate::setUseFakeVim);
|
||||||
connect(&s.readVimRc, &FvBaseAspect::changed,
|
connect(&s.readVimRc, &FvBaseAspect::changed,
|
||||||
@@ -1107,7 +1106,7 @@ void FakeVimPluginPrivate::initialize()
|
|||||||
connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested,
|
connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested,
|
||||||
this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection);
|
this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection);
|
||||||
|
|
||||||
setCursorBlinking(s.blinkingCursor.value());
|
setCursorBlinking(s.blinkingCursor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::userActionTriggered(int key)
|
void FakeVimPluginPrivate::userActionTriggered(int key)
|
||||||
@@ -1116,7 +1115,7 @@ void FakeVimPluginPrivate::userActionTriggered(int key)
|
|||||||
FakeVimHandler *handler = m_editorToHandler[editor].handler;
|
FakeVimHandler *handler = m_editorToHandler[editor].handler;
|
||||||
if (handler) {
|
if (handler) {
|
||||||
// If disabled, enable FakeVim mode just for single user command.
|
// If disabled, enable FakeVim mode just for single user command.
|
||||||
bool enableFakeVim = !fakeVimSettings()->useFakeVim.value();
|
bool enableFakeVim = !settings().useFakeVim();
|
||||||
if (enableFakeVim)
|
if (enableFakeVim)
|
||||||
setUseFakeVimInternal(true);
|
setUseFakeVimInternal(true);
|
||||||
|
|
||||||
@@ -1142,26 +1141,18 @@ void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
|
|||||||
{
|
{
|
||||||
if (auto textEditor = TextEditorWidget::fromEditor(editor)) {
|
if (auto textEditor = TextEditorWidget::fromEditor(editor)) {
|
||||||
auto relativeNumbers = new RelativeNumbersColumn(textEditor);
|
auto relativeNumbers = new RelativeNumbersColumn(textEditor);
|
||||||
connect(&fakeVimSettings()->relativeNumber, &FvBaseAspect::changed,
|
connect(&settings().relativeNumber, &FvBaseAspect::changed,
|
||||||
relativeNumbers, &QObject::deleteLater);
|
relativeNumbers, &QObject::deleteLater);
|
||||||
connect(&fakeVimSettings()->useFakeVim, &FvBaseAspect::changed,
|
connect(&settings().useFakeVim, &FvBaseAspect::changed,
|
||||||
relativeNumbers, &QObject::deleteLater);
|
relativeNumbers, &QObject::deleteLater);
|
||||||
relativeNumbers->show();
|
relativeNumbers->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::writeSettings()
|
|
||||||
{
|
|
||||||
QSettings *settings = ICore::settings();
|
|
||||||
fakeVimSettings()->writeSettings(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FakeVimPluginPrivate::readSettings()
|
void FakeVimPluginPrivate::readSettings()
|
||||||
{
|
{
|
||||||
QSettings *settings = ICore::settings();
|
QSettings *settings = ICore::settings();
|
||||||
|
|
||||||
fakeVimSettings()->readSettings(settings);
|
|
||||||
|
|
||||||
m_exCommandMap = m_defaultExCommandMap;
|
m_exCommandMap = m_defaultExCommandMap;
|
||||||
int size = settings->beginReadArray(exCommandMapGroup);
|
int size = settings->beginReadArray(exCommandMapGroup);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
@@ -1190,9 +1181,9 @@ void FakeVimPluginPrivate::maybeReadVimRc()
|
|||||||
//qDebug() << theFakeVimSetting(ConfigReadVimRc)
|
//qDebug() << theFakeVimSetting(ConfigReadVimRc)
|
||||||
// << theFakeVimSetting(ConfigReadVimRc)->value();
|
// << theFakeVimSetting(ConfigReadVimRc)->value();
|
||||||
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
||||||
if (!fakeVimSettings()->readVimRc.value())
|
if (!settings().readVimRc())
|
||||||
return;
|
return;
|
||||||
QString fileName = fakeVimSettings()->vimRcPath.value();
|
QString fileName = settings().vimRcPath();
|
||||||
if (fileName.isEmpty()) {
|
if (fileName.isEmpty()) {
|
||||||
fileName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
|
fileName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
|
||||||
+ QLatin1String(HostOsInfo::isWindowsHost() ? "/_vimrc" : "/.vimrc");
|
+ QLatin1String(HostOsInfo::isWindowsHost() ? "/_vimrc" : "/.vimrc");
|
||||||
@@ -1202,7 +1193,6 @@ void FakeVimPluginPrivate::maybeReadVimRc()
|
|||||||
QPlainTextEdit editor;
|
QPlainTextEdit editor;
|
||||||
FakeVimHandler handler(&editor);
|
FakeVimHandler handler(&editor);
|
||||||
handler.handleCommand("source " + fileName);
|
handler.handleCommand("source " + fileName);
|
||||||
//writeSettings();
|
|
||||||
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1531,9 +1521,9 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
TabSettings tabSettings;
|
TabSettings tabSettings;
|
||||||
tabSettings.m_indentSize = fakeVimSettings()->shiftWidth();
|
tabSettings.m_indentSize = settings().shiftWidth();
|
||||||
tabSettings.m_tabSize = fakeVimSettings()->tabStop();
|
tabSettings.m_tabSize = settings().tabStop();
|
||||||
tabSettings.m_tabPolicy = fakeVimSettings()->expandTab()
|
tabSettings.m_tabPolicy = settings().expandTab()
|
||||||
? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy;
|
? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy;
|
||||||
tabSettings.m_continuationAlignBehavior =
|
tabSettings.m_continuationAlignBehavior =
|
||||||
tew->textDocument()->tabSettings().m_continuationAlignBehavior;
|
tew->textDocument()->tabSettings().m_continuationAlignBehavior;
|
||||||
@@ -1757,19 +1747,15 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
|
|||||||
*output = proc.cleanedStdOut();
|
*output = proc.cleanedStdOut();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(ICore::instance(), &ICore::saveSettingsRequested,
|
|
||||||
this, &FakeVimPluginPrivate::writeSettings);
|
|
||||||
|
|
||||||
|
|
||||||
handler->setCurrentFileName(editor->document()->filePath().toString());
|
handler->setCurrentFileName(editor->document()->filePath().toString());
|
||||||
handler->installEventFilter();
|
handler->installEventFilter();
|
||||||
|
|
||||||
// pop up the bar
|
// pop up the bar
|
||||||
if (fakeVimSettings()->useFakeVim.value()) {
|
if (settings().useFakeVim()) {
|
||||||
resetCommandBuffer();
|
resetCommandBuffer();
|
||||||
handler->setupWidget();
|
handler->setupWidget();
|
||||||
|
|
||||||
if (fakeVimSettings()->relativeNumber.value())
|
if (settings().relativeNumber())
|
||||||
createRelativeNumberWidget(editor);
|
createRelativeNumberWidget(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1811,8 +1797,8 @@ void FakeVimPluginPrivate::setUseFakeVim(bool on)
|
|||||||
//qDebug() << "SET USE FAKEVIM" << on;
|
//qDebug() << "SET USE FAKEVIM" << on;
|
||||||
Find::setUseFakeVim(on);
|
Find::setUseFakeVim(on);
|
||||||
setUseFakeVimInternal(on);
|
setUseFakeVimInternal(on);
|
||||||
setShowRelativeLineNumbers(fakeVimSettings()->relativeNumber.value());
|
setShowRelativeLineNumbers(settings().relativeNumber());
|
||||||
setCursorBlinking(fakeVimSettings()->blinkingCursor.value());
|
setCursorBlinking(settings().blinkingCursor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
|
void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
|
||||||
@@ -1840,7 +1826,7 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
|
|||||||
|
|
||||||
void FakeVimPluginPrivate::setShowRelativeLineNumbers(bool on)
|
void FakeVimPluginPrivate::setShowRelativeLineNumbers(bool on)
|
||||||
{
|
{
|
||||||
if (on && fakeVimSettings()->useFakeVim.value()) {
|
if (on && settings().useFakeVim()) {
|
||||||
for (auto it = m_editorToHandler.constBegin(); it != m_editorToHandler.constEnd(); ++it)
|
for (auto it = m_editorToHandler.constBegin(); it != m_editorToHandler.constEnd(); ++it)
|
||||||
createRelativeNumberWidget(it.key());
|
createRelativeNumberWidget(it.key());
|
||||||
}
|
}
|
||||||
@@ -1851,7 +1837,7 @@ void FakeVimPluginPrivate::setCursorBlinking(bool on)
|
|||||||
if (m_savedCursorFlashTime == 0)
|
if (m_savedCursorFlashTime == 0)
|
||||||
m_savedCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime();
|
m_savedCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime();
|
||||||
|
|
||||||
const bool blink = on || !fakeVimSettings()->useFakeVim.value();
|
const bool blink = on || !settings().useFakeVim();
|
||||||
QGuiApplication::styleHints()->setCursorFlashTime(blink ? m_savedCursorFlashTime : 0);
|
QGuiApplication::styleHints()->setCursorFlashTime(blink ? m_savedCursorFlashTime : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1995,7 +1981,7 @@ void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
|
|||||||
|
|
||||||
void FakeVimPluginPrivate::quitFakeVim()
|
void FakeVimPluginPrivate::quitFakeVim()
|
||||||
{
|
{
|
||||||
fakeVimSettings()->useFakeVim.setValue(false);
|
settings().useFakeVim.setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::resetCommandBuffer()
|
void FakeVimPluginPrivate::resetCommandBuffer()
|
||||||
|
|||||||
Reference in New Issue
Block a user