From 7c28a120d953d03a514100609bee2c4ab1b63021 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Mon, 27 Jul 2020 16:19:30 -0400 Subject: [PATCH] Improve single-line indentation and dedentation functionality Fix #5721, close #8623 --- PowerEditor/src/NppCommands.cpp | 28 +++++++++++++++++++++++----- PowerEditor/src/Parameters.cpp | 8 ++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 4693dfbfe..bec2ab212 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1419,12 +1419,30 @@ void Notepad_plus::command(int id) break; case IDM_EDIT_INS_TAB: - _pEditView->execute(SCI_TAB); - break; - case IDM_EDIT_RMV_TAB: - _pEditView->execute(SCI_BACKTAB); - break; + { + bool forwards = id == IDM_EDIT_INS_TAB; + int selStartPos = static_cast(_pEditView->execute(SCI_GETSELECTIONSTART)); + int lineNumber = static_cast(_pEditView->execute(SCI_LINEFROMPOSITION, selStartPos)); + int numSelections = static_cast(_pEditView->execute(SCI_GETSELECTIONS)); + int selEndPos = static_cast(_pEditView->execute(SCI_GETSELECTIONEND)); + int selEndLineNumber = static_cast(_pEditView->execute(SCI_LINEFROMPOSITION, selEndPos)); + if ((numSelections > 1) || (lineNumber != selEndLineNumber)) + { + // multiple-selection or multi-line selection; use Scintilla SCI_TAB / SCI_BACKTAB behavior + _pEditView->execute(forwards ? SCI_TAB : SCI_BACKTAB); + } + else + { + // zero-length selection (simple single caret) or selected text is all on single line + // depart from Scintilla behavior and do it our way + int currentIndent = static_cast(_pEditView->execute(SCI_GETLINEINDENTATION, lineNumber)); + int indentDelta = static_cast(_pEditView->execute(SCI_GETTABWIDTH)); + if (!forwards) indentDelta = -indentDelta; + _pEditView->setLineIndent(lineNumber, currentIndent + indentDelta); + } + } + break; case IDM_EDIT_DUP_LINE: _pEditView->execute(SCI_LINEDUPLICATE); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 4ec6ca8ee..765caa55d 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -117,8 +117,8 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_NULL, IDM_EDIT_FULLPATHTOCLIP, false, false, false, nullptr }, { VK_NULL, IDM_EDIT_FILENAMETOCLIP, false, false, false, nullptr }, { VK_NULL, IDM_EDIT_CURRENTDIRTOCLIP, false, false, false, nullptr }, -// { VK_NULL, IDM_EDIT_INS_TAB, false, false, false, nullptr }, -// { VK_NULL, IDM_EDIT_RMV_TAB, false, false, false, nullptr }, + { VK_NULL, IDM_EDIT_INS_TAB, false, false, false, nullptr }, + { VK_NULL, IDM_EDIT_RMV_TAB, false, false, false, nullptr }, { VK_U, IDM_EDIT_UPPERCASE, true, false, true, nullptr }, { VK_U, IDM_EDIT_LOWERCASE, true, false, false, nullptr }, { VK_U, IDM_EDIT_PROPERCASE_FORCE, false, true, false, nullptr }, @@ -427,8 +427,8 @@ static const ScintillaKeyDefinition scintKeyDefs[] = {TEXT(""), SCI_REDO, true, false, true, VK_Z, 0}, {TEXT("SCI_NEWLINE"), SCI_NEWLINE, false, false, false, VK_RETURN, 0}, {TEXT(""), SCI_NEWLINE, false, false, true, VK_RETURN, 0}, - {TEXT("SCI_TAB"), SCI_TAB, false, false, false, VK_TAB, IDM_EDIT_INS_TAB}, - {TEXT("SCI_BACKTAB"), SCI_BACKTAB, false, false, true, VK_TAB, IDM_EDIT_RMV_TAB}, + {TEXT("SCI_TAB"), SCI_TAB, false, false, false, VK_TAB, 0}, + {TEXT("SCI_BACKTAB"), SCI_BACKTAB, false, false, true, VK_TAB, 0}, {TEXT("SCI_FORMFEED"), SCI_FORMFEED, false, false, false, 0, 0}, {TEXT("SCI_ZOOMIN"), SCI_ZOOMIN, true, false, false, VK_ADD, IDM_VIEW_ZOOMIN}, {TEXT("SCI_ZOOMOUT"), SCI_ZOOMOUT, true, false, false, VK_SUBTRACT, IDM_VIEW_ZOOMOUT},