FakeVim: Emulate Vim option ignorecase

Change-Id: I0dc87f8a34fa458a9eab14440f7ad2ac2cfe0a98
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Lukas Holecek
2013-03-03 16:33:47 +01:00
committed by hjk
parent 4394b798bb
commit ca5b956ab5
5 changed files with 164 additions and 149 deletions

View File

@@ -193,6 +193,7 @@ FakeVimSettings *theFakeVimSettings()
createAction(s, ConfigIncSearch, true, _("IncSearch"), _("is")); createAction(s, ConfigIncSearch, true, _("IncSearch"), _("is"));
createAction(s, ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs")); createAction(s, ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs"));
createAction(s, ConfigSmartCase, false, _("SmartCase"), _("scs")); createAction(s, ConfigSmartCase, false, _("SmartCase"), _("scs"));
createAction(s, ConfigIgnoreCase, false, _("IgnoreCase"), _("ic"));
createAction(s, ConfigWrapScan, true, _("WrapScan"), _("ws")); createAction(s, ConfigWrapScan, true, _("WrapScan"), _("ws"));
createAction(s, ConfigShowCmd, true, _("ShowCmd"), _("sc")); createAction(s, ConfigShowCmd, true, _("ShowCmd"), _("sc"));
createAction(s, ConfigScrollOff, 0, _("ScrollOff"), _("so")); createAction(s, ConfigScrollOff, 0, _("ScrollOff"), _("so"));

View File

@@ -75,6 +75,7 @@ enum FakeVimSettingsCode
ConfigIncSearch, ConfigIncSearch,
ConfigUseCoreSearch, ConfigUseCoreSearch,
ConfigSmartCase, ConfigSmartCase,
ConfigIgnoreCase,
ConfigWrapScan, ConfigWrapScan,
// indent allow backspacing over autoindent // indent allow backspacing over autoindent

View File

