Skip to content

Commit

Permalink
1. убрана отложенная сортировка цветовых областей в редакторе.
Browse files Browse the repository at this point in the history
  • Loading branch information
zg0 committed Apr 19, 2016
1 parent af8a598 commit 885b9e9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 102 deletions.
6 changes: 5 additions & 1 deletion far/changelog
@@ -1,4 +1,8 @@
w17 20.04.2016 01:39:19 +0300 - build 4627
zg 20.04.2016 02:44:24 +0200 - build 4628

1. убрана отложенная сортировка цветовых областей в редакторе.

w17 20.04.2016 01:39:19 +0300 - build 4627

1. Fix 4492.

Expand Down
53 changes: 9 additions & 44 deletions far/edit.cpp
Expand Up @@ -2139,56 +2139,19 @@ void Edit::DeleteBlock()
Changed(true);
}

void Edit::AddColor(const ColorItem& col,bool skipsort)
void Edit::AddColor(const ColorItem& col)
{
if (skipsort && !ColorListFlags.Check(ECLF_NEEDSORT) && !ColorList.empty() && ColorList.back().Priority > col.Priority)
{
ColorListFlags.Set(ECLF_NEEDSORT);
}

ColorList.emplace_back(col);

if (!skipsort)
{
std::stable_sort(ALL_RANGE(ColorList));
}
ColorList.insert(col);
}

void Edit::SortColorUnlocked()
{
if (ColorListFlags.Check(ECLF_NEEDFREE))
{
ColorListFlags.Clear(ECLF_NEEDFREE);
if (ColorList.empty())
{
clear_and_shrink(ColorList);
}
}

if (ColorListFlags.Check(ECLF_NEEDSORT))
{
ColorListFlags.Clear(ECLF_NEEDSORT);
std::stable_sort(ALL_RANGE(ColorList));
}
}

void Edit::DeleteColor(const delete_color_condition& Condition, bool skipfree)
void Edit::DeleteColor(const delete_color_condition& Condition)
{
if (!ColorList.empty())
{
ColorList.erase(std::remove_if(ALL_RANGE(ColorList), Condition), ColorList.end());

if (ColorList.empty())
std::for_each(RANGE(ColorList, color)
{
if (skipfree)
{
ColorListFlags.Set(ECLF_NEEDFREE);
}
else
{
clear_and_shrink(ColorList);
}
}
if (Condition(color)) ColorList.erase(color);
});
}
}

Expand All @@ -2197,7 +2160,9 @@ bool Edit::GetColor(ColorItem& col, size_t Item) const
if (Item >= ColorList.size())
return false;

col = ColorList[Item];
auto it = ColorList.begin();
std::advance(it, Item);
col = *it;
return true;
}

Expand Down
13 changes: 3 additions & 10 deletions far/edit.hpp
Expand Up @@ -102,11 +102,6 @@ class Editor;

class Edit: public SimpleScreenObject
{
enum EDITCOLORLISTFLAGS
{
ECLF_NEEDSORT = 0x1,
ECLF_NEEDFREE = 0x2,
};
struct ShowInfo
{
int LeftPos;
Expand Down Expand Up @@ -182,9 +177,8 @@ class Edit: public SimpleScreenObject
void SetEditorMode(bool Mode) {m_Flags.Change(FEDITLINE_EDITORMODE, Mode);}
bool ReplaceTabs();
void InsertTab();
void AddColor(const ColorItem& col, bool skipsort);
void SortColorUnlocked();
void DeleteColor(const delete_color_condition& Condition,bool skipfree);
void AddColor(const ColorItem& col);
void DeleteColor(const delete_color_condition& Condition);
bool GetColor(ColorItem& col, size_t Item) const;
void Xlat(bool All=false);
void SetDialogParent(DWORD Sets);
Expand Down Expand Up @@ -258,11 +252,10 @@ class Edit: public SimpleScreenObject
friend class FileEditor;

// KEEP ALIGNED!
std::vector<ColorItem> ColorList;
std::multiset<ColorItem> ColorList;
int m_SelStart;
int m_SelEnd;
int LeftPos;
TBitFlags<unsigned char> ColorListFlags;
unsigned char EndType;
};

Expand Down
44 changes: 3 additions & 41 deletions far/editor.cpp
Expand Up @@ -131,8 +131,6 @@ Editor::Editor(window_ptr Owner, bool DialogUsed):
NewSessionPos(),
EditorID(::EditorID++),
HostFileEditor(nullptr),
SortColorLockCount(0),
SortColorUpdate(false),
EditorControlLock(0),
Color(colors::PaletteColorToFarColor(COL_EDITORTEXT)),
SelColor(colors::PaletteColorToFarColor(COL_EDITORSELECTEDTEXT)),
Expand Down Expand Up @@ -310,9 +308,7 @@ void Editor::ShowEditor()
if (!m_Flags.Check(FEDITOR_DIALOGMEMOEDIT))
{
_SYS_EE_REDRAW(SysLog(L"Call ProcessEditorEvent(EE_REDRAW)"));
SortColorLock();
Global->CtrlObject->Plugins->ProcessEditorEvent(EE_REDRAW, EEREDRAW_ALL, this);
SortColorUnlock();
}
}
_SYS_EE_REDRAW(else SysLog(L"ScrBuf Locked !!!"));
Expand Down Expand Up @@ -2702,9 +2698,7 @@ int Editor::ProcessKey(const Manager::Key& Key)
{
//_D(SysLog(L"%08d EE_REDRAW",__LINE__));
_SYS_EE_REDRAW(SysLog(L"Editor::ProcessKey[%d](!EdOpt.CursorBeyondEOL): EE_REDRAW(EEREDRAW_ALL)",__LINE__));
SortColorLock();
Global->CtrlObject->Plugins->ProcessEditorEvent(EE_REDRAW, EEREDRAW_ALL, this);
SortColorUnlock();
}

