forked from qt-creator/qt-creator
fakevim: fixes for search using Core find dialog
- repeated searching ('n'/'N') would not work
- search would have been restricted to selection
- fix search when used as motion in an edit command ('c/...')
Merge-request: 190
Reviewed-by: hjk <qtc-committer@nokia.com>
This commit is contained in:
@@ -814,6 +814,7 @@ public:
|
|||||||
|
|
||||||
bool m_lastSearchForward;
|
bool m_lastSearchForward;
|
||||||
bool m_findPending;
|
bool m_findPending;
|
||||||
|
int m_findStartPosition;
|
||||||
QString m_lastInsertion;
|
QString m_lastInsertion;
|
||||||
QString m_lastDeletion;
|
QString m_lastDeletion;
|
||||||
|
|
||||||
@@ -984,6 +985,7 @@ void FakeVimHandler::Private::init()
|
|||||||
m_subsubmode = NoSubSubMode;
|
m_subsubmode = NoSubSubMode;
|
||||||
m_passing = false;
|
m_passing = false;
|
||||||
m_findPending = false;
|
m_findPending = false;
|
||||||
|
m_findStartPosition = -1;
|
||||||
m_fakeEnd = false;
|
m_fakeEnd = false;
|
||||||
m_positionPastEnd = false;
|
m_positionPastEnd = false;
|
||||||
m_anchorPastEnd = false;
|
m_anchorPastEnd = false;
|
||||||
@@ -1326,8 +1328,9 @@ void FakeVimHandler::Private::stopIncrementalFind()
|
|||||||
if (m_findPending) {
|
if (m_findPending) {
|
||||||
m_findPending = false;
|
m_findPending = false;
|
||||||
QTextCursor tc = cursor();
|
QTextCursor tc = cursor();
|
||||||
tc.setPosition(tc.selectionStart());
|
setAnchorAndPosition(m_findStartPosition, tc.selectionStart());
|
||||||
setCursor(tc);
|
finishMovement();
|
||||||
|
setAnchor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1924,8 +1927,10 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
|
|||||||
if (hasConfig(ConfigUseCoreSearch)) {
|
if (hasConfig(ConfigUseCoreSearch)) {
|
||||||
// re-use the core dialog.
|
// re-use the core dialog.
|
||||||
m_findPending = true;
|
m_findPending = true;
|
||||||
|
m_findStartPosition = position();
|
||||||
|
m_movetype = MoveExclusive;
|
||||||
|
setAnchor(); // clear selection: otherwise, search is restricted to selection
|
||||||
emit q->findRequested(!m_lastSearchForward);
|
emit q->findRequested(!m_lastSearchForward);
|
||||||
//m_tc.setPosition(m_tc.selectionStart());
|
|
||||||
} else {
|
} else {
|
||||||
// FIXME: make core find dialog sufficiently flexible to
|
// FIXME: make core find dialog sufficiently flexible to
|
||||||
// produce the "default vi" behaviour too. For now, roll our own.
|
// produce the "default vi" behaviour too. For now, roll our own.
|
||||||
@@ -2306,12 +2311,23 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
|
|||||||
handleStartOfLine();
|
handleStartOfLine();
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (input.is('n') || input.is('N')) {
|
} else if (input.is('n') || input.is('N')) {
|
||||||
SearchData sd;
|
if (hasConfig(ConfigUseCoreSearch)) {
|
||||||
sd.needle = g.searchHistory.current();
|
bool forward = (input.is('n')) ? m_lastSearchForward : !m_lastSearchForward;
|
||||||
sd.forward = input.is('n') ? m_lastSearchForward : !m_lastSearchForward;
|
int pos = position();
|
||||||
sd.highlightCursor = false;
|
emit q->findNextRequested(!forward);
|
||||||
sd.highlightMatches = true;
|
if (forward && pos == cursor().selectionStart()) {
|
||||||
search(sd);
|
// if cursor is already positioned at the start of a find result, this is returned
|
||||||
|
emit q->findNextRequested(false);
|
||||||
|
}
|
||||||
|
setPosition(cursor().selectionStart());
|
||||||
|
} else {
|
||||||
|
SearchData sd;
|
||||||
|
sd.needle = g.searchHistory.current();
|
||||||
|
sd.forward = input.is('n') ? m_lastSearchForward : !m_lastSearchForward;
|
||||||
|
sd.highlightCursor = false;
|
||||||
|
sd.highlightMatches = true;
|
||||||
|
search(sd);
|
||||||
|
}
|
||||||
} else if (isVisualMode() && (input.is('o') || input.is('O'))) {
|
} else if (isVisualMode() && (input.is('o') || input.is('O'))) {
|
||||||
int pos = position();
|
int pos = position();
|
||||||
setAnchorAndPosition(pos, anchor());
|
setAnchorAndPosition(pos, anchor());
|
||||||
|
|||||||
Reference in New Issue
Block a user