From 12cc29c56a03723218b85becfc6b5a1a63e917e5 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 18 Nov 2006 22:27:48 +0000 Subject: [PATCH] Small cleanup. Set caret position when calling SetSelection. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43501 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/richtext/richtextbuffer.h | 2 +- include/wx/richtext/richtextctrl.h | 3 +++ src/richtext/richtextbuffer.cpp | 4 ++-- src/richtext/richtextctrl.cpp | 7 +++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 95a2e0c530..c5a638fb14 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -1844,7 +1844,7 @@ public: bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0); /// Submit command to delete this range - bool DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long newCaretPositon, wxRichTextCtrl* ctrl); + bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl); /// Mark modified void Modify(bool modify = true) { m_modified = modify; } diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index ec73215dc4..55049a7d4e 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -224,6 +224,9 @@ public: virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); + /// Deletes the content in the given range + virtual bool Delete(const wxRichTextRange& range); + // translate between the position (which is just an index in the text ctrl // considering all its contents as a single strings) and (x, y) coordinates // which represent column and line. diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 1242224d0a..2ac10201af 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -4810,11 +4810,11 @@ wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPos } /// Submit command to delete this range -bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long WXUNUSED(newCaretPositon), wxRichTextCtrl* ctrl) +bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl) { wxRichTextAction* action = new wxRichTextAction(NULL, _("Delete"), wxRICHTEXT_DELETE, this, ctrl); - action->SetPosition(initialCaretPosition); + action->SetPosition(ctrl->GetCaretPosition()); // Set the range to delete action->SetRange(range); diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index b84f2db4c7..a3d7c064db 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -2249,6 +2249,7 @@ void wxRichTextCtrl::DoSetSelection(long from, long to, bool WXUNUSED(scrollCare { m_selectionAnchor = from; m_selectionRange.SetRange(from, to-1); + m_caretPosition = from-1; Refresh(false); PositionCaret(); @@ -3098,6 +3099,12 @@ bool wxRichTextCtrl::PromoteList(int promoteBy, const wxRichTextRange& range, co return GetBuffer().PromoteList(promoteBy, range.ToInternal(), defName, flags, specifiedLevel); } +/// Deletes the content in the given range +bool wxRichTextCtrl::Delete(const wxRichTextRange& range) +{ + return GetBuffer().DeleteRangeWithUndo(range.ToInternal(), this); +} + const wxArrayString& wxRichTextCtrl::GetAvailableFontNames() { if (sm_availableFontNames.GetCount() == 0) -- 2.45.2