Skip to content

Commit

Permalink
Autocomplete-related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jul 1, 2021
1 parent 73d9fb7 commit e37fb0f
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 33 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 01.07.2021 03:01:55 +0100 - build 5843

1. Autocomplete-related fixes.

--------------------------------------------------------------------------------
drkns 30.06.2021 01:41:10 +0100 - build 5842

Expand Down
27 changes: 18 additions & 9 deletions far/editcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "common/algorithm.hpp"
#include "common/enum_tokens.hpp"
#include "common/enum_substrings.hpp"
#include "common/scope_exit.hpp"

// External:

Expand Down Expand Up @@ -544,13 +545,13 @@ int EditControl::AutoCompleteProc(bool Manual,bool DelBlock,Manager::Key& BackKe
size_t Size;
::GetCursorType(Visible, Size);
bool IsChanged = false;
const auto ExitCode = ComplMenu->Run([&](const Manager::Key& RawKey)
const auto ExitCode = ComplMenu->RunEx([&](int Msg, void* Param)
{
auto MenuKey = RawKey();
::SetCursorType(Visible, Size);

if(!Global->Opt->AutoComplete.ModalList)
if (Msg != DN_INPUT)
{
if (Global->Opt->AutoComplete.ModalList)
return 0;

const auto CurPos = ComplMenu->GetSelectPos();
if(CurPos>=0 && (PrevPos!=CurPos || IsChanged))
{
Expand All @@ -559,10 +560,18 @@ int EditControl::AutoCompleteProc(bool Manual,bool DelBlock,Manager::Key& BackKe
SetString(CurPos? ComplMenu->at(CurPos).Name : CurrentInput);
Show();
}

return 0;
}

if(MenuKey != KEY_NONE)
{
const auto& ReadRec = *static_cast<INPUT_RECORD const*>(Param);
auto MenuKey = InputRecordToKey(&ReadRec);

::SetCursorType(Visible, Size);

if (MenuKey == KEY_NONE)
return 0;

// ввод
if(in_closed_range(L' ', MenuKey, std::numeric_limits<wchar_t>::max()) || any_of(MenuKey, KEY_BS, KEY_DEL, KEY_NUMDEL))
{
Expand Down Expand Up @@ -718,12 +727,12 @@ int EditControl::AutoCompleteProc(bool Manual,bool DelBlock,Manager::Key& BackKe
default:
{
ComplMenu->Close(-1);
BackKey=RawKey;
BackKey= Manager::Key(MenuKey, ReadRec);
Result=1;
}
}
}
}

return 0;
});
// mouse click
Expand Down
2 changes: 1 addition & 1 deletion far/filefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void FileFilter::FilterEdit()
if (Msg!=DN_INPUT)
return 0;

auto Key = InputRecordToKey(static_cast<INPUT_RECORD*>(param));
auto Key = InputRecordToKey(static_cast<INPUT_RECORD const*>(param));

if (Key==KEY_ADD)
Key=L'+';
Expand Down
2 changes: 1 addition & 1 deletion far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7030,7 +7030,7 @@ class FileList::background_updater
private:
listener m_Listener{[this]
{
if (Global->IsPanelsActive() && m_Owner->IsVisible())
if (Global->WindowManager->IsPanelsActive() && m_Owner->IsVisible())
{
m_Owner->UpdateIfChanged(true);
m_Owner->Redraw();
Expand Down
5 changes: 0 additions & 5 deletions far/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ void global::StoreSearchString(string_view const Str, bool Hex)
m_SearchString = Str;
}

bool global::IsPanelsActive() const
{
return WindowManager && WindowManager->IsPanelsActive(true, true);
}

global::far_clock::far_clock()
{
update();
Expand Down
1 change: 0 additions & 1 deletion far/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class global: noncopyable
const string& GetSearchString() const { return m_SearchString; }
bool GetSearchHex() const { return m_SearchHex; }
void StoreSearchString(string_view Str, bool Hex);
bool IsPanelsActive() const;

// BUGBUG

Expand Down
2 changes: 1 addition & 1 deletion far/hmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ bool HMenu::ProcessCurrentSubMenu()
if (Msg != DN_INPUT)
return 0;

auto& rec = *static_cast<INPUT_RECORD*>(param);
const auto& rec = *static_cast<INPUT_RECORD const*>(param);
const auto Key = InputRecordToKey(&rec);

if (rec.EventType == MOUSE_EVENT)
Expand Down
17 changes: 8 additions & 9 deletions far/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,16 @@ void Manager::PluginsMenu() const
}
}

bool Manager::IsPanelsActive(bool and_not_qview, bool or_autocomplete) const
bool Manager::IsPanelsActive() const
{
if (!m_windows.empty() && GetCurrentWindow())
{
const auto fp = std::dynamic_pointer_cast<FilePanels>(GetCurrentWindow());
return (or_autocomplete && MACROAREA_SHELLAUTOCOMPLETION == GetCurrentWindow()->GetMacroArea()) || (fp && (!and_not_qview || fp->ActivePanel()->GetType() != panel_type::QVIEW_PANEL));
}
else
{
if (m_windows.empty())
return false;
}

const auto CurrentWindow = GetCurrentWindow();
if (!CurrentWindow)
return false;

return std::dynamic_pointer_cast<FilePanels>(CurrentWindow) != nullptr;
}

window_ptr Manager::GetWindow(size_t Index) const
Expand Down
2 changes: 1 addition & 1 deletion far/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Manager: noncopyable
*/
void PluginCommit();
int CountWindowsWithName(string_view Name, bool IgnoreCase = true);
bool IsPanelsActive(bool and_not_qview = false, bool or_autocomplete = false) const;
bool IsPanelsActive() const;
window_ptr FindWindowByFile(int ModalType, string_view FileName);
void EnterMainLoop();
void ProcessMainLoop();
Expand Down
8 changes: 4 additions & 4 deletions far/plugapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,15 +921,15 @@ intptr_t WINAPI apiMenuFn(
if (Msg!=DN_INPUT || !BreakKeys)
return 0;

const auto ReadRec = static_cast<INPUT_RECORD*>(param);
const auto ReadKey = InputRecordToKey(ReadRec);
const auto& ReadRec = *static_cast<INPUT_RECORD const*>(param);
const auto ReadKey = InputRecordToKey(&ReadRec);

if (ReadKey==KEY_NONE)
return 0;

for (size_t i = 0; BreakKeys[i].VirtualKeyCode; ++i)
{
if (ReadRec->Event.KeyEvent.wVirtualKeyCode != BreakKeys[i].VirtualKeyCode)
if (ReadRec.Event.KeyEvent.wVirtualKeyCode != BreakKeys[i].VirtualKeyCode)
continue;

const auto NormalizeControlKeys = [](DWORD const Value)
Expand All @@ -941,7 +941,7 @@ intptr_t WINAPI apiMenuFn(
(Value & SHIFT_PRESSED);
};

if (NormalizeControlKeys(ReadRec->Event.KeyEvent.dwControlKeyState) == NormalizeControlKeys(BreakKeys[i].ControlKeyState))
if (NormalizeControlKeys(ReadRec.Event.KeyEvent.dwControlKeyState) == NormalizeControlKeys(BreakKeys[i].ControlKeyState))
{
if (BreakCode)
*BreakCode = i;
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5842
5843
1 change: 1 addition & 0 deletions far/vmenu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ intptr_t VMenu2::VMenu2DlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void*
if(!Call(DN_INPUT, &rec))
Dlg->SendMessage( DM_KEY, 1, &rec);
}
Call(Msg, Param2);
break;

case DN_INPUT:
Expand Down

0 comments on commit e37fb0f

Please sign in to comment.