Skip to content

Commit

Permalink
Make auto-indent work on multi-editing
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Nov 15, 2023
1 parent 99364ff commit 96220c1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 30 deletions.
4 changes: 4 additions & 0 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ LRESULT Notepad_plus::init(HWND hwnd)
_mainEditView.execute(SCI_SETMULTIPASTE, SC_MULTIPASTE_EACH);
_subEditView.execute(SCI_SETMULTIPASTE, SC_MULTIPASTE_EACH);

// Turn auto-completion into each multi-select on
_mainEditView.execute(SCI_AUTOCSETMULTI, SC_MULTIAUTOC_EACH);
_subEditView.execute(SCI_AUTOCSETMULTI, SC_MULTIAUTOC_EACH);

// allow user to start selecting as a stream block, then switch to a column block by adding Alt keypress
_mainEditView.execute(SCI_SETMOUSESELECTIONRECTANGULARSWITCH, true);
_subEditView.execute(SCI_SETMOUSESELECTIONRECTANGULARSWITCH, true);
Expand Down
3 changes: 1 addition & 2 deletions PowerEditor/src/NppNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
{
const NppGUI & nppGui = NppParameters::getInstance().getNppGUI();
bool indentMaintain = nppGui._maitainIndent;
size_t nbSelections = _pEditView->execute(SCI_GETSELECTIONS);
if (indentMaintain && nbSelections <= 1) // No auto-indent if multi-edit is active
if (indentMaintain)
maintainIndentation(static_cast<TCHAR>(notification->ch));

Buffer* currentBuf = _pEditView->getCurrentBuffer();
Expand Down
113 changes: 85 additions & 28 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
}
}
}
break;
}
}
break;
Expand Down Expand Up @@ -3093,43 +3092,101 @@ void ScintillaEditView::showIndentGuideLine(bool willBeShowed)

void ScintillaEditView::setLineIndent(size_t line, size_t indent) const
{
Sci_CharacterRangeFull crange = getSelection();
int64_t posBefore = execute(SCI_GETLINEINDENTPOSITION, line);
execute(SCI_SETLINEINDENTATION, line, indent);
int64_t posAfter = execute(SCI_GETLINEINDENTPOSITION, line);
long long posDifference = posAfter - posBefore;
if (posAfter > posBefore)
{
// Move selection on
if (crange.cpMin >= posBefore)
size_t nbSelections = execute(SCI_GETSELECTIONS);

if (nbSelections == 1)
{
Sci_CharacterRangeFull crange = getSelection();
int64_t posBefore = execute(SCI_GETLINEINDENTPOSITION, line);
execute(SCI_SETLINEINDENTATION, line, indent);
int64_t posAfter = execute(SCI_GETLINEINDENTPOSITION, line);
long long posDifference = posAfter - posBefore;
if (posAfter > posBefore)
{
crange.cpMin += static_cast<Sci_Position>(posDifference);
// Move selection on
if (crange.cpMin >= posBefore)
{
crange.cpMin += static_cast<Sci_Position>(posDifference);
}
if (crange.cpMax >= posBefore)
{
crange.cpMax += static_cast<Sci_Position>(posDifference);
}
}
if (crange.cpMax >= posBefore)
else if (posAfter < posBefore)
{
crange.cpMax += static_cast<Sci_Position>(posDifference);
// Move selection back
if (crange.cpMin >= posAfter)
{
if (crange.cpMin >= posBefore)
crange.cpMin += static_cast<Sci_Position>(posDifference);
else
crange.cpMin = static_cast<Sci_Position>(posAfter);
}

if (crange.cpMax >= posAfter)
{
if (crange.cpMax >= posBefore)
crange.cpMax += static_cast<Sci_Position>(posDifference);
else
crange.cpMax = static_cast<Sci_Position>(posAfter);
}
}
execute(SCI_SETSEL, crange.cpMin, crange.cpMax);
}
else if (posAfter < posBefore)
else
{
// Move selection back
if (crange.cpMin >= posAfter)
execute(SCI_BEGINUNDOACTION);
for (size_t i = 0; i < nbSelections; ++i)
{
if (crange.cpMin >= posBefore)
crange.cpMin += static_cast<Sci_Position>(posDifference);
else
crange.cpMin = static_cast<Sci_Position>(posAfter);
}
LRESULT posStart = execute(SCI_GETSELECTIONNSTART, i);
LRESULT posEnd = execute(SCI_GETSELECTIONNEND, i);


size_t l = execute(SCI_LINEFROMPOSITION, posStart);

int64_t posBefore = execute(SCI_GETLINEINDENTPOSITION, l);
execute(SCI_SETLINEINDENTATION, l, indent);
int64_t posAfter = execute(SCI_GETLINEINDENTPOSITION, l);

long long posDifference = posAfter - posBefore;
if (posAfter > posBefore)
{
// Move selection on
if (posStart >= posBefore)
{
posStart += static_cast<Sci_Position>(posDifference);
}
if (posEnd >= posBefore)
{
posEnd += static_cast<Sci_Position>(posDifference);
}
}
else if (posAfter < posBefore)
{
// Move selection back
if (posStart >= posAfter)
{
if (posStart >= posBefore)
posStart += static_cast<Sci_Position>(posDifference);
else
posStart = static_cast<Sci_Position>(posAfter);
}

if (crange.cpMax >= posAfter)
{
if (crange.cpMax >= posBefore)
crange.cpMax += static_cast<Sci_Position>(posDifference);
else
crange.cpMax = static_cast<Sci_Position>(posAfter);
if (posEnd >= posAfter)
{
if (posEnd >= posBefore)
posEnd += static_cast<Sci_Position>(posDifference);
else
posEnd = static_cast<Sci_Position>(posAfter);
}
}

execute(SCI_SETSELECTIONNSTART, i, posStart);
execute(SCI_SETSELECTIONNEND, i, posEnd);
}
execute(SCI_ENDUNDOACTION);
}
execute(SCI_SETSEL, crange.cpMin, crange.cpMax);
}

void ScintillaEditView::updateLineNumberWidth()
Expand Down

0 comments on commit 96220c1

Please sign in to comment.