From 324b638abcd4f7812adbd3abd7e401aef97099a8 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 26 Jan 2018 09:17:05 +0100 Subject: [PATCH] + fix: TAB indentation handling according to predecessors (NP2) --- src/Edit.c | 8 +++---- src/Notepad3.c | 60 +++++++++++++++++++++++++++++++++---------------- src/Notepad3.rc | 4 ++-- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 5ad29bac6..3b88e35ca 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -3307,11 +3307,11 @@ void EditCompressSpaces(HWND hwnd) const int iNewLen = StringCchLenA(pszOut, LocalSize(pszOut)); - if (iCurPos > iAnchorPos) { - EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iNewLen); + if (iCurPos < iAnchorPos) { + EditSelectEx(hwnd, iCurPos + iNewLen, iCurPos); } - else if (iCurPos < iAnchorPos) { - EditSelectEx(hwnd, iCurPos, iCurPos + iNewLen); + else if (iCurPos > iAnchorPos) { + EditSelectEx(hwnd, iAnchorPos, iAnchorPos + iNewLen); } else { // empty selection int iNewPos = iCurPos; diff --git a/src/Notepad3.c b/src/Notepad3.c index ecd94fe3a..9debc1e2d 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -3324,18 +3324,53 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case IDM_EDIT_INDENT: { - int token = BeginUndoAction(); - SendMessage(g_hwndEdit,SCI_TAB,0,0); - EndUndoAction(token); + int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction(); + + if (bTabIndents && !SciCall_IsSelectionEmpty()) { + const int iLineSelStart = SciCall_LineFromPosition(SciCall_GetSelectionStart()); + const int iLineSelEnd = SciCall_LineFromPosition(SciCall_GetSelectionEnd()); + if (iLineSelStart == iLineSelEnd) { + SendMessage(g_hwndEdit, SCI_VCHOME, 0, 0); + } + } + + SendMessage(g_hwndEdit, SCI_TAB, 0, 0); + + if (token >= 0) { EndUndoAction(token); } } break; case IDM_EDIT_UNINDENT: { - int token = BeginUndoAction(); - SendMessage(g_hwndEdit,SCI_BACKTAB,0,0); - EndUndoAction(token); + int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction(); + + if (bTabIndents && !SciCall_IsSelectionEmpty()) { + const int iLineSelStart = SciCall_LineFromPosition(SciCall_GetSelectionStart()); + const int iLineSelEnd = SciCall_LineFromPosition(SciCall_GetSelectionEnd()); + if (iLineSelStart == iLineSelEnd) { + SendMessage(g_hwndEdit, SCI_VCHOME, 0, 0); + } + } + + SendMessage(g_hwndEdit, SCI_BACKTAB, 0, 0); + + if (token >= 0) { EndUndoAction(token); } + } + break; + + + case CMD_CTRLTAB: + { + int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction(); + + SendMessage(g_hwndEdit, SCI_SETTABINDENTS, FALSE, 0); + SendMessage(g_hwndEdit, SCI_SETUSETABS, TRUE, 0); + SendMessage(g_hwndEdit, SCI_TAB, 0, 0); + SendMessage(g_hwndEdit, SCI_SETUSETABS, !bTabsAsSpaces, 0); + SendMessage(g_hwndEdit, SCI_SETTABINDENTS, bTabIndents, 0); + + if (token >= 0) { EndUndoAction(token); } } break; @@ -4865,19 +4900,6 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) break; - case CMD_CTRLTAB: - { - int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction(); - SendMessage(g_hwndEdit,SCI_SETTABINDENTS,FALSE,0); - SendMessage(g_hwndEdit,SCI_SETUSETABS,TRUE,0); - SendMessage(g_hwndEdit,SCI_TAB,0,0); - SendMessage(g_hwndEdit,SCI_SETUSETABS,!bTabsAsSpaces,0); - SendMessage(g_hwndEdit,SCI_SETTABINDENTS,bTabIndents,0); - if (token >= 0) EndUndoAction(token); - } - break; - - case CMD_RECODEDEFAULT: { WCHAR tchCurFile2[MAX_PATH] = { L'\0' }; diff --git a/src/Notepad3.rc b/src/Notepad3.rc index e7b4e9d6d..36485ff8f 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -181,8 +181,8 @@ BEGIN END POPUP "&Block" BEGIN - MENUITEM "&Indent\tTab", IDM_EDIT_INDENT - MENUITEM "&Unindent\tShift+Tab", IDM_EDIT_UNINDENT + MENUITEM "&Indent\tTab", IDM_EDIT_INDENT + MENUITEM "&Unindent\tShift+Tab", IDM_EDIT_UNINDENT MENUITEM SEPARATOR POPUP "&Enclose Selection" BEGIN