diff --git a/uppsrc/RichEdit/Cursor.cpp b/uppsrc/RichEdit/Cursor.cpp index 2b22502b3..a0561b380 100644 --- a/uppsrc/RichEdit/Cursor.cpp +++ b/uppsrc/RichEdit/Cursor.cpp @@ -7,6 +7,7 @@ void RichEdit::FinishNF() anchorp = text.GetRichPos(anchor); cursorp = text.GetRichPos(cursor); tablesel = 0; + begtabsel = false; if(anchor != cursor) { RichPos p = text.GetRichPos(cursor, anchorp.level); if(anchorp.level == 0 || anchorp.level < cursorp.level) { @@ -15,20 +16,26 @@ void RichEdit::FinishNF() } else if(p.table != anchorp.table) { - tablesel = anchorp.table; - if(cursor < anchor) { - cells.left = 0; - cells.right = anchorp.cell.x; - cells.top = 0; - cells.bottom = anchorp.cell.y; + if(text.GetRichPos(anchor, 1).table == 1 && anchor < cursor) { + begtabsel = true; + anchor = 0; } else { - cells.left = anchorp.cell.x; - cells.right = anchorp.tabsize.cx - 1; - cells.top = anchorp.cell.y; - cells.bottom = anchorp.tabsize.cy - 1; + tablesel = anchorp.table; + if(cursor < anchor) { + cells.left = 0; + cells.right = anchorp.cell.x; + cells.top = 0; + cells.bottom = anchorp.cell.y; + } + else { + cells.left = anchorp.cell.x; + cells.right = anchorp.tabsize.cx - 1; + cells.top = anchorp.cell.y; + cells.bottom = anchorp.tabsize.cy - 1; + } + text.AdjustTableSel(tablesel, cells); } - text.AdjustTableSel(tablesel, cells); } else if(p.cell != anchorp.cell) { @@ -86,8 +93,10 @@ void RichEdit::MoveNG(int newpos, bool select) if(newpos >= text.GetLength() + select) newpos = text.GetLength() + select; CloseFindReplace(); cursor = newpos; - if(!select) + if(!select) { anchor = cursor; + begtabsel = false; + } objectpos = -1; Finish(); if(select) @@ -286,7 +295,7 @@ bool RichEdit::CursorKey(dword key, int count) bool RichEdit::IsSelection() const { - return anchor >= 0 && anchor != cursor; + return anchor != cursor; } bool RichEdit::GetSelection(int& l, int& h) const @@ -315,6 +324,7 @@ void RichEdit::CancelSelection() if(IsSelection()) { tablesel = 0; anchor = cursor; + begtabsel = false; found = notfoundfw = false; CloseFindReplace(); Finish(); @@ -331,6 +341,7 @@ bool RichEdit::RemoveSelection(bool back) Move(text.GetCellPos(tablesel, cells.top, cells.left).pos); } else { + BegSelTabFix(); int c = min(cursor, anchor); Remove(c, abs(cursor - anchor), back); found = notfoundfw = false; diff --git a/uppsrc/RichEdit/Editor.cpp b/uppsrc/RichEdit/Editor.cpp index 5fdd39c99..a3eeb735f 100644 --- a/uppsrc/RichEdit/Editor.cpp +++ b/uppsrc/RichEdit/Editor.cpp @@ -129,7 +129,7 @@ void RichEdit::Paint(Draw& w) pi.cells = cells; } else { - pi.sell = min(cursor, anchor); + pi.sell = begtabsel ? -1 : min(cursor, anchor); pi.selh = max(cursor, anchor); } text.Paint(pw, pagesz, pi); @@ -525,9 +525,9 @@ void RichEdit::SetPickUndoInfo(pick_ UndoInfo& f) void RichEdit::PosInfo::Serialize(Stream& s) { - int version = 1; + int version = 2; s / version; - s % cursor % anchor % zsc; + s % cursor % anchor % zsc % begtabsel; if(version == 0) zsc = 0; } @@ -537,6 +537,7 @@ RichEdit::PosInfo RichEdit::GetPosInfo() const PosInfo f; f.cursor = cursor; f.anchor = anchor; + f.begtabsel = begtabsel; f.zsc = zsc; return f; } @@ -546,6 +547,9 @@ void RichEdit::SetPosInfo(const PosInfo& f) int l = text.GetLength(); cursor = min(l, f.cursor); anchor = min(l, f.anchor); + begtabsel = f.begtabsel; + if(begtabsel) + anchor = 0; Finish(); zsc = f.zsc; Layout(); @@ -591,6 +595,8 @@ RichEdit::RichEdit() style.Tip(t_("Style")); style <<= THISBACK(Style); + + WhenBar = THISBACK(StdBar); pagesz = Size(3968, 6074); unit = UNIT_POINT; @@ -622,8 +628,6 @@ RichEdit::RichEdit() AddFrame(sb); RefreshBar(); - WhenBar = THISBACK(StdBar); - ruler.WhenBeginTrack = THISBACK(BeginRulerTrack); ruler.WhenTrack = THISBACK(RulerTrack); ruler.WhenEndTrack = THISBACK(ReadFormat); diff --git a/uppsrc/RichEdit/Kbd.cpp b/uppsrc/RichEdit/Kbd.cpp index 3e65dffe2..e26e23c42 100644 --- a/uppsrc/RichEdit/Kbd.cpp +++ b/uppsrc/RichEdit/Kbd.cpp @@ -29,6 +29,7 @@ bool RichEdit::Key(dword key, int count) if(cursor <= 0 || RemoveSpecial(cursor, cursor - 1, true)) return true; anchor = --cursor; + begtabsel = false; Remove(cursor, 1); break; case K_DELETE: @@ -52,6 +53,7 @@ bool RichEdit::Key(dword key, int count) return true; Remove(c, cursor - c); cursor = anchor = c; + begtabsel = false; break; } break; @@ -127,6 +129,7 @@ bool RichEdit::Key(dword key, int count) } if(cursorp.table && cursorp.posincell == cursorp.celllen) { cursor = anchor = cursor + 1; + begtabsel = false; break; } default: diff --git a/uppsrc/RichEdit/Modify.cpp b/uppsrc/RichEdit/Modify.cpp index a31b064a9..0a3cef08e 100644 --- a/uppsrc/RichEdit/Modify.cpp +++ b/uppsrc/RichEdit/Modify.cpp @@ -2,8 +2,75 @@ NAMESPACE_UPP + void RichEdit::Filter(RichText& txt) {} +void BegSelFixRaw(RichText& text) +{ + RichPos p = text.GetRichPos(0, 1); + ASSERT(p.table == 1); + if(p.table != 1) + return; + RichPara::Format fmt; + text.InsertParaSpecial(1, true, fmt); +} + +void BegSelUnFixRaw(RichText& text) +{ + ASSERT(text.GetLength() > 0); + RichPos p = text.GetRichPos(1, 1); + ASSERT(p.table == 1); + if(p.table != 1) + return; + text.RemoveParaSpecial(1, true); +} + +void RichEdit::UndoBegSelFix::Apply(RichText& txt) +{ + BegSelUnFixRaw(txt); +} + +RichEdit::UndoRec *RichEdit::UndoBegSelFix::GetRedo(const RichText& txt) +{ + return new RichEdit::UndoBegSelUnFix; +} + +void RichEdit::UndoBegSelUnFix::Apply(RichText& text) +{ + BegSelFixRaw(text); +} + +RichEdit::UndoRec * RichEdit::UndoBegSelUnFix::GetRedo(const RichText& txt) +{ + return new RichEdit::UndoBegSelFix; +} + +bool RichEdit::BegSelTabFix() +{ + if(begtabsel) { + int c = cursor; + AddUndo(new UndoBegSelFix); + BegSelFixRaw(text); + Move(0); + Move(c + 1, true); + begtabsel = false; + return true; + } + return false; +} + +void RichEdit::BegSelTabFixEnd(bool fix) +{ + if(fix && GetLength() > 0) { + int c = cursor; + AddUndo(new UndoBegSelUnFix); + BegSelUnFixRaw(text); + Move(0); + Move(c - 1, true); + begtabsel = true; + } +} + bool RichEdit::InvalidRange(int l, int h) { return !InSameTxt(text.GetRichPos(min(l, h)), text.GetRichPos(max(l, h))); @@ -20,6 +87,7 @@ void RichEdit::AddUndo(UndoRec *ur) found = false; ur->cursor = cursor; ur->serial = undoserial; + DLOG("Undo serial: " << undoserial); undo.AddTail(ur); } @@ -54,7 +122,9 @@ void RichEdit::SaveFormat() pos = cursor; count = 0; } + bool b = BegSelTabFix(); SaveFormat(pos, count); + BegSelTabFixEnd(b); } void RichEdit::Limit(int& pos, int& count) @@ -68,9 +138,11 @@ void RichEdit::ModifyFormat(int pos, const RichText::FormatInfo& fi, int count) { if(IsReadOnly()) return; + bool b = BegSelTabFix(); Limit(pos, count); SaveFormat(pos, count); text.ApplyFormatInfo(pos, fi, count); + BegSelTabFixEnd(b); } void RichEdit::Remove(int pos, int len, bool forward) @@ -187,8 +259,19 @@ RichText RichEdit::GetSelection(int maxcount) const clip.SetStyles(text.GetStyles()); clip.CatPick(tab); } - else - clip = text.Copy(min(cursor, anchor), min(maxcount, abs(cursor - anchor))); + else { + if(begtabsel) { + RichPos p = text.GetRichPos(0, 1); + if(p.table) { + RichTable tab = text.CopyTable(p.table); + clip.SetStyles(text.GetStyles()); + clip.CatPick(tab); + clip.CatPick(text.Copy(p.tablen + 1, minmax(abs(cursor - p.tablen - 1), 0, maxcount))); + } + } + else + clip = text.Copy(min(cursor, anchor), min(maxcount, abs(cursor - anchor))); + } return clip; } @@ -377,6 +460,7 @@ void RichEdit::InsertLine() formatinfo.label = lbl; } anchor = cursor = cursor + 1; + begtabsel = false; formatinfo.newpage = false; if(st) { Uuid next = text.GetStyle(b.styleid).next; diff --git a/uppsrc/RichEdit/RichEdit.h b/uppsrc/RichEdit/RichEdit.h index 18fe7dd9e..53f2271ae 100644 --- a/uppsrc/RichEdit/RichEdit.h +++ b/uppsrc/RichEdit/RichEdit.h @@ -227,6 +227,7 @@ private: RichText text; RichText::FormatInfo formatinfo; int cursor, anchor; + bool begtabsel; RichCaret cursorc; RichPos cursorp; RichPos anchorp; @@ -282,8 +283,6 @@ private: Vector ffs; int bullet_indent; - - static int fh[]; @@ -409,6 +408,16 @@ private: UndoTable(const RichText& txt, int table); }; + + struct UndoBegSelFix : UndoRec { + virtual void Apply(RichText& txt); + virtual UndoRec *GetRedo(const RichText& txt); + }; + + struct UndoBegSelUnFix : UndoRec { + virtual void Apply(RichText& txt); + virtual UndoRec *GetRedo(const RichText& txt); + }; BiArray undo; Array redo; @@ -465,7 +474,7 @@ private: void Limit(int& pos, int& count); bool InvalidRange(int c1, int c2); - void NextUndo() { undoserial += incundoserial; incundoserial = false; } + void NextUndo() { undoserial += incundoserial; incundoserial = false; DDUMP(undoserial); } void AddUndo(UndoRec *undo); void BeginRulerTrack(); @@ -594,6 +603,9 @@ private: void StyleKeys(); void ApplyStyleKey(int i); + bool BegSelTabFix(); + void BegSelTabFixEnd(bool fix); + struct DisplayDefault : public Display { virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const; @@ -630,6 +642,8 @@ public: Callback1 WhenLabel; Callback1 WhenBar; + void StdBar(Bar& menu); + void SerializeSettings(Stream& s); Zoom GetZoom() const; @@ -674,8 +688,6 @@ public: bool Print(); void DoPrint() { Print(); } - void StdBar(Bar& bar); - void StyleTool(Bar& bar, int width = 120); void FaceTool(Bar& bar, int width = 130); void HeightTool(Bar& bar, int width = 50); @@ -774,9 +786,10 @@ public: }; struct PosInfo { - int cursor; - int anchor; - int zsc; + int cursor; + int anchor; + bool begtabsel; + int zsc; void Serialize(Stream& s); }; diff --git a/uppsrc/RichEdit/Table.cpp b/uppsrc/RichEdit/Table.cpp index 4714f7652..0e5c6080d 100644 --- a/uppsrc/RichEdit/Table.cpp +++ b/uppsrc/RichEdit/Table.cpp @@ -49,6 +49,7 @@ void RichEdit::InsertTable() if(text.GetRichPos(cursor).paralen) { InsertLine(); cursor = anchor = cursor - 1; + begtabsel = false; } SaveFormat(cursor, 0); AddUndo(new UndoCreateTable(text.SetTable(cursor, table))); diff --git a/uppsrc/RichEdit/init b/uppsrc/RichEdit/init index b2a9df155..79f126b80 100644 --- a/uppsrc/RichEdit/init +++ b/uppsrc/RichEdit/init @@ -1,7 +1,7 @@ #ifndef _RichEdit_icpp_init_stub #define _RichEdit_icpp_init_stub #include "CtrlLib/init" -#define BLITZ_INDEX__ FFF73E96341F7950C74E5D046FB6E89FD +#define BLITZ_INDEX__ FD6E3AA0190F1EC3A8E9638C6CE96943B #include "RichEdit.icpp" #undef BLITZ_INDEX__ #endif