FakeVim: Aspectify settings

Change-Id: Ic73edce82e192779ed3efe86a5cb747a52d94d36
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-02-26 17:55:55 +01:00
parent 3e08210998
commit 50f93710b7
8 changed files with 401 additions and 815 deletions

View File

@@ -5,7 +5,6 @@ add_qtc_plugin(FakeVim
fakevim.qrc fakevim.qrc
fakevimactions.cpp fakevimactions.h fakevimactions.cpp fakevimactions.h
fakevimhandler.cpp fakevimhandler.h fakevimhandler.cpp fakevimhandler.h
fakevimoptions.ui
fakevimplugin.cpp fakevimplugin.h fakevimplugin.cpp fakevimplugin.h
fakevimtr.h fakevimtr.h
) )

View File

@@ -2,14 +2,15 @@
include(../../qtcreatorplugin.pri) include(../../qtcreatorplugin.pri)
QT += gui QT += gui
SOURCES += fakevimactions.cpp \ SOURCES += fakevimactions.cpp \
fakevimhandler.cpp \ fakevimhandler.cpp \
fakevimplugin.cpp fakevimplugin.cpp
HEADERS += fakevimactions.h \ HEADERS += fakevimactions.h \
fakevimhandler.h \ fakevimhandler.h \
fakevimplugin.h \ fakevimplugin.h \
fakevimtr.h fakevimtr.h
FORMS += fakevimoptions.ui
equals(TEST, 1) { equals(TEST, 1) {
SOURCES += fakevim_test.cpp SOURCES += fakevim_test.cpp

View File

@@ -21,7 +21,6 @@ QtcPlugin {
"fakevimactions.h", "fakevimactions.h",
"fakevimhandler.cpp", "fakevimhandler.cpp",
"fakevimhandler.h", "fakevimhandler.h",
"fakevimoptions.ui",
"fakevimplugin.cpp", "fakevimplugin.cpp",
"fakevimplugin.h", "fakevimplugin.h",
"fakevimtr.h", "fakevimtr.h",

View File

@@ -31,7 +31,7 @@
// Qt Creator. The idea is to keep this file here in a "clean" state that // Qt Creator. The idea is to keep this file here in a "clean" state that
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class. // allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QDebug> #include <QDebug>
@@ -41,168 +41,171 @@ using namespace Utils;
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
DummyAction::DummyAction(void *) #ifdef FAKEVIM_STANDALONE
FvBaseAspect::FvBaseAspect()
{ {
} }
void DummyAction::setValue(const QVariant &value) void FvBaseAspect::setValue(const QVariant &value)
{ {
m_value = value; m_value = value;
} }
QVariant DummyAction::value() const QVariant FvBaseAspect::value() const
{ {
return m_value; return m_value;
} }
void DummyAction::setDefaultValue(const QVariant &value) void FvBaseAspect::setDefaultValue(const QVariant &value)
{ {
m_defaultValue = value; m_defaultValue = value;
} }
QVariant DummyAction::defaultValue() const QVariant FvBaseAspect::defaultValue() const
{ {
return m_defaultValue; return m_defaultValue;
} }
void DummyAction::setSettingsKey(const QString &group, const QString &key) void FvBaseAspect::setSettingsKey(const QString &group, const QString &key)
{ {
m_settingsGroup = group; m_settingsGroup = group;
m_settingsKey = key; m_settingsKey = key;
} }
QString DummyAction::settingsKey() const QString FvBaseAspect::settingsKey() const
{ {
return m_settingsKey; return m_settingsKey;
} }
#endif
FakeVimSettings::FakeVimSettings() FakeVimSettings::FakeVimSettings()
{ {
// Specific FakeVim settings
createAction(ConfigReadVimRc, false, "ReadVimRc");
createAction(ConfigVimRcPath, QString(), "VimRcPath");
#ifndef FAKEVIM_STANDALONE #ifndef FAKEVIM_STANDALONE
createAction(ConfigUseFakeVim, false, "UseFakeVim"); setup(&useFakeVim, false, "UseFakeVim", {}, tr("Use FakeVim"));
item(ConfigUseFakeVim)->setText(tr("Use Vim-style Editing"));
item(ConfigReadVimRc)->setText(tr("Read .vimrc"));
item(ConfigVimRcPath)->setText(tr("Path to .vimrc"));
#endif #endif
createAction(ConfigShowMarks, false, "ShowMarks", "sm"); // Specific FakeVim settings
createAction(ConfigPassControlKey, false, "PassControlKey", "pck"); setup(&readVimRc, false, "ReadVimRc", {}, tr("Read .vimrc from location:"));
createAction(ConfigPassKeys, true, "PassKeys", "pk"); setup(&vimRcPath, QString(), "VimRcPath", {}, {}); // tr("Path to .vimrc")
setup(&showMarks, false, "ShowMarks", "sm", tr("Show position of text marks"));
setup(&passControlKey, false, "PassControlKey", "pck", tr("Pass control keys"));
setup(&passKeys, true, "PassKeys", "pk", tr("Pass keys in insert mode"));
// Emulated Vsetting // Emulated Vsetting
createAction(ConfigStartOfLine, true, "StartOfLine", "sol"); setup(&startOfLine, true, "StartOfLine", "sol", tr("Start of line"));
createAction(ConfigTabStop, 8, "TabStop", "ts"); setup(&tabStop, 8, "TabStop", "ts", tr("Tabulator size:"));
createAction(ConfigSmartTab, false, "SmartTab", "sta"); setup(&smartTab, false, "SmartTab", "sta", tr("Smart tabulators"));
createAction(ConfigHlSearch, true, "HlSearch", "hls"); setup(&hlSearch, true, "HlSearch", "hls", tr("Highlight search results"));
createAction(ConfigShiftWidth, 8, "ShiftWidth", "sw"); setup(&shiftWidth, 8, "ShiftWidth", "sw", tr("Shift width:"));
createAction(ConfigExpandTab, false, "ExpandTab", "et"); setup(&expandTab, false, "ExpandTab", "et", tr("Expand tabulators"));
createAction(ConfigAutoIndent, false, "AutoIndent", "ai"); setup(&autoIndent, false, "AutoIndent", "ai", tr("Automatic indentation"));
createAction(ConfigSmartIndent, false, "SmartIndent", "si"); setup(&smartIndent, false, "SmartIndent", "si", tr("Smart tabulators"));
createAction(ConfigIncSearch, true, "IncSearch", "is"); setup(&incSearch, true, "IncSearch", "is", tr("Incremental search"));
createAction(ConfigUseCoreSearch, false, "UseCoreSearch", "ucs"); setup(&useCoreSearch, false, "UseCoreSearch", "ucs", tr("Use search dialog"));
createAction(ConfigSmartCase, false, "SmartCase", "scs"); setup(&smartCase, false, "SmartCase", "scs", tr("Use smartcase"));
createAction(ConfigIgnoreCase, false, "IgnoreCase", "ic"); setup(&ignoreCase, false, "IgnoreCase", "ic", tr("Use ignorecase"));
createAction(ConfigWrapScan, true, "WrapScan", "ws"); setup(&wrapScan, true, "WrapScan", "ws", tr("Use wrapscan"));
createAction(ConfigTildeOp, false, "TildeOp", "top"); setup(&tildeOp, false, "TildeOp", "top", tr("Use tildeop"));
createAction(ConfigShowCmd, true, "ShowCmd", "sc"); setup(&showCmd, true, "ShowCmd", "sc", tr("Show partial command"));
createAction(ConfigRelativeNumber, false, "RelativeNumber", "rnu"); setup(&relativeNumber, false, "RelativeNumber", "rnu", tr("Show line numbers relative to cursor"));
createAction(ConfigBlinkingCursor, false, "BlinkingCursor", "bc"); setup(&blinkingCursor, false, "BlinkingCursor", "bc", tr("Blinking cursor"));
createAction(ConfigScrollOff, 0, "ScrollOff", "so"); setup(&scrollOff, 0, "ScrollOff", "so", tr("Scroll offset:"));
createAction(ConfigBackspace, QString("indent,eol,start"), "ConfigBackspace", "bs"); setup(&backspace, "indent,eol,start",
createAction(ConfigIsKeyword, QString("@,48-57,_,192-255,a-z,A-Z"), "IsKeyword", "isk"); "ConfigBackspace","bs", tr("Backspace:"));
createAction(ConfigClipboard, QString(), "Clipboard", "cb"); setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z",
createAction(ConfigFormatOptions, QString(), "formatoptions", "fo"); "IsKeyword", "isk", tr("Keyword characters:"));
setup(&clipboard, {}, "Clipboard", "cb", tr(""));
setup(&formatOptions, {}, "formatoptions", "fo", tr(""));
// Emulated plugins // Emulated plugins
createAction(ConfigEmulateVimCommentary, false, "commentary"); setup(&emulateVimCommentary, false, "commentary", {}, "vim-commentary");
createAction(ConfigEmulateReplaceWithRegister, false, "ReplaceWithRegister"); setup(&emulateReplaceWithRegister, false, "ReplaceWithRegister", {}, "ReplaceWithRegister");
createAction(ConfigEmulateExchange, false, "exchange"); setup(&emulateExchange, false, "exchange", {}, "vim-exchange");
createAction(ConfigEmulateArgTextObj, false, "argtextobj"); setup(&emulateArgTextObj, false, "argtextobj", {}, "argtextobj.vim");
createAction(ConfigEmulateSurround, false, "surround"); setup(&emulateSurround, false, "surround", {}, "vim-surround");
// Some polish
useFakeVim.setDisplayName(tr("Use Vim-style Editing"));
relativeNumber.setToolTip(tr("Displays line numbers relative to the line containing "
"text cursor."));
passControlKey.setToolTip(tr("Does not interpret key sequences like Ctrl-S in FakeVim "
"but handles them as regular shortcuts. This gives easier access to core functionality "
"at the price of losing some features of FakeVim."));
passKeys.setToolTip(tr("Does not interpret some key presses in insert mode so that "
"code can be properly completed and expanded."));
tabStop.setToolTip(tr("Vim tabstop option."));
#ifndef FAKEVIM_STANDALONE
backspace.setDisplayStyle(FvStringAspect::LineEditDisplay);
isKeyword.setDisplayStyle(FvStringAspect::LineEditDisplay);
const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
vimRcPath.setExpectedKind(PathChooser::File);
vimRcPath.setToolTip(tr("Keep empty to use the default path, i.e. "
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
vimRcPath.setPlaceHolderText(tr("Default: %1").arg(vimrcDefault));
vimRcPath.setDisplayStyle(FvStringAspect::PathChooserDisplay);
#endif
} }
FakeVimSettings::~FakeVimSettings() FakeVimSettings::~FakeVimSettings() = default;
{
qDeleteAll(m_items);
}
void FakeVimSettings::insertItem(int code, FakeVimAction *item, FvBaseAspect *FakeVimSettings::item(const QString &name)
const QString &longName, const QString &shortName)
{ {
QTC_ASSERT(!m_items.contains(code), qDebug() << code; return); return m_nameToAspect.value(name, nullptr);
m_items[code] = item;
if (!longName.isEmpty()) {
m_nameToCode[longName] = code;
m_codeToName[code] = longName;
}
if (!shortName.isEmpty())
m_nameToCode[shortName] = code;
}
void FakeVimSettings::readSettings(QSettings *settings)
{
foreach (FakeVimAction *item, m_items)
item->readSettings(settings);
}
void FakeVimSettings::writeSettings(QSettings *settings)
{
foreach (FakeVimAction *item, m_items)
item->writeSettings(settings);
}
FakeVimAction *FakeVimSettings::item(int code)
{
QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return nullptr);
return m_items.value(code, 0);
}
FakeVimAction *FakeVimSettings::item(const QString &name)
{
return m_items.value(m_nameToCode.value(name, -1), 0);
} }
QString FakeVimSettings::trySetValue(const QString &name, const QString &value) QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
{ {
int code = m_nameToCode.value(name, -1); FvBaseAspect *aspect = m_nameToAspect.value(name, nullptr);
if (code == -1) if (!aspect)
return tr("Unknown option: %1").arg(name); return tr("Unknown option: %1").arg(name);
if (code == ConfigTabStop || code == ConfigShiftWidth) { if (aspect == &tabStop || aspect == &shiftWidth) {
if (value.toInt() <= 0) if (value.toInt() <= 0)
return tr("Argument must be positive: %1=%2") return tr("Argument must be positive: %1=%2")
.arg(name).arg(value); .arg(name).arg(value);
} }
FakeVimAction *act = item(code); aspect->setValue(value);
if (!act)
return tr("Unknown option: %1").arg(name);
act->setValue(value);
return QString(); return QString();
} }
void FakeVimSettings::createAction(int code, const QVariant &value, void FakeVimSettings::setup(FvBaseAspect *aspect,
const QString &settingsKey, const QVariant &value,
const QString &shortKey) const QString &settingsKey,
const QString &shortName,
const QString &labelText)
{ {
auto item = new FakeVimAction(nullptr); aspect->setSettingsKey("FakeVim", settingsKey);
item->setValue(value); aspect->setDefaultValue(value);
item->setSettingsKey("FakeVim", settingsKey); #ifndef FAKEVIM_STANDALONE
item->setDefaultValue(value); aspect->setLabelText(labelText);
item->setCheckable(value.canConvert<bool>()); aspect->setAutoApply(false);
insertItem(code, item, settingsKey.toLower(), shortKey); registerAspect(aspect);
if (auto boolAspect = dynamic_cast<FvBoolAspect *>(aspect))
boolAspect->setLabelPlacement(FvBoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
#else
Q_UNUSED(labelText)
#endif
const QString longName = settingsKey.toLower();
if (!longName.isEmpty()) {
m_nameToAspect[longName] = aspect;
m_aspectToName[aspect] = longName;
}
if (!shortName.isEmpty())
m_nameToAspect[shortName] = aspect;
} }
FakeVimSettings *theFakeVimSettings() FakeVimSettings *fakeVimSettings()
{ {
static FakeVimSettings s; static FakeVimSettings s;
return &s; return &s;
} }
FakeVimAction *theFakeVimSetting(int code)
{
return theFakeVimSettings()->item(code);
}
} // namespace Internal } // namespace Internal
} // namespace FakeVim } // namespace FakeVim

View File

@@ -26,23 +26,25 @@
#pragma once #pragma once
#ifndef FAKEVIM_STANDALONE #ifndef FAKEVIM_STANDALONE
# include <utils/savedaction.h> # include <utils/aspects.h>
#endif #endif
#include <QCoreApplication> #include <QCoreApplication>
#include <QHash> #include <QHash>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QSettings>
#include <QVariant> #include <QVariant>
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
class DummyAction #ifdef FAKEVIM_STANDALONE
class FvBaseAspect
{ {
public: public:
DummyAction(void *parent); FvBaseAspect();
virtual ~FvBaseAspect() {}
void setValue(const QVariant &value); void setValue(const QVariant &value);
QVariant value() const; QVariant value() const;
void setDefaultValue(const QVariant &value); void setDefaultValue(const QVariant &value);
@@ -50,105 +52,121 @@ public:
void setSettingsKey(const QString &group, const QString &key); void setSettingsKey(const QString &group, const QString &key);
QString settingsKey() const; QString settingsKey() const;
void setCheckable(bool) {} void setCheckable(bool) {}
void setDisplayName(const QString &) {}
void setToolTip(const QString &) {}
void readSettings(QSettings *) {} private:
void writeSettings(QSettings *) {}
QVariant m_value; QVariant m_value;
QVariant m_defaultValue; QVariant m_defaultValue;
QString m_settingsGroup; QString m_settingsGroup;
QString m_settingsKey; QString m_settingsKey;
}; };
#ifdef FAKEVIM_STANDALONE class FvBoolAspect : public FvBaseAspect
using FakeVimAction = DummyAction;
#else
using FakeVimAction = Utils::SavedAction;
#endif
enum FakeVimSettingsCode
{ {
ConfigUseFakeVim, public:
ConfigReadVimRc, bool value() const { return FvBaseAspect::value().toBool(); }
ConfigVimRcPath,
ConfigStartOfLine,
ConfigHlSearch,
ConfigTabStop,
ConfigSmartTab,
ConfigShiftWidth,
ConfigExpandTab,
ConfigAutoIndent,
ConfigSmartIndent,
ConfigIncSearch,
ConfigUseCoreSearch,
ConfigSmartCase,
ConfigIgnoreCase,
ConfigWrapScan,
// command ~ behaves as g~
ConfigTildeOp,
// indent allow backspacing over autoindent
// eol allow backspacing over line breaks (join lines)
// start allow backspacing over the start of insert; CTRL-W and CTRL-U
// stop once at the start of insert.
ConfigBackspace,
// @,48-57,_,192-255
ConfigIsKeyword,
// other actions
ConfigShowMarks,
ConfigPassControlKey,
ConfigPassKeys,
ConfigClipboard,
ConfigShowCmd,
ConfigScrollOff,
ConfigRelativeNumber,
ConfigFormatOptions,
// Plugin emulation
ConfigEmulateVimCommentary,
ConfigEmulateReplaceWithRegister,
ConfigEmulateExchange,
ConfigEmulateArgTextObj,
ConfigEmulateSurround,
ConfigBlinkingCursor
}; };
class FakeVimSettings class FvIntegerAspect : public FvBaseAspect
{
public:
qint64 value() const { return FvBaseAspect::value().toLongLong(); }
};
class FvStringAspect : public FvBaseAspect
{
public:
QString value() const { return FvBaseAspect::value().toString(); }
};
class FvAspectContainer : public FvBaseAspect
{
public:
};
#else
using FvAspectContainer = Utils::AspectContainer;
using FvBaseAspect = Utils::BaseAspect;
using FvBoolAspect = Utils::BoolAspect;
using FvIntegerAspect = Utils::IntegerAspect;
using FvStringAspect = Utils::StringAspect;
#endif
class FakeVimSettings final : public FvAspectContainer
{ {
Q_DECLARE_TR_FUNCTIONS(FakeVim) Q_DECLARE_TR_FUNCTIONS(FakeVim)
public: public:
FakeVimSettings(); FakeVimSettings();
~FakeVimSettings(); ~FakeVimSettings();
void insertItem(int code, FakeVimAction *item,
const QString &longname = QString(),
const QString &shortname = QString());
FakeVimAction *item(int code); FvBaseAspect *item(const QString &name);
FakeVimAction *item(const QString &name);
QString trySetValue(const QString &name, const QString &value); QString trySetValue(const QString &name, const QString &value);
void readSettings(QSettings *settings); FvBoolAspect useFakeVim;
void writeSettings(QSettings *settings); FvBoolAspect readVimRc;
FvStringAspect vimRcPath;
FvBoolAspect startOfLine;
FvIntegerAspect tabStop;
FvBoolAspect hlSearch;
FvBoolAspect smartTab;
FvIntegerAspect shiftWidth;
FvBoolAspect expandTab;
FvBoolAspect autoIndent;
FvBoolAspect smartIndent;
FvBoolAspect incSearch;
FvBoolAspect useCoreSearch;
FvBoolAspect smartCase;
FvBoolAspect ignoreCase;
FvBoolAspect wrapScan;
// command ~ behaves as g~
FvBoolAspect tildeOp;
// indent allow backspacing over autoindent
// eol allow backspacing over line breaks (join lines)
// start allow backspacing over the start of insert; CTRL-W and CTRL-U
// stop once at the start of insert.
FvStringAspect backspace;
// @,48-57,_,192-255
FvStringAspect isKeyword;
// other actions
FvBoolAspect showMarks;
FvBoolAspect passControlKey;
FvBoolAspect passKeys;
FvStringAspect clipboard;
FvBoolAspect showCmd;
FvIntegerAspect scrollOff;
FvBoolAspect relativeNumber;
FvStringAspect formatOptions;
// Plugin emulation
FvBoolAspect emulateVimCommentary;
FvBoolAspect emulateReplaceWithRegister;
FvBoolAspect emulateExchange;
FvBoolAspect emulateArgTextObj;
FvBoolAspect emulateSurround;
FvBoolAspect blinkingCursor;
private: private:
void createAction(int code, const QVariant &value, void setup(FvBaseAspect *aspect, const QVariant &value,
const QString &settingsKey = QString(), const QString &settingsKey,
const QString &shortKey = QString()); const QString &shortName,
const QString &label);
QHash<int, FakeVimAction *> m_items; QHash<QString, FvBaseAspect *> m_nameToAspect;
QHash<QString, int> m_nameToCode; QHash<FvBaseAspect *, QString> m_aspectToName;
QHash<int, QString> m_codeToName;
}; };
FakeVimSettings *theFakeVimSettings(); FakeVimSettings *fakeVimSettings();
FakeVimAction *theFakeVimSetting(int code);
} // namespace Internal } // namespace Internal
} // namespace FakeVim } // namespace FakeVim

