Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
editor replace fix (4997)
  • Loading branch information
alabuzhev committed Aug 3, 2017
1 parent e61c549 commit 7026f54
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
21 changes: 7 additions & 14 deletions far/PluginA.cpp
Expand Up @@ -96,20 +96,15 @@ DECLARE_PLUGIN_FUNCTION(iProcessDialogEvent, int (WINAPI*)(int Event, void *
class file_version: noncopyable
{
public:
explicit file_version(const string& File):
m_File(File)
bool Read(const string& Filename)
{
}

bool Read()
{
const auto Size = GetFileVersionInfoSize(m_File.data(), nullptr);
const auto Size = GetFileVersionInfoSize(Filename.data(), nullptr);
if (!Size)
return false;

m_Buffer.reset(Size);

if (!GetFileVersionInfo(m_File.data(), 0, Size, m_Buffer.get()))
if (!GetFileVersionInfo(Filename.data(), 0, Size, m_Buffer.get()))
return false;

const auto Translation = GetValue<DWORD>(L"\\VarFileInfo\\Translation");
Expand All @@ -120,9 +115,9 @@ class file_version: noncopyable
return true;
}

auto GetStringValue(const string& value) const
auto GetStringValue(const string& Value) const
{
return GetValue<wchar_t>((m_BlockPath + value).data());
return GetValue<wchar_t>((m_BlockPath + Value).data());
}

auto GetFixedInfo() const
Expand All @@ -139,7 +134,6 @@ class file_version: noncopyable
return VerQueryValue(m_Buffer.get(), SubBlock, reinterpret_cast<void**>(&Result), &Length) && Length? Result : nullptr;
}

string m_File;
string m_BlockPath;
wchar_t_ptr m_Buffer;
};
Expand All @@ -150,8 +144,7 @@ class oem_plugin_module: public native_plugin_module
NONCOPYABLE(oem_plugin_module);

explicit oem_plugin_module(const string& Name):
native_plugin_module(Name),
m_FileVersion(Name)
native_plugin_module(Name)
{
}

Expand Down Expand Up @@ -4985,7 +4978,7 @@ class PluginA: public Plugin

auto& FileVersion = static_cast<oem_plugin_module*>(m_Instance.get())->m_FileVersion;

if (FileVersion.Read())
if (FileVersion.Read(GetModuleName()))
{
const wchar_t* Value;
if (((Value = FileVersion.GetStringValue(L"InternalName")) != nullptr || (Value = FileVersion.GetStringValue(L"OriginalName")) != nullptr) && *Value)
Expand Down
6 changes: 6 additions & 0 deletions far/changelog
@@ -1,3 +1,9 @@
drkns 04.08.2017 00:27:23 +0000 - build 4998

1. Уточнение 4997 - погнулась замена.

2. Там же - криво работала замена, содержащая "\r", и уже давно.

drkns 01.08.2017 20:39:18 +0000 - build 4997

1. Продолжение #3462 - не меняем позицию курсора без необходимости.
Expand Down
53 changes: 27 additions & 26 deletions far/editor.cpp
Expand Up @@ -3509,6 +3509,9 @@ bool Editor::Search(bool Next)
}
else
{
// BUGBUG Too much in editor depends on it
CurPtr->SetCurPos(CurPos);

if (!EdOpt.PersistentBlocks)
UnmarkBlock();

Expand Down Expand Up @@ -3541,11 +3544,11 @@ bool Editor::Search(bool Next)
}

m_it_TopScreen=TmpPtr;
int LeftPos=CurPtr->GetLeftPos();
int TabCurPos=CurPtr->GetTabCurPos();

if (ObjWidth()>8 && TabCurPos-LeftPos+SearchLength>ObjWidth()-8)
CurPtr->SetLeftPos(TabCurPos+SearchLength-ObjWidth()+8);
const auto TabCurPos = CurPtr->GetTabCurPos();

if (TabCurPos + SearchLength + 8 > CurPtr->GetLeftPos() + ObjWidth())
CurPtr->SetLeftPos(TabCurPos + SearchLength + 8 - ObjWidth());

if (ReplaceMode)
{
Expand All @@ -3561,13 +3564,9 @@ bool Editor::Search(bool Next)
newcol.Priority=EDITOR_COLOR_SELECTION_PRIORITY;
CurPtr->AddColor(newcol);

string strQSearchStr(CurPtr->GetString().data() + CurPtr->GetCurPos(), SearchLength), strQReplaceStr = strReplaceStrCurrent;

// do not use InsertQuote, AI is not suitable here
strQSearchStr.insert(0, 1, L'"');
strQSearchStr.push_back(L'"');
strQReplaceStr.insert(0, 1, L'"');
strQReplaceStr.push_back(L'"');
const auto strQSearchStr = concat(L'"', make_string_view(CurPtr->GetString(), CurPos, SearchLength), L'"');
const auto strQReplaceStr = concat(L'"', strReplaceStrCurrent, L'"');

if (!SearchLength && !strReplaceStrCurrent.length())
ZeroLength = true;
Expand Down Expand Up @@ -3636,9 +3635,15 @@ bool Editor::Search(bool Next)
if (Ch==L'\r')
{
ProcessKeyInternal(Manager::Key(KEY_DEL), RefreshMe);
}

if (Ch!=KEY_BS)
// ProcessKeyInternal('\r') changes m_it_CurLine!
m_Flags.Clear(FEDITOR_OVERTYPE);
m_it_CurLine->SetOvertypeMode(false);
ProcessKeyInternal(Manager::Key(Ch), RefreshMe);
m_Flags.Set(FEDITOR_OVERTYPE);
m_it_CurLine->SetOvertypeMode(true);
}
else if (Ch!=KEY_BS)
ProcessKeyInternal(Manager::Key(Ch), RefreshMe);
}

