Skip to content

Commit

Permalink
Selection & executor fixes
Browse files Browse the repository at this point in the history
1. Forum: selection in fixed size edit controls.

2. Other selection-related fixes in edit controls and the editor.
   Various service keys shouldn't stop selection / deselect anymore.

3. Forum: extra echo when executing unknown commands in a new window.
  • Loading branch information
alabuzhev committed Jun 15, 2021
1 parent 278be7d commit 9530d5f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 76 deletions.
10 changes: 10 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
--------------------------------------------------------------------------------
drkns 15.06.2021 22:01:42 +0100 - build 5822

1. Forum: selection in fixed size edit controls.

2. Other selection-related fixes in edit controls and the editor.
Various service keys shouldn't stop selection / deselect anymore.

3. Forum: extra echo when executing unknown commands in a new window.

--------------------------------------------------------------------------------
drkns 14.06.2021 19:10:39 +0100 - build 5821

Expand Down
39 changes: 23 additions & 16 deletions far/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,25 +648,14 @@ bool Edit::ProcessKey(const Manager::Key& Key)

if (
!IntKeyState.ShiftPressed() &&
(!Global->CtrlObject->Macro.IsExecuting() || IsNavKey(LocalKey)) &&
!IsShiftKey(LocalKey) &&
!Global->CtrlObject->Macro.IsExecuting() &&
!Recurse &&
// No single ctrl, alt, shift key or their combination
LocalKey & ~KEY_CTRLMASK &&
none_of(LocalKey, KEY_NONE, KEY_INS, KEY_KILLFOCUS, KEY_GOTFOCUS) &&
none_of(LocalKey & ~KEY_CTRLMASK, KEY_LWIN, KEY_RWIN, KEY_APPS)
is_clear_selection_key(LocalKey)
)
{
m_Flags.Clear(FEDITLINE_MARKINGBLOCK);

if (
!m_Flags.CheckAny(FEDITLINE_PERSISTENTBLOCKS | FEDITLINE_EDITORMODE) &&
none_of(LocalKey,
KEY_CTRLINS, KEY_RCTRLINS, KEY_CTRLNUMPAD0, KEY_RCTRLNUMPAD0,
KEY_SHIFTDEL, KEY_SHIFTNUMDEL, KEY_SHIFTDECIMAL,
KEY_CTRLQ, KEY_RCTRLQ,
KEY_SHIFTINS, KEY_SHIFTNUMPAD0)
)
if (!m_Flags.CheckAny(FEDITLINE_PERSISTENTBLOCKS | FEDITLINE_EDITORMODE))
{
if (m_SelStart != -1 || m_SelEnd )
{
Expand Down Expand Up @@ -778,15 +767,15 @@ bool Edit::ProcessKey(const Manager::Key& Key)
m_Flags.Set(FEDITLINE_MARKINGBLOCK);
}

if ((m_SelStart != -1 && m_SelEnd == -1) || m_SelEnd > SavedCurPos)
if ((m_SelStart != -1 && m_SelEnd == -1) || (SavedCurPos != m_CurPos && m_SelEnd > SavedCurPos))
{
if (m_CurPos == m_SelEnd)
RemoveSelection();
else
Select(m_CurPos, m_SelEnd);
}
else
AddSelect(SavedCurPos, m_CurPos);
AddSelect(SavedCurPos, m_CurPos == SavedCurPos && m_CurPos < m_Str.size()? m_Str.size() : m_CurPos);

Show();

Expand Down Expand Up @@ -2297,3 +2286,21 @@ bool Edit::is_valid_surrogate_pair_at(size_t const Position) const
string_view const Str(m_Str);
return Position < Str.size() && is_valid_surrogate_pair(Str.substr(Position));
}

bool Edit::is_clear_selection_key(unsigned const Key)
{
static const unsigned int Keys[]
{
KEY_LEFT, KEY_NUMPAD4,
KEY_RIGHT, KEY_NUMPAD6,
KEY_HOME, KEY_NUMPAD7,
KEY_END, KEY_NUMPAD1,
KEY_CTRLHOME, KEY_RCTRLHOME, KEY_CTRLNUMPAD7, KEY_RCTRLNUMPAD7,
KEY_CTRLEND, KEY_RCTRLEND, KEY_CTRLNUMPAD1, KEY_RCTRLNUMPAD1,
KEY_CTRLLEFT, KEY_RCTRLLEFT, KEY_CTRLNUMPAD4, KEY_RCTRLNUMPAD4,
KEY_CTRLRIGHT, KEY_RCTRLRIGHT, KEY_CTRLNUMPAD7, KEY_RCTRLNUMPAD7,
KEY_CTRLS, KEY_RCTRLS,
};

return contains(Keys, Key);
}
1 change: 1 addition & 0 deletions far/edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Edit: public SimpleScreenObject
bool GetReadOnly() const {return m_Flags.Check(FEDITLINE_READONLY);}
void SetReadOnly(bool NewReadOnly) {m_Flags.Change(FEDITLINE_READONLY,NewReadOnly);}
void SetHorizontalPosition(int X1, int X2) { SetPosition({ X1, m_Where.top, X2, m_Where.bottom }); }
static bool is_clear_selection_key(unsigned Key);

protected:
virtual void RefreshStrByMask(int InitMode=FALSE) {}
Expand Down
79 changes: 23 additions & 56 deletions far/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,25 @@ long long Editor::VMProcess(int OpCode, void* vParam, long long iParam)
return 0;
}

