From ca5b956ab5559089dfd9f6ee5e23f7843295756d Mon Sep 17 00:00:00 2001 From: Lukas Holecek <hluk@email.cz> Date: Sun, 3 Mar 2013 16:33:47 +0100 Subject: [PATCH] FakeVim: Emulate Vim option ignorecase Change-Id: I0dc87f8a34fa458a9eab14440f7ad2ac2cfe0a98 Reviewed-by: hjk <hjk121@nokiamail.com> --- src/plugins/fakevim/fakevimactions.cpp | 1 + src/plugins/fakevim/fakevimactions.h | 1 + src/plugins/fakevim/fakevimhandler.cpp | 12 +- src/plugins/fakevim/fakevimoptions.ui | 260 +++++++++++++------------ src/plugins/fakevim/fakevimplugin.cpp | 5 +- 5 files changed, 147 insertions(+), 132 deletions(-) diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp index 6b7029e757..6e0426b04d 100644 --- a/src/plugins/fakevim/fakevimactions.cpp +++ b/src/plugins/fakevim/fakevimactions.cpp @@ -193,6 +193,7 @@ FakeVimSettings *theFakeVimSettings() createAction(s, ConfigIncSearch, true, _("IncSearch"), _("is")); createAction(s, ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs")); createAction(s, ConfigSmartCase, false, _("SmartCase"), _("scs")); + createAction(s, ConfigIgnoreCase, false, _("IgnoreCase"), _("ic")); createAction(s, ConfigWrapScan, true, _("WrapScan"), _("ws")); createAction(s, ConfigShowCmd, true, _("ShowCmd"), _("sc")); createAction(s, ConfigScrollOff, 0, _("ScrollOff"), _("so")); diff --git a/src/plugins/fakevim/fakevimactions.h b/src/plugins/fakevim/fakevimactions.h index 0bcf9e8c05..2ff3790edf 100644 --- a/src/plugins/fakevim/fakevimactions.h +++ b/src/plugins/fakevim/fakevimactions.h @@ -75,6 +75,7 @@ enum FakeVimSettingsCode ConfigIncSearch, ConfigUseCoreSearch, ConfigSmartCase, + ConfigIgnoreCase, ConfigWrapScan, // indent allow backspacing over autoindent diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 4e3296c710..e061d76e7d 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -348,7 +348,7 @@ static bool eatString(const char *prefix, QString *str) return true; } -static QRegExp vimPatternToQtPattern(QString needle, bool smartcase) +static QRegExp vimPatternToQtPattern(QString needle, bool ignoreCaseOption, bool smartCaseOption) { /* Transformations (Vim regexp -> QRegExp): * \a -> [A-Za-z] @@ -379,7 +379,9 @@ static QRegExp vimPatternToQtPattern(QString needle, bool smartcase) * \c - set ignorecase for rest * \C - set noignorecase for rest */ - bool ignorecase = smartcase && !needle.contains(QRegExp(_("[A-Z]"))); + // FIXME: Option smartcase should be used only if search was typed by user. + bool ignorecase = ignoreCaseOption + && !(smartCaseOption && needle.contains(QRegExp(_("[A-Z]")))); QString pattern; pattern.reserve(2 * needle.size()); @@ -4724,7 +4726,8 @@ bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd) if (g.lastSubstituteFlags.contains(QLatin1Char('i'))) needle.prepend(_("\\c")); - QRegExp pattern = vimPatternToQtPattern(needle, hasConfig(ConfigSmartCase)); + QRegExp pattern = vimPatternToQtPattern(needle, hasConfig(ConfigIgnoreCase), + hasConfig(ConfigSmartCase)); QTextBlock lastBlock; QTextBlock firstBlock; @@ -5448,7 +5451,8 @@ void FakeVimHandler::Private::searchBalanced(bool forward, QChar needle, QChar o QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos, int count, bool showMessages) { - QRegExp needleExp = vimPatternToQtPattern(sd.needle, hasConfig(ConfigSmartCase)); + QRegExp needleExp = vimPatternToQtPattern(sd.needle, hasConfig(ConfigIgnoreCase), + hasConfig(ConfigSmartCase)); if (!needleExp.isValid()) { if (showMessages) { QString error = needleExp.errorString(); diff --git a/src/plugins/fakevim/fakevimoptions.ui b/src/plugins/fakevim/fakevimoptions.ui index 25e12a0835..48590d7f6e 100644 --- a/src/plugins/fakevim/fakevimoptions.ui +++ b/src/plugins/fakevim/fakevimoptions.ui @@ -24,57 +24,34 @@ <string>Vim Behavior</string> </property> <layout class="QGridLayout" name="gridLayout"> - <item row="3" column="0" colspan="2"> - <widget class="QCheckBox" name="checkBoxSmartTab"> + <item row="11" column="0"> + <widget class="QLabel" name="labelIsKeyword"> <property name="text"> - <string>Smart tabulators</string> + <string>Keyword characters:</string> </property> </widget> </item> - <item row="10" column="1" colspan="2"> - <widget class="QLineEdit" name="lineEditIsKeyword"/> - </item> <item row="12" column="0"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>17</width> - <height>10</height> - </size> - </property> - </spacer> - </item> - <item row="1" column="2"> - <widget class="QCheckBox" name="checkBoxUseCoreSearch"> + <widget class="QLabel" name="labelVimRcPath"> <property name="text"> - <string>Use search dialog</string> + <string>Location of .vimrc:</string> </property> </widget> </item> - <item row="0" column="2"> - <widget class="QCheckBox" name="checkBoxStartOfLine"> + <item row="7" column="2"> + <widget class="QCheckBox" name="checkBoxReadVimRc"> <property name="text"> - <string>Start of line</string> + <string>Read .vimrc</string> </property> </widget> </item> - <item row="1" column="0" colspan="2"> - <widget class="QCheckBox" name="checkBoxSmartIndent"> - <property name="text"> - <string>Smart indentation</string> - </property> - </widget> + <item row="11" column="1" colspan="2"> + <widget class="QLineEdit" name="lineEditIsKeyword"/> </item> - <item row="2" column="0" colspan="2"> - <widget class="QCheckBox" name="checkBoxExpandTab"> + <item row="4" column="2"> + <widget class="QCheckBox" name="checkBoxWrapScan"> <property name="text"> - <string>Expand tabulators</string> + <string>Use wrapscan</string> </property> </widget> </item> @@ -85,24 +62,30 @@ </property> </widget> </item> - <item row="5" column="2"> - <widget class="QCheckBox" name="checkBoxPassControlKey"> - <property name="toolTip"> - <string>Pass key sequences like Ctrl-S to Qt Creator core instead of interpreting them in FakeVim. This gives easier access to Qt Creator core functionality at the price of losing some features of FakeVim.</string> + <item row="13" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> - <property name="text"> - <string>Pass control key</string> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> </property> - </widget> + <property name="sizeHint" stdset="0"> + <size> + <width>17</width> + <height>10</height> + </size> + </property> + </spacer> </item> - <item row="4" column="0" colspan="2"> - <widget class="QCheckBox" name="checkBoxHlSearch"> + <item row="1" column="2"> + <widget class="QCheckBox" name="checkBoxUseCoreSearch"> <property name="text"> - <string>Highlight search results</string> + <string>Use search dialog</string> </property> </widget> </item> - <item row="7" column="1" colspan="2"> + <item row="8" column="1" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <widget class="QSpinBox" name="spinBoxShiftWidth"> @@ -129,14 +112,37 @@ </item> </layout> </item> - <item row="6" column="0"> - <widget class="QCheckBox" name="checkBoxShowCmd"> - <property name="text"> - <string>Show partial command</string> - </property> - </widget> + <item row="9" column="1" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <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_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> + </layout> </item> - <item row="9" column="0"> + <item row="10" column="1" colspan="2"> + <widget class="QLineEdit" name="lineEditBackspace"/> + </item> + <item row="10" column="0"> <widget class="QLabel" name="labelBackspace"> <property name="text"> <string>Backspace:</string> @@ -144,6 +150,13 @@ </widget> </item> <item row="8" column="0"> + <widget class="QLabel" name="labelShiftWidth"> + <property name="text"> + <string>Shift width:</string> + </property> + </widget> + </item> + <item row="9" column="0"> <widget class="QLabel" name="labelTabulator"> <property name="toolTip"> <string>Vim tabstop option</string> @@ -153,24 +166,32 @@ </property> </widget> </item> - <item row="9" column="1" colspan="2"> - <widget class="QLineEdit" name="lineEditBackspace"/> - </item> - <item row="7" column="0"> - <widget class="QLabel" name="labelShiftWidth"> + <item row="3" column="2"> + <widget class="QCheckBox" name="checkBoxSmartCase"> <property name="text"> - <string>Shift width:</string> + <string>Use smartcase</string> </property> </widget> </item> - <item row="5" column="0" colspan="2"> - <widget class="QCheckBox" name="checkBoxIncSearch"> - <property name="text"> - <string>Incremental search</string> - </property> - </widget> + <item row="12" column="1" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayoutVimRcPath"> + <item> + <widget class="QLineEdit" name="lineEditVimRcPath"> + <property name="toolTip"> + <string>Keep empty to use the default path, i.e. %USERPROFILE%\_vimrc on Windows, ~/.vimrc otherwise.</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButtonVimRcPath"> + <property name="text"> + <string>Browse...</string> + </property> + </widget> + </item> + </layout> </item> - <item row="13" column="0" colspan="3"> + <item row="14" column="0" colspan="3"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QPushButton" name="pushButtonCopyTextEditorSettings"> @@ -208,92 +229,78 @@ </item> </layout> </item> - <item row="4" column="2"> + <item row="5" column="2"> <widget class="QCheckBox" name="checkBoxShowMarks"> <property name="text"> <string>Show position of text marks</string> </property> </widget> </item> + <item row="1" column="0" colspan="2"> + <widget class="QCheckBox" name="checkBoxSmartIndent"> + <property name="text"> + <string>Smart indentation</string> + </property> + </widget> + </item> + <item row="6" column="2"> + <widget class="QCheckBox" name="checkBoxPassControlKey"> + <property name="toolTip"> + <string>Pass key sequences like Ctrl-S to Qt Creator core instead of interpreting them in FakeVim. This gives easier access to Qt Creator 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="2" column="2"> - <widget class="QCheckBox" name="checkBoxSmartCase"> + <widget class="QCheckBox" name="checkBoxIgnoreCase"> <property name="text"> - <string>Use smartcase</string> + <string>Use ignorecase</string> </property> </widget> </item> - <item row="3" column="2"> - <widget class="QCheckBox" name="checkBoxWrapScan"> + <item row="2" column="0"> + <widget class="QCheckBox" name="checkBoxExpandTab"> <property name="text"> - <string>Use wrapscan</string> + <string>Expand tabulators</string> </property> </widget> </item> - <item row="8" column="1" colspan="2"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <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_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> - </layout> + <item row="3" column="0"> + <widget class="QCheckBox" name="checkBoxSmartTab"> + <property name="text"> + <string>Smart tabulators</string> + </property> + </widget> </item> - <item row="10" column="0"> - <widget class="QLabel" name="labelIsKeyword"> + <item row="4" column="0"> + <widget class="QCheckBox" name="checkBoxHlSearch"> <property name="text"> - <string>Keyword characters:</string> + <string>Highlight search results</string> </property> </widget> </item> - <item row="11" column="0"> - <widget class="QLabel" name="labelVimRcPath"> + <item row="0" column="2"> + <widget class="QCheckBox" name="checkBoxIncSearch"> <property name="text"> - <string>Location of .vimrc:</string> + <string>Incremental search</string> </property> </widget> </item> - <item row="6" column="2"> - <widget class="QCheckBox" name="checkBoxReadVimRc"> + <item row="5" column="0"> + <widget class="QCheckBox" name="checkBoxShowCmd"> <property name="text"> - <string>Read .vimrc</string> + <string>Show partial command</string> </property> </widget> </item> - <item row="11" column="1" colspan="2"> - <layout class="QHBoxLayout" name="horizontalLayoutVimRcPath"> - <item> - <widget class="QLineEdit" name="lineEditVimRcPath"> - <property name="toolTip"> - <string>Keep empty to use the default path, i.e. %USERPROFILE%\_vimrc on Windows, ~/.vimrc otherwise.</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButtonVimRcPath"> - <property name="text"> - <string>Browse...</string> - </property> - </widget> - </item> - </layout> + <item row="6" column="0"> + <widget class="QCheckBox" name="checkBoxStartOfLine"> + <property name="text"> + <string>Start of line</string> + </property> + </widget> </item> </layout> </widget> @@ -320,10 +327,11 @@ <tabstop>checkBoxExpandTab</tabstop> <tabstop>checkBoxSmartTab</tabstop> <tabstop>checkBoxHlSearch</tabstop> - <tabstop>checkBoxIncSearch</tabstop> <tabstop>checkBoxShowCmd</tabstop> <tabstop>checkBoxStartOfLine</tabstop> + <tabstop>checkBoxIncSearch</tabstop> <tabstop>checkBoxUseCoreSearch</tabstop> + <tabstop>checkBoxIgnoreCase</tabstop> <tabstop>checkBoxSmartCase</tabstop> <tabstop>checkBoxWrapScan</tabstop> <tabstop>checkBoxShowMarks</tabstop> diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index db30a5fa83..f85a76c658 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -313,6 +313,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent) m_ui.checkBoxUseCoreSearch); m_group.insert(theFakeVimSetting(ConfigSmartCase), m_ui.checkBoxSmartCase); + m_group.insert(theFakeVimSetting(ConfigIgnoreCase), + m_ui.checkBoxIgnoreCase); m_group.insert(theFakeVimSetting(ConfigWrapScan), m_ui.checkBoxWrapScan); @@ -1792,9 +1794,8 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) } else if (cmd.args == _("noic") || cmd.args == _("noignorecase")) { // :set noic setActionChecked(Find::Constants::CASE_SENSITIVE, true); - } else { - *handled = false; // Let the handler see it as well. } + *handled = false; // Let the handler see it as well. } else if (cmd.matches(_("n"), _("next"))) { // :n[ext] switchToFile(currentFile() + cmd.count); -- GitLab