@@ -348,7 +348,7 @@ static bool eatString(const char *prefix, QString *str)
return true; return true;
} }
static QRegExp vimPatternToQtPattern(QString needle, bool smartcase) static QRegExp vimPatternToQtPattern(QString needle, bool ignoreCaseOption, bool smartCaseOption)
{ {
/* Transformations (Vim regexp -> QRegExp): /* Transformations (Vim regexp -> QRegExp):
* \a -> [A-Za-z] * \a -> [A-Za-z]
@@ -379,7 +379,9 @@ static QRegExp vimPatternToQtPattern(QString needle, bool smartcase)
* \c - set ignorecase for rest * \c - set ignorecase for rest
* \C - set noignorecase 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; QString pattern;
pattern.reserve(2 * needle.size()); pattern.reserve(2 * needle.size());
@@ -4724,7 +4726,8 @@ bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd)
if (g.lastSubstituteFlags.contains(QLatin1Char('i'))) if (g.lastSubstituteFlags.contains(QLatin1Char('i')))
needle.prepend(_("\\c")); needle.prepend(_("\\c"));
QRegExp pattern = vimPatternToQtPattern(needle, hasConfig(ConfigSmartCase)); QRegExp pattern = vimPatternToQtPattern(needle, hasConfig(ConfigIgnoreCase),
hasConfig(ConfigSmartCase));
QTextBlock lastBlock; QTextBlock lastBlock;
QTextBlock firstBlock; 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, QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos, int count,
bool showMessages) bool showMessages)
{ {
QRegExp needleExp = vimPatternToQtPattern(sd.needle, hasConfig(ConfigSmartCase)); QRegExp needleExp = vimPatternToQtPattern(sd.needle, hasConfig(ConfigIgnoreCase),
hasConfig(ConfigSmartCase));
if (!needleExp.isValid()) { if (!needleExp.isValid()) {
if (showMessages) { if (showMessages) {
QString error = needleExp.errorString(); QString error = needleExp.errorString();

View File

@@ -24,17 +24,45 @@
<string>Vim Behavior</string> <string>Vim Behavior</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="2"> <item row="11" column="0">
<widget class="QCheckBox" name="checkBoxSmartTab"> <widget class="QLabel" name="labelIsKeyword">
<property name="text"> <property name="text">
<string>Smart tabulators</string> <string>Keyword characters:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="1" colspan="2"> <item row="12" column="0">
<widget class="QLabel" name="labelVimRcPath">
<property name="text">
<string>Location of .vimrc:</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QCheckBox" name="checkBoxReadVimRc">
<property name="text">
<string>Read .vimrc</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QLineEdit" name="lineEditIsKeyword"/> <widget class="QLineEdit" name="lineEditIsKeyword"/>
</item> </item>
<item row="12" column="0"> <item row="4" column="2">
<widget class="QCheckBox" name="checkBoxWrapScan">
<property name="text">
<string>Use wrapscan</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
<string>Automatic indentation</string>
</property>
</widget>
</item>
<item row="13" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@@ -57,52 +85,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="8" column="1" colspan="2">
<widget class="QCheckBox" name="checkBoxStartOfLine">
<property name="text">
<string>Start of line</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="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxExpandTab">
<property name="text">
<string>Expand tabulators</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
<string>Automatic indentation</string>
</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>
</property>
<property name="text">
<string>Pass control key</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxHlSearch">
<property name="text">
<string>Highlight search results</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QSpinBox" name="spinBoxShiftWidth"> <widget class="QSpinBox" name="spinBoxShiftWidth">
@@ -129,14 +112,37 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="6" column="0"> <item row="9" column="1" colspan="2">
<widget class="QCheckBox" name="checkBoxShowCmd"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="text"> <item>
<string>Show partial command</string> <widget class="QSpinBox" name="spinBoxTabStop">
</property> <property name="minimum">
</widget> <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>
<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"> <widget class="QLabel" name="labelBackspace">
<property name="text"> <property name="text">
<string>Backspace:</string> <string>Backspace:</string>
@@ -144,6 +150,13 @@
</widget> </widget>
</item> </item>
<item row="8" column="0"> <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"> <widget class="QLabel" name="labelTabulator">
<property name="toolTip"> <property name="toolTip">
<string>Vim tabstop option</string> <string>Vim tabstop option</string>
@@ -153,24 +166,32 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1" colspan="2"> <item row="3" column="2">
<widget class="QLineEdit" name="lineEditBackspace"/> <widget class="QCheckBox" name="checkBoxSmartCase">
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelShiftWidth">
<property name="text"> <property name="text">
<string>Shift width:</string> <string>Use smartcase</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="12" column="1" colspan="2">
<widget class="QCheckBox" name="checkBoxIncSearch"> <layout class="QHBoxLayout" name="horizontalLayoutVimRcPath">
<property name="text"> <item>
<string>Incremental search</string> <widget class="QLineEdit" name="lineEditVimRcPath">
</property> <property name="toolTip">
</widget> <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>
<item row="13" column="0" colspan="3"> <item row="14" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QPushButton" name="pushButtonCopyTextEditorSettings"> <widget class="QPushButton" name="pushButtonCopyTextEditorSettings">
@@ -208,92 +229,78 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="4" column="2"> <item row="5" column="2">
<widget class="QCheckBox" name="checkBoxShowMarks"> <widget class="QCheckBox" name="checkBoxShowMarks">
<property name="text"> <property name="text">
<string>Show position of text marks</string> <string>Show position of text marks</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartCase"> <widget class="QCheckBox" name="checkBoxSmartIndent">
<property name="text"> <property name="text">
<string>Use smartcase</string> <string>Smart indentation</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QCheckBox" name="checkBoxWrapScan">
<property name="text">
<string>Use wrapscan</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>
<item row="10" column="0">
<widget class="QLabel" name="labelIsKeyword">
<property name="text">
<string>Keyword characters:</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="labelVimRcPath">
<property name="text">
<string>Location of .vimrc:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="2"> <item row="6" column="2">
<widget class="QCheckBox" name="checkBoxReadVimRc"> <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"> <property name="text">
<string>Read .vimrc</string> <string>Pass control key</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="1" colspan="2"> <item row="2" column="2">
<layout class="QHBoxLayout" name="horizontalLayoutVimRcPath"> <widget class="QCheckBox" name="checkBoxIgnoreCase">
<item> <property name="text">
<widget class="QLineEdit" name="lineEditVimRcPath"> <string>Use ignorecase</string>
<property name="toolTip"> </property>
<string>Keep empty to use the default path, i.e. %USERPROFILE%\_vimrc on Windows, ~/.vimrc otherwise.</string> </widget>
</property> </item>
</widget> <item row="2" column="0">
</item> <widget class="QCheckBox" name="checkBoxExpandTab">
<item> <property name="text">
<widget class="QPushButton" name="pushButtonVimRcPath"> <string>Expand tabulators</string>
<property name="text"> </property>
<string>Browse...</string> </widget>
</property> </item>
</widget> <item row="3" column="0">
</item> <widget class="QCheckBox" name="checkBoxSmartTab">
</layout> <property name="text">
<string>Smart tabulators</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="2">
<widget class="QCheckBox" name="checkBoxIncSearch">
<property name="text">
<string>Incremental search</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="6" column="0">
<widget class="QCheckBox" name="checkBoxStartOfLine">
<property name="text">
<string>Start of line</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@@ -320,10 +327,11 @@
<tabstop>checkBoxExpandTab</tabstop> <tabstop>checkBoxExpandTab</tabstop>
<tabstop>checkBoxSmartTab</tabstop> <tabstop>checkBoxSmartTab</tabstop>
<tabstop>checkBoxHlSearch</tabstop> <tabstop>checkBoxHlSearch</tabstop>
<tabstop>checkBoxIncSearch</tabstop>
<tabstop>checkBoxShowCmd</tabstop> <tabstop>checkBoxShowCmd</tabstop>
<tabstop>checkBoxStartOfLine</tabstop> <tabstop>checkBoxStartOfLine</tabstop>
<tabstop>checkBoxIncSearch</tabstop>
<tabstop>checkBoxUseCoreSearch</tabstop> <tabstop>checkBoxUseCoreSearch</tabstop>
<tabstop>checkBoxIgnoreCase</tabstop>
<tabstop>checkBoxSmartCase</tabstop> <tabstop>checkBoxSmartCase</tabstop>
<tabstop>checkBoxWrapScan</tabstop> <tabstop>checkBoxWrapScan</tabstop>
<tabstop>checkBoxShowMarks</tabstop> <tabstop>checkBoxShowMarks</tabstop>

View File

@@ -313,6 +313,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent)
m_ui.checkBoxUseCoreSearch); m_ui.checkBoxUseCoreSearch);
m_group.insert(theFakeVimSetting(ConfigSmartCase), m_group.insert(theFakeVimSetting(ConfigSmartCase),
m_ui.checkBoxSmartCase); m_ui.checkBoxSmartCase);
m_group.insert(theFakeVimSetting(ConfigIgnoreCase),
m_ui.checkBoxIgnoreCase);
m_group.insert(theFakeVimSetting(ConfigWrapScan), m_group.insert(theFakeVimSetting(ConfigWrapScan),
m_ui.checkBoxWrapScan); m_ui.checkBoxWrapScan);
@@ -1792,9 +1794,8 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
} else if (cmd.args == _("noic") || cmd.args == _("noignorecase")) { } else if (cmd.args == _("noic") || cmd.args == _("noignorecase")) {
// :set noic // :set noic
setActionChecked(Find::Constants::CASE_SENSITIVE, true); 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"))) { } else if (cmd.matches(_("n"), _("next"))) {
// :n[ext] // :n[ext]
switchToFile(currentFile() + cmd.count); switchToFile(currentFile() + cmd.count);