/*$ 03.02.2001 SKV
Expand Down Expand Up @@ -2987,9 +2981,7 @@ int Editor::ProcessMouse(const MOUSE_EVENT_RECORD *MouseEvent)
if (!m_Flags.Check(FEDITOR_DIALOGMEMOEDIT))
{
_SYS_EE_REDRAW(SysLog(L"Editor::ProcessMouse[%08d] ProcessEditorEvent(EE_REDRAW)",__LINE__));
SortColorLock();
Global->CtrlObject->Plugins->ProcessEditorEvent(EE_REDRAW, EEREDRAW_ALL, this);
SortColorUnlock();
}
ShowEditor();
}
Expand Down Expand Up @@ -5967,9 +5959,8 @@ int Editor::EditorControl(int Command, intptr_t Param1, void *Param2)
return FALSE;
}

CurPtr->AddColor(newcol, SortColorLocked());
CurPtr->AddColor(newcol);
if (col->Flags&ECF_AUTODELETE) m_AutoDeletedColors.emplace(&*CurPtr);
SortColorUpdate=true;
return TRUE;
}

Expand Down Expand Up @@ -6027,12 +6018,7 @@ int Editor::EditorControl(int Command, intptr_t Param1, void *Param2)
_ECTLLOG(SysLog(L"GetStringByNumber(%d) return nullptr",col->StringNumber));
return FALSE;
}

SortColorUpdate=true;

CurPtr->DeleteColor(
[&](const ColorItem& Item) { return (col->StartPos == -1 || col->StartPos == Item.StartPos) && col->Owner == Item.GetOwner(); },
SortColorLocked());
CurPtr->DeleteColor([&](const ColorItem& Item) { return (col->StartPos == -1 || col->StartPos == Item.StartPos) && col->Owner == Item.GetOwner();});
return TRUE;
}

Expand Down Expand Up @@ -7342,30 +7328,6 @@ void Editor::DrawScrollbar()
}
}

void Editor::SortColorLock()
{
SortColorLockCount++;
}

void Editor::SortColorUnlock()
{
if (SortColorLockCount > 0)
SortColorLockCount--;
else
SortColorLockCount = 0;

if (SortColorLockCount == 0 && SortColorUpdate)
{
SortColorUpdate = false;
std::for_each(ALL_RANGE(Lines), std::mem_fn(&Edit::SortColorUnlocked));
}
}

bool Editor::SortColorLocked() const
{
return SortColorLockCount > 0;
}

void Editor::Change(EDITOR_CHANGETYPE Type,int StrNum)
{
if (ChangeEventSubscribers.empty())
Expand Down Expand Up @@ -7427,7 +7389,7 @@ void Editor::AutoDeleteColors()
{
std::for_each(CONST_RANGE(m_AutoDeletedColors, i)
{
i->DeleteColor([](const ColorItem& Item){ return (Item.Flags & ECF_AUTODELETE) != 0; }, SortColorLocked());
i->DeleteColor([](const ColorItem& Item){ return (Item.Flags & ECF_AUTODELETE) != 0; });
});
m_AutoDeletedColors.clear();
}
5 changes: 0 additions & 5 deletions far/editor.hpp
Expand Up @@ -124,9 +124,6 @@ class Editor: public SimpleScreenObject
int GetCurRow() const { return static_cast<int>(m_it_CurLine.Number()); }
void SetCurPos(int NewCol, int NewRow = -1);
void DrawScrollbar();
void SortColorLock();
void SortColorUnlock();
bool SortColorLocked() const;
bool EditorControlLocked() const { return EditorControlLock != 0; }
const FarColor& GetNormalColor() const { return Color; }
const FarColor& GetSelectedColor() const { return SelColor; }
Expand Down Expand Up @@ -372,8 +369,6 @@ class Editor: public SimpleScreenObject
bool NewSessionPos;
int EditorID;
FileEditor *HostFileEditor;
int SortColorLockCount;
bool SortColorUpdate;
int EditorControlLock;
std::vector<char> decoded;
FarColor Color;
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4627)m4_dnl
m4_define(BUILD,4628)m4_dnl

0 comments on commit 885b9e9

Please sign in to comment.