Commit 11d2d744 authored by David Schulz's avatar David Schulz
Browse files

Editor: Keep selection on updateCurrentSelection().



Task-number: QTCREATORBUG-9959

Change-Id: Ib3324e78bc36790e588c56af7474d3eb968032dc
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 48f16164
...@@ -322,19 +322,21 @@ void TextEditorPlugin::updateVariable(const QByteArray &variable) ...@@ -322,19 +322,21 @@ void TextEditorPlugin::updateVariable(const QByteArray &variable)
void TextEditorPlugin::updateCurrentSelection(const QString &text) void TextEditorPlugin::updateCurrentSelection(const QString &text)
{ {
Core::IEditor *iface = Core::EditorManager::currentEditor(); if (ITextEditor *editor = qobject_cast<ITextEditor *>(Core::EditorManager::currentEditor())) {
ITextEditor *editor = qobject_cast<ITextEditor *>(iface); const int pos = editor->position();
if (editor) {
int pos = editor->position();
int anchor = editor->position(ITextEditor::Anchor); int anchor = editor->position(ITextEditor::Anchor);
if (anchor < 0) // no selection if (anchor < 0) // no selection
anchor = pos; anchor = pos;
int selectionLength = anchor-pos; int selectionLength = pos - anchor;
if (selectionLength < 0) const bool selectionInTextDirection = selectionLength >= 0;
if (!selectionInTextDirection)
selectionLength = -selectionLength; selectionLength = -selectionLength;
int start = qMin(pos, anchor); const int start = qMin(pos, anchor);
editor->setCursorPosition(start); editor->setCursorPosition(start);
editor->replace(selectionLength, text); editor->replace(selectionLength, text);
const int replacementEnd = editor->position();
editor->setCursorPosition(selectionInTextDirection ? start : replacementEnd);
editor->select(selectionInTextDirection ? replacementEnd : start);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment