From 726985303b82fbe09b17cdfddd274d186df53aad Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Tue, 24 Aug 2010 12:28:51 +0200 Subject: [PATCH] TextEditor: Fix extra selection for snippets to match the editable area. Task-number: QTCREATORBUG-2099 Reviewed-by: mae --- src/plugins/texteditor/basetexteditor.cpp | 6 +++--- src/plugins/texteditor/texteditoroverlay.cpp | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index f7475990e92..c4c411b4b98 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1452,7 +1452,7 @@ void BaseTextEditor::insertCodeSnippet(const QTextCursor &cursor_arg, const QStr if (textToInsert.isEmpty()) { positions.insert(cursorPosition, 0); } else { - positions.insert(cursorPosition-1, textToInsert.length()+1); + positions.insert(cursorPosition, textToInsert.length()); } ++pos; @@ -1485,7 +1485,7 @@ void BaseTextEditor::insertCodeSnippet(const QTextCursor &cursor_arg, const QStr cursor = textCursor(); if (selection.cursor.hasSelection()) { - cursor.setPosition(selection.cursor.selectionStart()+1); + cursor.setPosition(selection.cursor.selectionStart()); cursor.setPosition(selection.cursor.selectionEnd(), QTextCursor::KeepAnchor); } else { cursor.setPosition(selection.cursor.position()); @@ -2020,7 +2020,7 @@ void BaseTextEditorPrivate::snippetTabOrBacktab(bool forward) if (final.m_cursor_begin.position() == final.m_cursor_end.position()) { // empty tab stop cursor.setPosition(final.m_cursor_end.position()); } else { - cursor.setPosition(final.m_cursor_begin.position()+1); + cursor.setPosition(final.m_cursor_begin.position()); cursor.setPosition(final.m_cursor_end.position(), QTextCursor::KeepAnchor); } q->setTextCursor(cursor); diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp index 20fd2698b75..4fbe7d27818 100644 --- a/src/plugins/texteditor/texteditoroverlay.cpp +++ b/src/plugins/texteditor/texteditoroverlay.cpp @@ -442,11 +442,14 @@ void TextEditorOverlay::fill(QPainter *painter, const QColor &color, const QRect } } +/*! \returns true if any selection contains \a cursor, where a cursor on the + start or end of a selection is counted as contained. +*/ bool TextEditorOverlay::hasCursorInSelection(const QTextCursor &cursor) const { for (int i = 0; i < m_selections.size(); ++i) { const OverlaySelection &selection = m_selections.at(i); - if (cursor.position() > selection.m_cursor_begin.position() + if (cursor.position() >= selection.m_cursor_begin.position() && cursor.position() <= selection.m_cursor_end.position()) return true; } -- GitLab