From 1a692f0f227648b1a1bd08e710f4ba682efa86c1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 May 2012 21:16:24 +0000 Subject: [PATCH] Fix calculation of the wxStyledTextCtrl selection size. Use SCI_GETSELTEXT to compute the size of the buffer instead of doing it ourselves, especially as we do it incorrectly in case of rectangular selection. Closes #14331. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71540 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/stc/stc.cpp | 12 +++--------- src/stc/stc.cpp.in | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index cc580a1ff3..b5d71eebbe 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -4128,16 +4128,10 @@ wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line) wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw() { - long start; - long end; - - GetSelection(&start, &end); - int len = end - start; - if (!len) { - wxCharBuffer empty; - return empty; - } + // Calculate the length needed first. + const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0); + // And then really get the data. wxCharBuffer buf(len); SendMsg(SCI_GETSELTEXT, 0, (sptr_t)buf.data()); return buf; diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 70f3646ae9..10ceabad07 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -628,16 +628,10 @@ wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line) wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw() { - long start; - long end; - - GetSelection(&start, &end); - int len = end - start; - if (!len) { - wxCharBuffer empty; - return empty; - } + // Calculate the length needed first. + const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0); + // And then really get the data. wxCharBuffer buf(len); SendMsg(SCI_GETSELTEXT, 0, (sptr_t)buf.data()); return buf; -- 2.45.2