CtrlLib: Improved selection in RichTextView tables

git-svn-id: svn://ultimatepp.org/upp/trunk@3428 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-05-17 11:21:55 +00:00
parent 781db0382c
commit 591ead2a91
3 changed files with 16 additions and 30 deletions

View file

@ -96,14 +96,20 @@ Image RichTextView::CursorImage(Point p, dword keyflags)
return Image::Arrow();
}
void RichTextView::Copy()
{
if(anchor == cursor)
WriteClipboardUnicodeText(text.GetPlainText());
else {
RefreshSel();
WriteClipboardUnicodeText(text.Copy(sell, selh - sell).GetPlainText());
WString h = text.GetPlainText(false).Mid(sell, selh - sell);
WString r;
for(const wchar *s = ~h; s < h.End(); s++) {
if(*s == '\n')
r.Cat('\r');
r.Cat(*s);
}
WriteClipboardUnicodeText(r);
}
}
@ -156,30 +162,8 @@ void RichTextView::RefreshRange(int a, int b)
void RichTextView::RefreshSel()
{
int l = min(cursor, anchor);
int h = max(cursor, anchor);
if(l != h) {
for(;;) {
RichPos pl = text.GetRichPos(l);
if(!pl.table)
break;
l -= pl.posintab + 1;
if(l < 0)
break;
}
for(;;) {
RichPos ph = text.GetRichPos(h);
if(!ph.table)
break;
h += ph.tablen - ph.posintab + 1;
if(h >= text.GetLength())
break;
}
if(l < 0)
l = 0;
if(h >= text.GetLength())
h = text.GetLength();
}
int l = minmax(min(cursor, anchor), 0, text.GetLength());
int h = minmax(max(cursor, anchor), 0, text.GetLength());
if(sell == l && selh == h || sell == selh && l == h)
return;
RichPos pl = text.GetRichPos(l);

View file

@ -227,7 +227,7 @@ public:
void Normalize();
Vector<int> GetAllLanguages() const;
WString GetPlainText() const;
WString GetPlainText(bool withcr = true) const;
struct UpdateIterator {
enum { CONTINUE = 0, STOP = 1, UPDATE = 2 };

View file

@ -285,11 +285,12 @@ void RichTxt::RestoreFormat(int pi, const Formating& info, int& ii, const RichSt
}
}
WString RichTxt::GetPlainText() const {
WString RichTxt::GetPlainText(bool withcr) const {
WString clip;
for(int pi = 0; pi < GetPartCount(); pi++) {
if(pi) {
clip.Cat('\r');
if(withcr)
clip.Cat('\r');
clip.Cat('\n');
}
if(IsTable(pi)) {
@ -298,7 +299,8 @@ WString RichTxt::GetPlainText() const {
for(int j = 0; j < tab.GetColumns(); j++)
if(tab(i, j)) {
if(i || j) {
clip.Cat('\r');
if(withcr)
clip.Cat('\r');
clip.Cat('\n');
}
clip << tab[i][j].text.GetPlainText();