static bool is_clear_selection_key(unsigned const Key)
{
static const unsigned int Keys[]
{
KEY_UP, KEY_NUMPAD8,
KEY_DOWN, KEY_NUMPAD2,
KEY_PGUP, KEY_NUMPAD9,
KEY_PGDN, KEY_NUMPAD3,
KEY_CTRLPGUP, KEY_RCTRLPGUP, KEY_CTRLNUMPAD9, KEY_RCTRLNUMPAD9,
KEY_CTRLPGDN, KEY_RCTRLPGDN, KEY_CTRLNUMPAD3, KEY_RCTRLNUMPAD3,
KEY_CTRLUP, KEY_RCTRLUP, KEY_CTRLNUMPAD8, KEY_RCTRLNUMPAD8,
KEY_CTRLDOWN, KEY_RCTRLDOWN, KEY_CTRLNUMPAD2, KEY_RCTRLNUMPAD2,
KEY_CTRLN, KEY_RCTRLN,
KEY_CTRLE, KEY_RCTRLE,
};

return Edit::is_clear_selection_key(Key) || contains(Keys, Key);
}

bool Editor::ProcessKeyInternal(const Manager::Key& Key, bool& Refresh)
{
auto LocalKey = Key;
Expand Down Expand Up @@ -808,65 +827,13 @@ bool Editor::ProcessKeyInternal(const Manager::Key& Key, bool& Refresh)

auto CurPos = m_it_CurLine->GetCurPos();
const auto CurVisPos = GetLineCurPos();
const auto isk = IsShiftKey(LocalKey());
const auto ick = any_of(LocalKey(), KEY_CTRLC, KEY_RCTRLC, KEY_CTRLINS, KEY_CTRLNUMPAD0, KEY_RCTRLINS, KEY_RCTRLNUMPAD0);
const auto imk = in_closed_range(KEY_MACRO_BASE, LocalKey(), KEY_MACRO_ENDBASE);
const auto ipk = in_closed_range(KEY_OP_BASE, LocalKey(), KEY_OP_ENDBASE);

//if ((!isk || Global->CtrlObject->Macro.IsExecuting()) && !isk && !Pasting)
if (!isk && !Pasting && !ick && !imk && !ipk )
if (!Pasting && IsAnySelection() && is_clear_selection_key(LocalKey()))
{
if (IsAnySelection())
{
TurnOffMarkingBlock();
}

if (IsAnySelection() && !EdOpt.PersistentBlocks)
// if (BlockStart || VBlockStart && !EdOpt.PersistentBlocks)
{
TurnOffMarkingBlock();

if (!EdOpt.PersistentBlocks)
{
static const unsigned int UnmarkKeys[]=
{
KEY_LEFT, KEY_NUMPAD4,
KEY_RIGHT, KEY_NUMPAD6,
KEY_HOME, KEY_NUMPAD7,
KEY_END, KEY_NUMPAD1,
KEY_UP, KEY_NUMPAD8,
KEY_DOWN, KEY_NUMPAD2,
KEY_PGUP, KEY_NUMPAD9,
KEY_PGDN, KEY_NUMPAD3,
KEY_CTRLHOME, KEY_RCTRLHOME, KEY_CTRLNUMPAD7, KEY_RCTRLNUMPAD7,
KEY_CTRLPGUP, KEY_RCTRLPGUP, KEY_CTRLNUMPAD9, KEY_RCTRLNUMPAD9,
KEY_CTRLEND, KEY_RCTRLEND, KEY_CTRLNUMPAD1, KEY_RCTRLNUMPAD1,
KEY_CTRLPGDN, KEY_RCTRLPGDN, KEY_CTRLNUMPAD3, KEY_RCTRLNUMPAD3,
KEY_CTRLLEFT, KEY_RCTRLLEFT, KEY_CTRLNUMPAD4, KEY_RCTRLNUMPAD4,
KEY_CTRLRIGHT, KEY_RCTRLRIGHT, KEY_CTRLNUMPAD7, KEY_RCTRLNUMPAD7,
KEY_CTRLUP, KEY_RCTRLUP, KEY_CTRLNUMPAD8, KEY_RCTRLNUMPAD8,
KEY_CTRLDOWN, KEY_RCTRLDOWN, KEY_CTRLNUMPAD2, KEY_RCTRLNUMPAD2,
KEY_CTRLN, KEY_RCTRLN,
KEY_CTRLE, KEY_RCTRLE,
KEY_CTRLS, KEY_RCTRLS,
};

if (contains(UnmarkKeys, LocalKey()))
{
UnmarkBlock();
}
}
else
{
intptr_t StartSel,EndSel;
// Edit *BStart=!BlockStart?VBlockStart:BlockStart;
// BStart->GetRealSelection(StartSel,EndSel);
m_it_AnyBlockStart->GetRealSelection(StartSel,EndSel);
TurnOffMarkingBlock();

if (StartSel==-1 || StartSel==EndSel)
UnmarkBlock();
}
}
if (!EdOpt.PersistentBlocks)
UnmarkBlock();
}

if (any_of(LocalKey(), KEY_ALTD, KEY_RALTD))
Expand Down
7 changes: 6 additions & 1 deletion far/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ static bool execute_impl(
rectangle ConsoleWindowRect;
point ConsoleSize;
std::optional<external_execution_context> Context;
auto ConsoleActivatorInvoked = false;

const auto ExtendedActivator = [&](bool const Consolise)
{
Expand All @@ -607,7 +608,11 @@ static bool execute_impl(
Context.emplace();
}

ConsoleActivator(Consolise);
if (!ConsoleActivatorInvoked)
{
ConsoleActivator(Consolise);
ConsoleActivatorInvoked = true;
}
};

const auto execute_process = [&]
Expand Down
4 changes: 2 additions & 2 deletions far/setattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static bool ShellSetFileAttributesImpl(Panel* SrcPanel, const string* Object)
{
{ DI_DOUBLEBOX, {{ 3, 1 }, {DlgX-4, DlgY-2}}, DIF_NONE, msg(lng::MSetAttrTitle), },
{ DI_TEXT, {{-1, 2 }, {0, 2 }}, DIF_NONE, msg(lng::MSetAttrFor), },
{ DI_TEXT, {{-1, 3 }, {0, 3 }}, DIF_SHOWAMPERSAND, },
{ DI_TEXT, {{5, 3 }, {DlgX-6, 3 }}, DIF_CENTERTEXT | DIF_SHOWAMPERSAND, },
{ DI_COMBOBOX, {{5, 3 }, {DlgX-6, 3 }}, DIF_SHOWAMPERSAND | DIF_DROPDOWNLIST | DIF_LISTWRAPMODE | DIF_HIDDEN, },
{ DI_TEXT, {{5, 3 }, {17, 3 }}, DIF_HIDDEN, },
{ DI_EDIT, {{18, 3 }, {DlgX-6, 3 }}, DIF_HIDDEN | DIF_EDITPATH, },
Expand Down Expand Up @@ -1045,7 +1045,7 @@ static bool ShellSetFileAttributesImpl(Panel* SrcPanel, const string* Object)
}
}

AttrDlg[SA_TEXT_NAME].strData = truncate_left(QuoteOuterSpace(SingleSelFileName), DlgX - 10);
AttrDlg[SA_TEXT_NAME].strData = QuoteOuterSpace(SingleSelFileName);

const auto ComputerName = ExtractComputerName(SrcPanel?
SrcPanel->GetCurDir() :
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5821
5822

0 comments on commit 9530d5f

Please sign in to comment.