View File

@@ -289,21 +289,6 @@ QDebug operator<<(QDebug ts, const CursorPosition &pos)
} }
// vi style configuration // vi style configuration
static QVariant config(int code)
{
return theFakeVimSetting(code)->value();
}
static bool hasConfig(int code)
{
return config(code).toBool();
}
static bool hasConfig(int code, const QString &value)
{
return config(code).toString().contains(value);
}
class Mark class Mark
{ {
@@ -447,8 +432,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 = hasConfig(ConfigIgnoreCase); const bool ignoreCaseOption = fakeVimSettings()->ignoreCase.value();
const bool smartCaseOption = hasConfig(ConfigSmartCase); const bool smartCaseOption = fakeVimSettings()->smartCase.value();
const bool initialIgnoreCase = ignoreCaseOption const bool initialIgnoreCase = ignoreCaseOption
&& !(smartCaseOption && needle.contains(QRegularExpression("[A-Z]"))); && !(smartCaseOption && needle.contains(QRegularExpression("[A-Z]")));
@@ -2443,6 +2428,8 @@ public:
bool surroundUpperCaseS; // True for yS and cS, false otherwise bool surroundUpperCaseS; // True for yS and cS, false otherwise
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();
}; };
FakeVimHandler::Private::GlobalData FakeVimHandler::Private::g; FakeVimHandler::Private::GlobalData FakeVimHandler::Private::g;
@@ -2581,7 +2568,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 (hasConfig(ConfigShowMarks)) if (s.showMarks.value())
updateSelection(); updateSelection();
updateMiniBuffer(); updateMiniBuffer();
@@ -2630,7 +2617,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)
&& !config(ConfigPassControlKey).toBool() && !s.passControlKey.value()
&& ((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
@@ -2840,7 +2827,7 @@ void FakeVimHandler::Private::ensureCursorVisible()
void FakeVimHandler::Private::updateEditor() void FakeVimHandler::Private::updateEditor()
{ {
setTabSize(config(ConfigTabStop).toInt()); setTabSize(s.tabStop.value());
setupCharClass(); setupCharClass();
} }
@@ -3113,7 +3100,7 @@ void FakeVimHandler::Private::stopIncrementalFind()
void FakeVimHandler::Private::updateFind(bool isComplete) void FakeVimHandler::Private::updateFind(bool isComplete)
{ {
if (!isComplete && !hasConfig(ConfigIncSearch)) if (!isComplete && !s.incSearch.value())
return; return;
g.currentMessage.clear(); g.currentMessage.clear();
@@ -3215,7 +3202,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 && hasConfig(ConfigStartOfLine)) { } else if (g.movetype == MoveLineWise && s.startOfLine.value()) {
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) {
@@ -3675,8 +3662,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 } else if (g.submode == ReplaceWithRegisterSubMode && s.emulateReplaceWithRegister.value()) {
&& hasConfig(ConfigEmulateReplaceWithRegister)) {
pushUndoState(false); pushUndoState(false);
beginEditBlock(); beginEditBlock();
replaceWithRegister(currentRange()); replaceWithRegister(currentRange());
@@ -3789,7 +3775,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 (hasConfig(ConfigShowMarks)) { if (s.showMarks.value()) {
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;
@@ -3808,7 +3794,7 @@ void FakeVimHandler::Private::updateSelection()
void FakeVimHandler::Private::updateHighlights() void FakeVimHandler::Private::updateHighlights()
{ {
if (hasConfig(ConfigUseCoreSearch) || !hasConfig(ConfigHlSearch) || g.highlightsCleared) { if (s.useCoreSearch.value() || !s.hlSearch.value() || g.highlightsCleared) {
if (m_highlighted.isEmpty()) if (m_highlighted.isEmpty())
return; return;
m_highlighted.clear(); m_highlighted.clear();
@@ -3855,7 +3841,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() && hasConfig(ConfigShowCmd)) { } else if (g.mode == CommandMode && !g.currentCommand.isEmpty() && s.showCmd.value()) {
msg = g.currentCommand; msg = g.currentCommand;
messageLevel = MessageShowCmd; messageLevel = MessageShowCmd;
} else if (g.mode == CommandMode && isVisualMode()) { } else if (g.mode == CommandMode && isVisualMode()) {
@@ -3962,7 +3948,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') && hasConfig(ConfigEmulateArgTextObj)) else if (input.is('a') && s.emulateArgTextObj.value())
handled = selectArgumentTextObject(g.subsubdata.is('i')); handled = selectArgumentTextObject(g.subsubdata.is('i'));
else else
handled = false; handled = false;
@@ -4105,7 +4091,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 (hasConfig(ConfigUseCoreSearch)) { if (s.useCoreSearch.value()) {
// re-use the core dialog. // re-use the core dialog.
g.findPending = true; g.findPending = true;
m_findStartPosition = position(); m_findStartPosition = position();
@@ -4280,7 +4266,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 (hasConfig(ConfigUseCoreSearch)) { if (s.useCoreSearch.value()) {
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);
@@ -4369,7 +4355,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') && hasConfig(ConfigEmulateExchange)) { } else if (g.submode == ChangeSubMode && input.is('x') && s.emulateExchange.value()) {
// 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;
@@ -4379,15 +4365,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'))
&& hasConfig(ConfigEmulateSurround)) { && s.emulateSurround.value()) {
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') && hasConfig(ConfigEmulateSurround)) { } else if (g.submode == DeleteSubMode && input.is('s') && s.emulateSurround.value()) {
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'))
&& hasConfig(ConfigEmulateSurround)) { && s.emulateSurround.value()) {
g.submode = AddSurroundingSubMode; g.submode = AddSurroundingSubMode;
g.movetype = MoveInclusive; g.movetype = MoveInclusive;
g.surroundUpperCaseS = input.is('S'); g.surroundUpperCaseS = input.is('S');
@@ -4396,10 +4382,10 @@ 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 && hasConfig(ConfigEmulateVimCommentary)) { } else if (g.submode == CommentSubMode && s.emulateVimCommentary.value()) {
handled = handleCommentSubMode(input); handled = handleCommentSubMode(input);
} else if (g.submode == ReplaceWithRegisterSubMode } else if (g.submode == ReplaceWithRegisterSubMode
&& hasConfig(ConfigEmulateReplaceWithRegister)) { && 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);
@@ -4542,7 +4528,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') && hasConfig(ConfigEmulateVimCommentary)) { } else if (g.gflag && input.is('c') && s.emulateVimCommentary.value()) {
if (isVisualMode()) { if (isVisualMode()) {
pushUndoState(); pushUndoState();
@@ -4567,7 +4553,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
pushUndoState(); pushUndoState();
setAnchor(); setAnchor();
} }
} else if (g.gflag && input.is('r') && hasConfig(ConfigEmulateReplaceWithRegister)) { } else if (g.gflag && input.is('r') && s.emulateReplaceWithRegister.value()) {
g.submode = ReplaceWithRegisterSubMode; g.submode = ReplaceWithRegisterSubMode;
if (isVisualMode()) { if (isVisualMode()) {
dotCommand = visualDotCommand() + QString::number(count()) + "gr"; dotCommand = visualDotCommand() + QString::number(count()) + "gr";
@@ -4726,7 +4712,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() && hasConfig(ConfigEmulateSurround)) { } else if (input.is('S') && isVisualMode() && s.emulateSurround.value()) {
g.submode = AddSurroundingSubMode; g.submode = AddSurroundingSubMode;
g.subsubmode = SurroundSubSubMode; g.subsubmode = SurroundSubSubMode;
} else if (input.is('s')) { } else if (input.is('s')) {
@@ -4811,7 +4797,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
if (isVisualMode()) { if (isVisualMode()) {
leaveVisualMode(); leaveVisualMode();
finishMovement(); finishMovement();
} else if (g.gflag || (g.submode == InvertCaseSubMode && hasConfig(ConfigTildeOp))) { } else if (g.gflag || (g.submode == InvertCaseSubMode && s.tildeOp.value())) {
if (atEndOfLine()) if (atEndOfLine())
moveLeft(); moveLeft();
setAnchor(); setAnchor();
@@ -5457,15 +5443,15 @@ 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()
|| hasConfig(ConfigBackspace, "start") || s.backspace.value().contains("start")
|| hasConfig(ConfigBackspace, "2")) { || s.backspace.value().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);
const Column ind = indentation(data); const Column ind = indentation(data);
if (col.logical <= ind.logical && col.logical if (col.logical <= ind.logical && col.logical
&& startsWithWhitespace(data, col.physical)) { && startsWithWhitespace(data, col.physical)) {
const int ts = config(ConfigTabStop).toInt(); const int ts = s.tabStop.value();
const int newl = col.logical - 1 - (col.logical - 1) % ts; const int newl = col.logical - 1 - (col.logical - 1) % ts;
const QString prefix = tabExpand(newl); const QString prefix = tabExpand(newl);
setLineContents(line, prefix + data.mid(col.physical)); setLineContents(line, prefix + data.mid(col.physical));
@@ -5490,8 +5476,8 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
movePageUp(); movePageUp();
} else if (input.isKey(Key_Tab)) { } else if (input.isKey(Key_Tab)) {
m_buffer->insertState.insertingSpaces = true; m_buffer->insertState.insertingSpaces = true;
if (hasConfig(ConfigExpandTab)) { if (s.expandTab.value()) {
const int ts = config(ConfigTabStop).toInt(); const int ts = s.tabStop.value();
const int col = logicalCursorColumn(); const int col = logicalCursorColumn();
QString str = QString(ts - col % ts, ' '); QString str = QString(ts - col % ts, ' ');
insertText(str); insertText(str);
@@ -5501,8 +5487,8 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
m_buffer->insertState.insertingSpaces = false; m_buffer->insertState.insertingSpaces = false;
} else if (input.isControl('d')) { } else if (input.isControl('d')) {
// remove one level of indentation from the current line // remove one level of indentation from the current line
int shift = config(ConfigShiftWidth).toInt(); const int shift = s.shiftWidth.value();
int tab = config(ConfigTabStop).toInt(); const int tab = s.tabStop.value();
int line = cursorLine() + 1; int line = cursorLine() + 1;
int pos = firstPositionInLine(line); int pos = firstPositionInLine(line);
QString text = lineContents(line); QString text = lineContents(line);
@@ -5545,7 +5531,7 @@ void FakeVimHandler::Private::insertInInsertMode(const QString &text)
{ {
joinPreviousEditBlock(); joinPreviousEditBlock();
insertText(text); insertText(text);
if (hasConfig(ConfigSmartIndent) && isElectricCharacter(text.at(0))) { if (s.smartIndent.value() && 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()) {
@@ -6174,8 +6160,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
if (cmd.args.contains('=')) { if (cmd.args.contains('=')) {
// Non-boolean config to set. // Non-boolean config to set.
int p = cmd.args.indexOf('='); int p = cmd.args.indexOf('=');
QString error = theFakeVimSettings() QString error = s.trySetValue(cmd.args.left(p), cmd.args.mid(p + 1));
->trySetValue(cmd.args.left(p), cmd.args.mid(p + 1));
if (!error.isEmpty()) if (!error.isEmpty())
showMessage(MessageError, error); showMessage(MessageError, error);
} else { } else {
@@ -6190,7 +6175,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
if (negateOption) if (negateOption)
optionName.remove(0, 2); optionName.remove(0, 2);
FakeVimAction *act = theFakeVimSettings()->item(optionName); FvBaseAspect *act = s.item(optionName);
if (!act) { if (!act) {
showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args); showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args);
} else if (act->defaultValue().type() == QVariant::Bool) { } else if (act->defaultValue().type() == QVariant::Bool) {
@@ -6317,7 +6302,7 @@ bool FakeVimHandler::Private::handleExMoveCommand(const ExCommand &cmd)
if (!insertAtEnd) if (!insertAtEnd)
moveUp(1); moveUp(1);
if (hasConfig(ConfigStartOfLine)) if (s.startOfLine.value())
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
if (lastAnchor.line >= startLine && lastAnchor.line <= endLine) if (lastAnchor.line >= startLine && lastAnchor.line <= endLine)
@@ -6790,7 +6775,7 @@ QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos,
} }
if (tc.isNull()) { if (tc.isNull()) {
if (hasConfig(ConfigWrapScan)) { if (s.wrapScan.value()) {
tc = QTextCursor(document()); tc = QTextCursor(document());
tc.movePosition(sd.forward ? StartOfDocument : EndOfDocument); tc.movePosition(sd.forward ? StartOfDocument : EndOfDocument);
if (sd.forward) if (sd.forward)
@@ -6950,10 +6935,10 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat)
std::swap(beginLine, endLine); std::swap(beginLine, endLine);
targetPos = position(); targetPos = position();
} }
if (hasConfig(ConfigStartOfLine)) if (s.startOfLine.value())
targetPos = firstPositionInLine(beginLine); targetPos = firstPositionInLine(beginLine);
const int sw = config(ConfigShiftWidth).toInt(); const int sw = s.shiftWidth.value();
g.movetype = MoveLineWise; g.movetype = MoveLineWise;
beginEditBlock(); beginEditBlock();
QTextBlock block = document()->findBlockByLineNumber(beginLine - 1); QTextBlock block = document()->findBlockByLineNumber(beginLine - 1);
@@ -7102,7 +7087,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 = config(ConfigIsKeyword).toString(); const QString conf = s.isKeyword.value();
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));
@@ -7291,7 +7276,7 @@ int FakeVimHandler::Private::physicalCursorColumn() const
int FakeVimHandler::Private::physicalToLogicalColumn int FakeVimHandler::Private::physicalToLogicalColumn
(const int physical, const QString &line) const (const int physical, const QString &line) const
{ {
const int ts = config(ConfigTabStop).toInt(); const int ts = s.tabStop.value();
int p = 0; int p = 0;
int logical = 0; int logical = 0;
while (p < physical) { while (p < physical) {
@@ -7312,7 +7297,7 @@ int FakeVimHandler::Private::physicalToLogicalColumn
int FakeVimHandler::Private::logicalToPhysicalColumn int FakeVimHandler::Private::logicalToPhysicalColumn
(const int logical, const QString &line) const (const int logical, const QString &line) const
{ {
const int ts = config(ConfigTabStop).toInt(); const int ts = s.tabStop.value();
int physical = 0; int physical = 0;
for (int l = 0; l < logical && physical < line.size(); ++physical) { for (int l = 0; l < logical && physical < line.size(); ++physical) {
QChar c = line.at(physical); QChar c = line.at(physical);
@@ -7326,7 +7311,7 @@ int FakeVimHandler::Private::logicalToPhysicalColumn
int FakeVimHandler::Private::windowScrollOffset() const int FakeVimHandler::Private::windowScrollOffset() const
{ {
return qMin(theFakeVimSetting(ConfigScrollOff)->value().toInt(), linesOnScreen() / 2); return qMin(static_cast<int>(s.scrollOff.value()), linesOnScreen() / 2);
} }
int FakeVimHandler::Private::logicalCursorColumn() const int FakeVimHandler::Private::logicalCursorColumn() const
@@ -7590,7 +7575,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 (hasConfig(ConfigPassKeys)) { if (s.passKeys.value()) {
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);
@@ -7932,7 +7917,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 && config(ConfigFormatOptions).toString().contains('f')) { if (startingLineIsComment && s.formatOptions.value().contains('f')) {
if (characterAtCursor() == '/' && characterAt(position() + 1) == '/') if (characterAtCursor() == '/' && characterAt(position() + 1) == '/')
moveRight(2); moveRight(2);
else if (characterAtCursor() == '*' || characterAtCursor() == '#') else if (characterAtCursor() == '*' || characterAtCursor() == '#')
@@ -7950,7 +7935,7 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
void FakeVimHandler::Private::insertNewLine() void FakeVimHandler::Private::insertNewLine()
{ {
if ( m_buffer->editBlockLevel <= 1 && hasConfig(ConfigPassKeys) ) { if (m_buffer->editBlockLevel <= 1 && s.passKeys.value()) {
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;
@@ -7962,7 +7947,7 @@ void FakeVimHandler::Private::insertNewLine()
bool FakeVimHandler::Private::handleInsertInEditor(const Input &input) bool FakeVimHandler::Private::handleInsertInEditor(const Input &input)
{ {
if (m_buffer->editBlockLevel > 0 || !hasConfig(ConfigPassKeys)) if (m_buffer->editBlockLevel > 0 || !s.passKeys.value())
return false; return false;
joinPreviousEditBlock(); joinPreviousEditBlock();
@@ -8649,7 +8634,7 @@ void FakeVimHandler::Private::jump(int distance)
Column FakeVimHandler::Private::indentation(const QString &line) const Column FakeVimHandler::Private::indentation(const QString &line) const
{ {
int ts = config(ConfigTabStop).toInt(); int ts = s.tabStop.value();
int physical = 0; int physical = 0;
int logical = 0; int logical = 0;
int n = line.size(); int n = line.size();
@@ -8668,8 +8653,8 @@ Column FakeVimHandler::Private::indentation(const QString &line) const
QString FakeVimHandler::Private::tabExpand(int n) const QString FakeVimHandler::Private::tabExpand(int n) const
{ {
int ts = config(ConfigTabStop).toInt(); int ts = s.tabStop.value();
if (hasConfig(ConfigExpandTab) || ts < 1) if (s.expandTab.value() || ts < 1)
return QString(n, ' '); return QString(n, ' ');
return QString(n / ts, '\t') return QString(n / ts, '\t')
+ QString(n % ts, ' '); + QString(n % ts, ' ');
@@ -8677,10 +8662,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 && !hasConfig(ConfigAutoIndent) && !hasConfig(ConfigSmartIndent)) if (!forceAutoIndent && !s.autoIndent.value() && !s.smartIndent.value())
return; return;
if (hasConfig(ConfigSmartIndent)) { if (s.smartIndent.value()) {
QTextBlock bl = block(); QTextBlock bl = block();
Range range(bl.position(), bl.position()); Range range(bl.position(), bl.position());
indentText(range, '\n'); indentText(range, '\n');
@@ -8699,7 +8684,7 @@ void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool fo
void FakeVimHandler::Private::handleStartOfLine() void FakeVimHandler::Private::handleStartOfLine()
{ {
if (hasConfig(ConfigStartOfLine)) if (s.startOfLine.value())
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
} }
@@ -9296,7 +9281,7 @@ void FakeVimHandler::Private::getRegisterType(int *reg, bool *isClipboard, bool
*reg = c.toLower().unicode(); *reg = c.toLower().unicode();
if (c == '"') { if (c == '"') {
QStringList list = config(ConfigClipboard).toString().split(','); QStringList list = s.clipboard.value().split(',');
clipboard = list.contains("unnamedplus"); clipboard = list.contains("unnamedplus");
selection = list.contains("unnamed"); selection = list.contains("unnamed");
} else if (c == '+') { } else if (c == '+') {
@@ -9350,7 +9335,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 (!theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) if (!fakeVimSettings()->useFakeVim.value())
return QObject::eventFilter(ob, ev); return QObject::eventFilter(ob, ev);
#endif #endif

View File

@@ -1,443 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FakeVim::Internal::FakeVimOptionPage</class>
<widget class="QWidget" name="FakeVim::Internal::FakeVimOptionPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>568</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkBoxUseFakeVim">
<property name="text">
<string>Use FakeVim</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="behaviorBox">
<property name="title">
<string>Vim Behavior</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxIgnoreCase">
<property name="text">
<string>Use ignorecase</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkBoxSmartCase">
<property name="text">
<string>Use smartcase</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBoxStartOfLine">
<property name="text">
<string>Start of line</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="checkBoxSmartTab">
<property name="text">
<string>Smart tabulators</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBoxUseCoreSearch">
<property name="text">
<string>Use search dialog</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="checkBoxRelativeNumber">
<property name="toolTip">
<string>Displays line numbers relative to the line containing text cursor.</string>
</property>
<property name="text">
<string>Show line numbers relative to cursor</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBoxHlSearch">
<property name="text">
<string>Highlight search results</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBoxIncSearch">
<property name="text">
<string>Incremental search</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="checkBoxShowMarks">
<property name="text">
<string>Show position of text marks</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="checkBoxPassControlKey">
<property name="toolTip">
<string>Does not interpret key sequences like Ctrl-S in FakeVim but handles them as regular shortcuts. This gives easier access to core functionality at the price of losing some features of FakeVim.</string>
</property>
<property name="text">
<string>Pass control key</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
<string>Automatic indentation</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkBoxShowCmd">
<property name="text">
<string>Show partial command</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="checkBoxBlinkingCursor">
<property name="text">
<string>Blinking cursor</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxExpandTab">
<property name="text">
<string>Expand tabulators</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="checkBoxWrapScan">
<property name="text">
<string>Use wrapscan</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="checkBoxPassKeys">
<property name="toolTip">
<string>Does not interpret some key presses in insert mode so that code can be properly completed and expanded.</string>
</property>
<property name="text">
<string>Pass keys in insert mode</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxSmartIndent">
<property name="text">
<string>Smart indentation</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Plugin Emulation</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QCheckBox" name="checkBoxExchange">
<property name="text">
<string>vim-exchange</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxArgTextObj">
<property name="text">
<string>argtextobj.vim</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxReplaceWithRegister">
<property name="text">
<string>ReplaceWithRegister</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxVimCommentary">
<property name="text">
<string>vim-commentary</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBoxVimSurround">
<property name="text">
<string>vim-surround</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="labelShiftWidth">
<property name="text">
<string>Shift width:</string>
</property>
<property name="buddy">
<cstring>spinBoxShiftWidth</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxShiftWidth">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>80</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelTabulator">
<property name="toolTip">
<string>Vim tabstop option.</string>
</property>
<property name="text">
<string>Tabulator size:</string>
</property>
<property name="buddy">
<cstring>spinBoxTabStop</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxTabStop">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>80</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelScrollOff">
<property name="text">
<string>Scroll offset:</string>
</property>
<property name="buddy">
<cstring>spinBoxScrollOff</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxScrollOff"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelBackspace">
<property name="text">
<string>Backspace:</string>
</property>
<property name="buddy">
<cstring>lineEditBackspace</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditBackspace"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelIsKeyword">
<property name="text">
<string>Keyword characters:</string>
</property>
<property name="buddy">
<cstring>lineEditIsKeyword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditIsKeyword"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxReadVimRc">
<property name="text">
<string>Read .vimrc from location:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Utils::PathChooser" name="pathChooserVimRcPath" native="true"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonCopyTextEditorSettings">
<property name="text">
<string>Copy Text Editor Settings</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSetQtStyle">
<property name="text">
<string>Set Qt Style</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSetPlainStyle">
<property name="text">
<string>Set Plain Style</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>checkBoxUseFakeVim</tabstop>
<tabstop>checkBoxAutoIndent</tabstop>
<tabstop>checkBoxSmartIndent</tabstop>
<tabstop>checkBoxExpandTab</tabstop>
<tabstop>checkBoxSmartTab</tabstop>
<tabstop>checkBoxHlSearch</tabstop>
<tabstop>checkBoxShowCmd</tabstop>
<tabstop>checkBoxStartOfLine</tabstop>
<tabstop>checkBoxPassKeys</tabstop>
<tabstop>checkBoxIncSearch</tabstop>
<tabstop>checkBoxUseCoreSearch</tabstop>
<tabstop>checkBoxIgnoreCase</tabstop>
<tabstop>checkBoxSmartCase</tabstop>
<tabstop>checkBoxWrapScan</tabstop>
<tabstop>checkBoxShowMarks</tabstop>
<tabstop>checkBoxPassControlKey</tabstop>
<tabstop>checkBoxRelativeNumber</tabstop>
<tabstop>spinBoxShiftWidth</tabstop>
<tabstop>spinBoxTabStop</tabstop>
<tabstop>spinBoxScrollOff</tabstop>
<tabstop>lineEditBackspace</tabstop>
<tabstop>lineEditIsKeyword</tabstop>
<tabstop>checkBoxReadVimRc</tabstop>
<tabstop>pathChooserVimRcPath</tabstop>
<tabstop>pushButtonCopyTextEditorSettings</tabstop>
<tabstop>pushButtonSetQtStyle</tabstop>
<tabstop>pushButtonSetPlainStyle</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -28,7 +28,6 @@
#include "fakevimactions.h" #include "fakevimactions.h"
#include "fakevimhandler.h" #include "fakevimhandler.h"
#include "fakevimtr.h" #include "fakevimtr.h"
#include "ui_fakevimoptions.h"
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
@@ -67,26 +66,31 @@
#include <texteditor/codeassist/assistinterface.h> #include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/genericproposal.h> #include <texteditor/codeassist/genericproposal.h>
#include <utils/aspects.h>
#include <utils/fancylineedit.h> #include <utils/fancylineedit.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/layoutbuilder.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/savedaction.h> #include <utils/qtcassert.h>
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <QAction>
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QGridLayout>
#include <QGroupBox>
#include <QGuiApplication> #include <QGuiApplication>
#include <QItemDelegate> #include <QItemDelegate>
#include <QPainter> #include <QPainter>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QPointer> #include <QPointer>
#include <QPushButton>
#include <QRegularExpression> #include <QRegularExpression>
#include <QScrollBar> #include <QScrollBar>
#include <QSettings> #include <QSettings>
@@ -380,129 +384,149 @@ private:
void updateVimRcWidgets(); void updateVimRcWidgets();
QPointer<QWidget> m_widget; QPointer<QWidget> m_widget;
Ui::FakeVimOptionPage m_ui;
SavedActionSet m_group;
}; };
QWidget *FakeVimOptionPage::widget() QWidget *FakeVimOptionPage::widget()
{ {
if (!m_widget) { if (!m_widget) {
m_widget = new QWidget; m_widget = new QWidget;
m_ui.setupUi(m_widget);
const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
m_ui.pathChooserVimRcPath->setExpectedKind(PathChooser::File);
m_ui.pathChooserVimRcPath->lineEdit()->setToolTip(Tr::tr("Keep empty to use the default path, i.e. "
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(Tr::tr("Default: %1").arg(vimrcDefault));
m_group.clear(); auto copyTextEditorSettings = new QPushButton(tr("Copy Text Editor Settings"));
m_group.insert(theFakeVimSetting(ConfigUseFakeVim), m_ui.checkBoxUseFakeVim); auto setQtStyle = new QPushButton(tr("Set Qt Style"));
m_group.insert(theFakeVimSetting(ConfigReadVimRc), m_ui.checkBoxReadVimRc); auto setPlainStyle = new QPushButton(tr("Set Plain Style"));
m_group.insert(theFakeVimSetting(ConfigVimRcPath), m_ui.pathChooserVimRcPath);
m_group.insert(theFakeVimSetting(ConfigExpandTab), m_ui.checkBoxExpandTab); using namespace Layouting;
m_group.insert(theFakeVimSetting(ConfigHlSearch), m_ui.checkBoxHlSearch); FakeVimSettings &s = *fakeVimSettings();
m_group.insert(theFakeVimSetting(ConfigShiftWidth), m_ui.spinBoxShiftWidth);
m_group.insert(theFakeVimSetting(ConfigShowMarks), m_ui.checkBoxShowMarks);
m_group.insert(theFakeVimSetting(ConfigSmartTab), m_ui.checkBoxSmartTab); Row bools {
m_group.insert(theFakeVimSetting(ConfigStartOfLine), m_ui.checkBoxStartOfLine); Column {
m_group.insert(theFakeVimSetting(ConfigPassKeys), m_ui.checkBoxPassKeys); s.autoIndent,
m_group.insert(theFakeVimSetting(ConfigTabStop), m_ui.spinBoxTabStop); s.smartIndent,
m_group.insert(theFakeVimSetting(ConfigScrollOff), m_ui.spinBoxScrollOff); s.expandTab,
m_group.insert(theFakeVimSetting(ConfigBackspace), m_ui.lineEditBackspace); s.smartTab,
m_group.insert(theFakeVimSetting(ConfigIsKeyword), m_ui.lineEditIsKeyword); s.hlSearch,
s.showCmd,
s.startOfLine,
s.passKeys,
s.blinkingCursor
},
Column {
s.incSearch,
s.useCoreSearch,
s.ignoreCase,
s.smartCase,
s.wrapScan,
s.showMarks,
s.passControlKey,
s.relativeNumber,
s.tildeOp
}
};
m_group.insert(theFakeVimSetting(ConfigPassControlKey), m_ui.checkBoxPassControlKey); Row ints { s.shiftWidth, s.tabStop, s.scrollOff, Stretch() };
m_group.insert(theFakeVimSetting(ConfigAutoIndent), m_ui.checkBoxAutoIndent);
m_group.insert(theFakeVimSetting(ConfigSmartIndent), m_ui.checkBoxSmartIndent);
m_group.insert(theFakeVimSetting(ConfigIncSearch), m_ui.checkBoxIncSearch); Column strings {
m_group.insert(theFakeVimSetting(ConfigUseCoreSearch), m_ui.checkBoxUseCoreSearch); s.backspace,
m_group.insert(theFakeVimSetting(ConfigSmartCase), m_ui.checkBoxSmartCase); s.isKeyword,
m_group.insert(theFakeVimSetting(ConfigIgnoreCase), m_ui.checkBoxIgnoreCase); Row {s.readVimRc, s.vimRcPath}
m_group.insert(theFakeVimSetting(ConfigWrapScan), m_ui.checkBoxWrapScan); };
m_group.insert(theFakeVimSetting(ConfigShowCmd), m_ui.checkBoxShowCmd); Column {
s.useFakeVim,
m_group.insert(theFakeVimSetting(ConfigRelativeNumber), m_ui.checkBoxRelativeNumber); Group {
m_group.insert(theFakeVimSetting(ConfigBlinkingCursor), m_ui.checkBoxBlinkingCursor); bools,
ints,
strings
}.withTitle(tr("Vim Behavior")),
m_group.insert(theFakeVimSetting(ConfigEmulateVimCommentary), m_ui.checkBoxVimCommentary); Group {
m_group.insert(theFakeVimSetting(ConfigEmulateReplaceWithRegister), m_ui.checkBoxReplaceWithRegister); s.emulateVimCommentary,
m_group.insert(theFakeVimSetting(ConfigEmulateExchange), m_ui.checkBoxExchange); s.emulateReplaceWithRegister,
m_group.insert(theFakeVimSetting(ConfigEmulateArgTextObj), m_ui.checkBoxArgTextObj); s.emulateArgTextObj,
m_group.insert(theFakeVimSetting(ConfigEmulateSurround), m_ui.checkBoxVimSurround); s.emulateExchange,
s.emulateSurround
}.withTitle(tr("Plugin Emulation")),
connect(m_ui.pushButtonCopyTextEditorSettings, &QAbstractButton::clicked, Row { copyTextEditorSettings, setQtStyle, setPlainStyle, Stretch() },
Stretch()
}.attachTo(m_widget);
connect(copyTextEditorSettings, &QAbstractButton::clicked,
this, &FakeVimOptionPage::copyTextEditorSettings); this, &FakeVimOptionPage::copyTextEditorSettings);
connect(m_ui.pushButtonSetQtStyle, &QAbstractButton::clicked, connect(setQtStyle, &QAbstractButton::clicked,
this, &FakeVimOptionPage::setQtStyle); this, &FakeVimOptionPage::setQtStyle);
connect(m_ui.pushButtonSetPlainStyle, &QAbstractButton::clicked, connect(setPlainStyle, &QAbstractButton::clicked,
this, &FakeVimOptionPage::setPlainStyle); this, &FakeVimOptionPage::setPlainStyle);
connect(m_ui.checkBoxReadVimRc, &QCheckBox::stateChanged, connect(&s.readVimRc, &FvBaseAspect::changed,
this, &FakeVimOptionPage::updateVimRcWidgets); this, &FakeVimOptionPage::updateVimRcWidgets);
updateVimRcWidgets(); updateVimRcWidgets();
} }
return m_widget; return m_widget;
} }
void FakeVimOptionPage::apply() void FakeVimOptionPage::apply()
{ {
m_group.apply(ICore::settings()); FakeVimSettings &s = *fakeVimSettings();
s.apply();
s.writeSettings(ICore::settings());
} }
void FakeVimOptionPage::finish() void FakeVimOptionPage::finish()
{ {
m_group.finish(); FakeVimSettings &s = *fakeVimSettings();
s.cancel();
delete m_widget; delete m_widget;
} }
void FakeVimOptionPage::copyTextEditorSettings() void FakeVimOptionPage::copyTextEditorSettings()
{ {
FakeVimSettings &s = *fakeVimSettings();
TabSettings ts = TextEditorSettings::codeStyle()->tabSettings(); TabSettings ts = TextEditorSettings::codeStyle()->tabSettings();
TypingSettings tps = TextEditorSettings::typingSettings(); TypingSettings tps = TextEditorSettings::typingSettings();
m_ui.checkBoxExpandTab->setChecked(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy); s.expandTab.setValue(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
m_ui.spinBoxTabStop->setValue(ts.m_tabSize); s.tabStop.setValue(ts.m_tabSize);
m_ui.spinBoxShiftWidth->setValue(ts.m_indentSize); s.shiftWidth.setValue(ts.m_indentSize);
m_ui.checkBoxSmartTab->setChecked( s.smartTab.setValue(tps.m_smartBackspaceBehavior
tps.m_smartBackspaceBehavior == TypingSettings::BackspaceFollowsPreviousIndents); == TypingSettings::BackspaceFollowsPreviousIndents);
m_ui.checkBoxAutoIndent->setChecked(true); s.autoIndent.setValue(true);
m_ui.checkBoxSmartIndent->setChecked(tps.m_autoIndent); s.smartIndent.setValue(tps.m_autoIndent);
m_ui.checkBoxIncSearch->setChecked(true); s.incSearch.setValue(true);
} }
void FakeVimOptionPage::setQtStyle() void FakeVimOptionPage::setQtStyle()
{ {
m_ui.checkBoxExpandTab->setChecked(true); FakeVimSettings &s = *fakeVimSettings();
m_ui.spinBoxTabStop->setValue(4); s.expandTab.setVolatileValue(true);
m_ui.spinBoxShiftWidth->setValue(4); s.tabStop.setVolatileValue(4);
m_ui.checkBoxSmartTab->setChecked(true); s.shiftWidth.setVolatileValue(4);
m_ui.checkBoxAutoIndent->setChecked(true); s.smartTab.setVolatileValue(true);
m_ui.checkBoxSmartIndent->setChecked(true); s.autoIndent.setVolatileValue(true);
m_ui.checkBoxIncSearch->setChecked(true); s.smartIndent.setVolatileValue(true);
m_ui.lineEditBackspace->setText("indent,eol,start"); s.incSearch.setVolatileValue(true);
m_ui.checkBoxPassKeys->setChecked(true); s.backspace.setVolatileValue(QString("indent,eol,start"));
s.passKeys.setVolatileValue(true);
} }
void FakeVimOptionPage::setPlainStyle() void FakeVimOptionPage::setPlainStyle()
{ {
m_ui.checkBoxExpandTab->setChecked(false); FakeVimSettings &s = *fakeVimSettings();
m_ui.spinBoxTabStop->setValue(8); s.expandTab.setVolatileValue(false);
m_ui.spinBoxShiftWidth->setValue(8); s.tabStop.setVolatileValue(8);
m_ui.checkBoxSmartTab->setChecked(false); s.shiftWidth.setVolatileValue(8);
m_ui.checkBoxAutoIndent->setChecked(false); s.smartTab.setVolatileValue(false);
m_ui.checkBoxSmartIndent->setChecked(false); s.autoIndent.setVolatileValue(false);
m_ui.checkBoxIncSearch->setChecked(false); s.smartIndent.setVolatileValue(false);
m_ui.lineEditBackspace->clear(); s.incSearch.setVolatileValue(false);
m_ui.checkBoxPassKeys->setChecked(false); s.backspace.setVolatileValue(QString());
s.passKeys.setVolatileValue(false);
} }
void FakeVimOptionPage::updateVimRcWidgets() void FakeVimOptionPage::updateVimRcWidgets()
{ {
m_ui.pathChooserVimRcPath->setEnabled(m_ui.checkBoxReadVimRc->isChecked()); FakeVimSettings &s = *fakeVimSettings();
s.vimRcPath.setEnabled(s.readVimRc.value());
} }
@@ -531,13 +555,13 @@ public:
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName); void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
void renameFileNameInEditors(const QString &oldName, const QString &newName); void renameFileNameInEditors(const QString &oldName, const QString &newName);
void setUseFakeVim(const QVariant &value); void setUseFakeVim(bool on);
void setUseFakeVimInternal(bool on); void setUseFakeVimInternal(bool on);
void quitFakeVim(); void quitFakeVim();
void fold(FakeVimHandler *handler, int depth, bool fold); void fold(FakeVimHandler *handler, int depth, bool fold);
void maybeReadVimRc(); void maybeReadVimRc();
void setShowRelativeLineNumbers(const QVariant &value); void setShowRelativeLineNumbers(bool on);
void updateCursorBlinking(const QVariant &value); void setCursorBlinking(bool on);
void resetCommandBuffer(); void resetCommandBuffer();
void showCommandBuffer(FakeVimHandler *handler, const QString &contents, void showCommandBuffer(FakeVimHandler *handler, const QString &contents,
@@ -1199,8 +1223,13 @@ bool FakeVimPluginPrivate::initialize()
*/ */
readSettings(); readSettings();
// Vimrc can break test so don't source it if running tests.
if (!ExtensionSystem::PluginManager::testRunRequested())
maybeReadVimRc();
Command *cmd = nullptr; Command *cmd = nullptr;
cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim)->action(),
cmd = ActionManager::registerAction(fakeVimSettings()->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")));
@@ -1238,16 +1267,17 @@ bool FakeVimPluginPrivate::initialize()
connect(DocumentManager::instance(), &DocumentManager::documentRenamed, connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
this, &FakeVimPluginPrivate::documentRenamed); this, &FakeVimPluginPrivate::documentRenamed);
connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged, FakeVimSettings &s = *fakeVimSettings();
connect(&s.useFakeVim, &FvBoolAspect::valueChanged,
this, &FakeVimPluginPrivate::setUseFakeVim); this, &FakeVimPluginPrivate::setUseFakeVim);
connect(theFakeVimSetting(ConfigReadVimRc), &SavedAction::valueChanged, connect(&s.readVimRc, &FvBaseAspect::changed,
this, &FakeVimPluginPrivate::maybeReadVimRc); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(theFakeVimSetting(ConfigVimRcPath), &SavedAction::valueChanged, connect(&s.vimRcPath, &FvBaseAspect::changed,
this, &FakeVimPluginPrivate::maybeReadVimRc); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged, connect(&s.relativeNumber, &FvBoolAspect::valueChanged,
this, &FakeVimPluginPrivate::setShowRelativeLineNumbers); this, &FakeVimPluginPrivate::setShowRelativeLineNumbers);
connect(theFakeVimSetting(ConfigBlinkingCursor), &SavedAction::valueChanged, connect(&s.blinkingCursor, &FvBoolAspect::valueChanged,
this, &FakeVimPluginPrivate::updateCursorBlinking); this, &FakeVimPluginPrivate::setCursorBlinking);
// Delayed operations. // Delayed operations.
connect(this, &FakeVimPluginPrivate::delayedQuitRequested, connect(this, &FakeVimPluginPrivate::delayedQuitRequested,
@@ -1255,12 +1285,7 @@ bool FakeVimPluginPrivate::initialize()
connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested, connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested,
this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection); this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection);
// Vimrc can break test so don't source it if running tests. setCursorBlinking(s.blinkingCursor.value());
if (!ExtensionSystem::PluginManager::testRunRequested())
maybeReadVimRc();
// << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();
updateCursorBlinking(theFakeVimSetting(ConfigBlinkingCursor)->value());
return true; return true;
} }
@@ -1271,7 +1296,7 @@ void FakeVimPluginPrivate::userActionTriggered(int key)
FakeVimHandler *handler = m_editorToHandler[editor]; FakeVimHandler *handler = m_editorToHandler[editor];
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 = !theFakeVimSetting(ConfigUseFakeVim)->value().toBool(); bool enableFakeVim = !fakeVimSettings()->useFakeVim.value();
if (enableFakeVim) if (enableFakeVim)
setUseFakeVimInternal(true); setUseFakeVimInternal(true);
@@ -1287,9 +1312,9 @@ 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(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged, connect(&fakeVimSettings()->relativeNumber, &FvBaseAspect::changed,
relativeNumbers, &QObject::deleteLater); relativeNumbers, &QObject::deleteLater);
connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged, connect(&fakeVimSettings()->useFakeVim, &FvBaseAspect::changed,
relativeNumbers, &QObject::deleteLater); relativeNumbers, &QObject::deleteLater);
relativeNumbers->show(); relativeNumbers->show();
} }
@@ -1298,14 +1323,14 @@ void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
void FakeVimPluginPrivate::writeSettings() void FakeVimPluginPrivate::writeSettings()
{ {
QSettings *settings = ICore::settings(); QSettings *settings = ICore::settings();
theFakeVimSettings()->writeSettings(settings); fakeVimSettings()->writeSettings(settings);
} }
void FakeVimPluginPrivate::readSettings() void FakeVimPluginPrivate::readSettings()
{ {
QSettings *settings = ICore::settings(); QSettings *settings = ICore::settings();
theFakeVimSettings()->readSettings(settings); fakeVimSettings()->readSettings(settings);
m_exCommandMap = m_defaultExCommandMap; m_exCommandMap = m_defaultExCommandMap;
int size = settings->beginReadArray(exCommandMapGroup); int size = settings->beginReadArray(exCommandMapGroup);
@@ -1333,9 +1358,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 (!theFakeVimSetting(ConfigReadVimRc)->value().toBool()) if (!fakeVimSettings()->readVimRc.value())
return; return;
QString fileName = theFakeVimSetting(ConfigVimRcPath)->value().toString(); QString fileName = fakeVimSettings()->vimRcPath.value();
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");
@@ -1642,9 +1667,9 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
return; return;
TabSettings tabSettings; TabSettings tabSettings;
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt(); tabSettings.m_indentSize = fakeVimSettings()->shiftWidth.value();
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt(); tabSettings.m_tabSize = fakeVimSettings()->tabStop.value();
tabSettings.m_tabPolicy = theFakeVimSetting(ConfigExpandTab)->value().toBool() tabSettings.m_tabPolicy = fakeVimSettings()->expandTab.value()
? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy; ? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy;
tabSettings.m_continuationAlignBehavior = tabSettings.m_continuationAlignBehavior =
tew->textDocument()->tabSettings().m_continuationAlignBehavior; tew->textDocument()->tabSettings().m_continuationAlignBehavior;
@@ -1847,11 +1872,11 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
handler->installEventFilter(); handler->installEventFilter();
// pop up the bar // pop up the bar
if (theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) { if (fakeVimSettings()->useFakeVim.value()) {
resetCommandBuffer(); resetCommandBuffer();
handler->setupWidget(); handler->setupWidget();
if (theFakeVimSetting(ConfigRelativeNumber)->value().toBool()) if (fakeVimSettings()->relativeNumber.value())
createRelativeNumberWidget(editor); createRelativeNumberWidget(editor);
} }
} }
@@ -1888,14 +1913,13 @@ void FakeVimPluginPrivate::renameFileNameInEditors(const QString &oldName, const
} }
} }
void FakeVimPluginPrivate::setUseFakeVim(const QVariant &value) void FakeVimPluginPrivate::setUseFakeVim(bool on)
{ {
//qDebug() << "SET USE FAKEVIM" << value; //qDebug() << "SET USE FAKEVIM" << on;
bool on = value.toBool();
Find::setUseFakeVim(on); Find::setUseFakeVim(on);
setUseFakeVimInternal(on); setUseFakeVimInternal(on);
setShowRelativeLineNumbers(theFakeVimSetting(ConfigRelativeNumber)->value()); setShowRelativeLineNumbers(fakeVimSettings()->relativeNumber.value());
updateCursorBlinking(theFakeVimSetting(ConfigBlinkingCursor)->value()); setCursorBlinking(fakeVimSettings()->blinkingCursor.value());
} }
void FakeVimPluginPrivate::setUseFakeVimInternal(bool on) void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
@@ -1918,20 +1942,20 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
} }
} }
void FakeVimPluginPrivate::setShowRelativeLineNumbers(const QVariant &value) void FakeVimPluginPrivate::setShowRelativeLineNumbers(bool on)
{ {
if (value.toBool() && theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) { if (on && fakeVimSettings()->useFakeVim.value()) {
foreach (IEditor *editor, m_editorToHandler.keys()) foreach (IEditor *editor, m_editorToHandler.keys())
createRelativeNumberWidget(editor); createRelativeNumberWidget(editor);
} }
} }
void FakeVimPluginPrivate::updateCursorBlinking(const QVariant &value) void FakeVimPluginPrivate::setCursorBlinking(bool on)
{ {
if (m_savedCursorFlashTime == 0) if (m_savedCursorFlashTime == 0)
m_savedCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime(); m_savedCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime();
bool blink = value.toBool() || !theFakeVimSetting(ConfigUseFakeVim)->value().toBool(); const bool blink = on || !fakeVimSettings()->useFakeVim.value();
QGuiApplication::styleHints()->setCursorFlashTime(blink ? m_savedCursorFlashTime : 0); QGuiApplication::styleHints()->setCursorFlashTime(blink ? m_savedCursorFlashTime : 0);
} }
@@ -2062,7 +2086,7 @@ void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
void FakeVimPluginPrivate::quitFakeVim() void FakeVimPluginPrivate::quitFakeVim()
{ {
theFakeVimSetting(ConfigUseFakeVim)->setValue(false); fakeVimSettings()->useFakeVim.setValue(false);
} }
void FakeVimPluginPrivate::resetCommandBuffer() void FakeVimPluginPrivate::resetCommandBuffer()