Expand Down Expand Up @@ -3675,38 +3680,34 @@ bool Editor::Search(bool Next)
else
{
/* Fast method */
const auto& Str = m_it_CurLine->GetString();
const auto LocalCurPos = m_it_CurLine->GetCurPos();
const auto IsSelection = m_it_CurLine->IsSelection();
const auto& Str = CurPtr->GetString();
const auto IsSelection = CurPtr->IsSelection();
std::pair<intptr_t, intptr_t> Selection;
if (IsSelection)
{
m_it_CurLine->GetSelection(Selection.first, Selection.second);
CurPtr->GetSelection(Selection.first, Selection.second);
}
string NewStr(Str, 0, LocalCurPos);
NewStr += strReplaceStrCurrent;
NewStr.append(Str.cbegin() + LocalCurPos + SearchLength, Str.cend());
NewStr += m_it_CurLine->GetEOL();
AddUndoData(UNDO_EDIT, m_it_CurLine->GetString(), m_it_CurLine->GetEOL(), m_it_CurLine.Number(), m_it_CurLine->GetCurPos());
m_it_CurLine->SetString(NewStr);
m_it_CurLine->SetCurPos(LocalCurPos + static_cast<int>(strReplaceStrCurrent.size()));
const auto NewStr = concat(make_string_view(Str, 0, CurPos), strReplaceStrCurrent, make_string_view(Str, CurPos + SearchLength), CurPtr->GetEOL());
AddUndoData(UNDO_EDIT, CurPtr->GetString(), CurPtr->GetEOL(), CurPtr.Number(), CurPos);
CurPtr->SetString(NewStr);
CurPtr->SetCurPos(CurPos + static_cast<int>(strReplaceStrCurrent.size()));

if (IsSelection)
{
const auto& AdjustPos = [&](int Pos)
{
if (Pos > LocalCurPos)
if (Pos > CurPos)
{
Pos -= SearchLength;
Pos += static_cast<int>(strReplaceStrCurrent.size());
}
return Pos;
};

m_it_CurLine->Select(AdjustPos(Selection.first), AdjustPos(Selection.second));
CurPtr->Select(AdjustPos(Selection.first), AdjustPos(Selection.second));
}

Change(ECTYPE_CHANGED, m_it_CurLine.Number());
Change(ECTYPE_CHANGED, CurPtr.Number());
TextChanged(true);
}

Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4997)m4_dnl
m4_define(BUILD,4998)m4_dnl

0 comments on commit 7026f54

Please sign in to comment.