Improve single-line indentation and dedentation functionality

Fix #5721, close #8623
This commit is contained in:
Scott Sumner 2020-07-27 16:19:30 -04:00 committed by Don HO
parent e0f0dc14da
commit 7c28a120d9
2 changed files with 27 additions and 9 deletions

View File

@ -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<int>(_pEditView->execute(SCI_GETSELECTIONSTART));
int lineNumber = static_cast<int>(_pEditView->execute(SCI_LINEFROMPOSITION, selStartPos));
int numSelections = static_cast<int>(_pEditView->execute(SCI_GETSELECTIONS));
int selEndPos = static_cast<int>(_pEditView->execute(SCI_GETSELECTIONEND));
int selEndLineNumber = static_cast<int>(_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<int>(_pEditView->execute(SCI_GETLINEINDENTATION, lineNumber));
int indentDelta = static_cast<int>(_pEditView->execute(SCI_GETTABWIDTH));
if (!forwards) indentDelta = -indentDelta;
_pEditView->setLineIndent(lineNumber, currentIndent + indentDelta);
}
}
break;
case IDM_EDIT_DUP_LINE:
_pEditView->execute(SCI_LINEDUPLICATE);

View File

@ -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},