[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] /: vi-mode: fix deadly s/\s*/x/g loop
From: Michal Humpula <michal.humpula () seznam ! cz>
Date: 2014-02-22 20:50:06
Message-ID: E1WHJWQ-00011c-7Q () scm ! kde ! org
[Download RAW message or body]
Git commit 8c0722839c72de754f22b7bb08fefda489bfc6cb by Michal Humpula.
Committed on 22/02/2014 at 20:49.
Pushed by michalhumpula into branch 'master'.
vi-mode: fix deadly s/\s*/x/g loop
M +2 -0 autotests/src/vimode_test.cpp
M +17 -4 src/utils/katecmds.cpp
http://commits.kde.org/ktexteditor/8c0722839c72de754f22b7bb08fefda489bfc6cb
diff --git a/autotests/src/vimode_test.cpp b/autotests/src/vimode_test.cpp
index f595274..6c26ffc 100644
--- a/autotests/src/vimode_test.cpp
+++ b/autotests/src/vimode_test.cpp
@@ -2225,6 +2225,8 @@ void ViModeTest::CommandModeTests()
DoTest("foo\nfoo\nfoo\nfoo", "jlma2jmbgg\\:'b,'as/foo/bar\\", \
"foo\nbar\nbar\nbar"); DoTest("foo", "\\:s/$/x/g\\", "foox");
DoTest("foo", "\\:s/.*/x/g\\", "x");
+ DoTest("abc", "\\:s/\\\\s*/x/g\\", "xaxbxc");
+ //DoTest("abc\n123", "\\:s/\\\\s*/x/g\\", "xaxbxc\nx1x2x3"); // currently not \
working properly
DoTest("foo/bar", "\\:s-/--\\", "foobar");
DoTest("foo/bar", "\\:s_/__\\", "foobar");
diff --git a/src/utils/katecmds.cpp b/src/utils/katecmds.cpp
index 07e32bc..1bb398f 100644
--- a/src/utils/katecmds.cpp
+++ b/src/utils/katecmds.cpp
@@ -1002,11 +1002,17 @@ \
KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer(KTextEd
Range KateCommands::SedReplace::InteractiveSedReplacer::currentMatch()
{
- const Range currentMatch = fullCurrentMatch().first();
- if (currentMatch.start().line() > m_endLine) {
+ QVector<Range> matches = fullCurrentMatch();
+
+ if (matches.isEmpty()) {
+ return Range::invalid();
+ }
+
+ if (matches.first().start().line() > m_endLine) {
return Range::invalid();
}
- return currentMatch;
+
+ return matches.first();
}
void KateCommands::SedReplace::InteractiveSedReplacer::skipCurrentMatch()
@@ -1031,7 +1037,10 @@ void \
KateCommands::SedReplace::InteractiveSedReplacer::replaceCurrentMatch()
// Begin next search from directly after replacement.
if (!replacementText.contains(QLatin1Char('\n'))) {
- m_currentSearchPos = Cursor(currentMatch.start().line(), \
currentMatch.start().column() + replacementText.length()); + const int \
moveChar = currentMatch.isEmpty() ? 1 : 0; // if the search was for \s*, make sure we \
advance a char + const int col = currentMatch.start().column() + \
replacementText.length() + moveChar; +
+ m_currentSearchPos = Cursor(currentMatch.start().line(), col);
} else {
m_currentSearchPos = Cursor(currentMatch.start().line() + \
replacementText.count(QLatin1Char('\n')),
replacementText.length() - \
replacementText.lastIndexOf(QLatin1Char('\n')) - 1); @@ -1078,6 +1087,10 @@ QString \
KateCommands::SedReplace::InteractiveSedReplacer::finalStatusReportMessa
const QVector< Range > \
KateCommands::SedReplace::InteractiveSedReplacer::fullCurrentMatch() {
+ if (m_currentSearchPos > m_doc->documentEnd()) {
+ return QVector<Range>();
+ }
+
return m_regExpSearch.search(m_findPattern, Range(m_currentSearchPos, \
m_doc->documentEnd())); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic