Skip to content

Commit

Permalink
Fix DELETE key not working in multi-editing for EOL
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Nov 16, 2023
1 parent 3e7425f commit c517985
Showing 1 changed file with 53 additions and 25 deletions.
78 changes: 53 additions & 25 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,58 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa

case WM_KEYDOWN:
{
if ((execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) || (execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN))
SHORT ctrl = GetKeyState(VK_CONTROL);
SHORT alt = GetKeyState(VK_MENU);
SHORT shift = GetKeyState(VK_SHIFT);
bool isColumnSelection = (execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) || (execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN);

if (wParam == VK_DELETE)
{
// 1 shortcut:
// Shift + Delete: without selected text, it will delete the whole line.
//
if ((shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000) && !hasSelection()) // Shift-DEL & no selection
{
execute(SCI_LINEDELETE);
return TRUE;
}
else if (!(shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000)) // DEL & Multi-edit
{
size_t nbSelections = execute(SCI_GETSELECTIONS);
if (nbSelections > 1)
{
execute(SCI_BEGINUNDOACTION);
for (size_t i = 0; i < nbSelections; ++i)
{
LRESULT posStart = execute(SCI_GETSELECTIONNSTART, i);
LRESULT posEnd = execute(SCI_GETSELECTIONNEND, i);
if (posStart != posEnd)
{
replaceTarget(L"", posStart, posEnd);
}
else // posStart == posEnd)
{
char eolStr[3];
Sci_TextRange tr;
tr.chrg.cpMin = posStart;
tr.chrg.cpMax = posEnd + 2;
tr.lpstrText = eolStr;
execute(SCI_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));

int len = (eolStr[0] == '\r' && eolStr[1] == '\n') ? 2 : 1;

replaceTarget(L"", posStart, posEnd + len);
}

execute(SCI_SETSELECTIONNSTART, i, posStart);
execute(SCI_SETSELECTIONNEND, i, posStart);
}
execute(SCI_ENDUNDOACTION);
return TRUE;
}
}
}
else if (isColumnSelection)
{
//
// Transform the column selection to multi-edit
Expand Down Expand Up @@ -541,35 +592,15 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
else
{
//
// Add 3 shortcuts:
// Shift + Delete: without selected text, it will delete the whole line.
// 2 shortcuts:
// Ctrl + C: without selected text, it will copy the whole line.
// Ctrl + X: without selected text, it will cut the whole line.
//
switch (wParam)
{
case VK_DELETE:
{
SHORT ctrl = GetKeyState(VK_CONTROL);
SHORT alt = GetKeyState(VK_MENU);
SHORT shift = GetKeyState(VK_SHIFT);
if ((shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000)) // Shift-DEL
{
if (!hasSelection())
{
execute(SCI_LINEDELETE);
return TRUE;
}
}
}
break;

case 'C':
case 'X':
{
SHORT ctrl = GetKeyState(VK_CONTROL);
SHORT alt = GetKeyState(VK_MENU);
SHORT shift = GetKeyState(VK_SHIFT);
if ((ctrl & 0x8000) && !(alt & 0x8000) && !(shift & 0x8000))
{
if (!hasSelection())
Expand All @@ -584,9 +615,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa

case 'V':
{
SHORT ctrl = GetKeyState(VK_CONTROL);
SHORT alt = GetKeyState(VK_MENU);
SHORT shift = GetKeyState(VK_SHIFT);
if ((ctrl & 0x8000) && !(alt & 0x8000) && !(shift & 0x8000))
{
Buffer* buf = getCurrentBuffer();
Expand Down

0 comments on commit c517985

Please sign in to comment.