+ fix: sensible handling of "Block -> (Un)Indent" for different kinds of selections

This commit is contained in:
Rainer Kottenhoff 2018-01-29 00:11:45 +01:00
parent 527a4edc45
commit 109ebe4b03
5 changed files with 70 additions and 17 deletions

View File

@ -2553,6 +2553,41 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
}
//=============================================================================
//
// EditIndentBlock()
//
void EditIndentBlock(HWND hwnd, BOOL bIndent, BOOL bTabIndents, BOOL bBackspaceUnindents)
{
const int iCurPos = SciCall_GetCurrentPos();
const int iAnchorPos = SciCall_GetAnchor();
const int iCurLine = SciCall_LineFromPosition(iCurPos);
const BOOL bSingleLine = (iCurLine == SciCall_LineFromPosition(iAnchorPos));
int iDiff = 0;
if (bSingleLine) {
SendMessage(hwnd, SCI_VCHOME, 0, 0);
if (SciCall_PositionFromLine(iCurLine) == SciCall_GetCurrentPos()) {
SendMessage(hwnd, SCI_VCHOME, 0, 0);
}
iDiff = (iCurPos - SciCall_GetCurrentPos());
}
if (bIndent) {
SendMessage(hwnd, SCI_SETTABINDENTS, TRUE, 0);
SendMessage(hwnd, SCI_TAB, 0, 0);
SendMessage(hwnd, SCI_SETTABINDENTS, bTabIndents, 0);
}
else if (SciCall_PositionFromLine(iCurLine) != SciCall_GetSelectionStart()) {
SendMessage(hwnd, SCI_SETBACKSPACEUNINDENTS, TRUE, 0);
SendMessage(hwnd, SCI_DELETEBACK, 0, 0);
SendMessage(hwnd, SCI_SETBACKSPACEUNINDENTS, bBackspaceUnindents, 0);
}
if (bSingleLine) {
EditSelectEx(hwnd, SciCall_GetCurrentPos() + iDiff + (iAnchorPos - iCurPos), SciCall_GetCurrentPos() + iDiff);
}
}
//=============================================================================
//
// EditAlignText()
@ -2783,8 +2818,8 @@ void EditAlignText(HWND hwnd,int nMode)
SendMessage(hwnd, SCI_SETTARGETRANGE, iPos, SciCall_GetLineEndPosition(iLine));
SendMessage(hwnd, SCI_REPLACETARGET, (WPARAM)cch, (LPARAM)tchLineBuf);
if (nMode == ALIGN_LEFT)
SendMessage(hwnd, SCI_SETLINEINDENTATION, (WPARAM)iLine, (LPARAM)iMinIndent);
if (nMode == ALIGN_LEFT)
SendMessage(hwnd, SCI_SETLINEINDENTATION, (WPARAM)iLine, (LPARAM)iMinIndent);
}
}
}
@ -2814,6 +2849,7 @@ SendMessage(hwnd, SCI_SETLINEINDENTATION, (WPARAM)iLine, (LPARAM)iMinIndent);
}
//=============================================================================
//
// EditEncloseSelection()

View File

@ -88,6 +88,7 @@ void EditSpacesToTabs(HWND,int,BOOL);
void EditMoveUp(HWND);
void EditMoveDown(HWND);
void EditModifyLines(HWND,LPCWSTR,LPCWSTR);
void EditIndentBlock(HWND,BOOL,BOOL,BOOL);
void EditAlignText(HWND,int);
void EditEncloseSelection(HWND,LPCWSTR,LPCWSTR);
void EditToggleLineComments(HWND,LPCWSTR,BOOL);

View File

@ -2169,8 +2169,8 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
//EnableCmd(hmenu,IDM_EDIT_COPYLINE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_DELETELINE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_INDENT,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_UNINDENT,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_INDENT,i /*&& !bReadOnly*/);
//EnableCmd(hmenu,IDM_EDIT_UNINDENT,i /*&& !bReadOnly*/);
//EnableCmd(hmenu,IDM_EDIT_PADWITHSPACES,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_STRIP1STCHAR,!bReadOnly);
@ -2179,9 +2179,9 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
//EnableCmd(hmenu,IDM_EDIT_MERGEBLANKLINES,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_REMOVEBLANKLINES,!bReadOnly);
EnableCmd(hmenu,IDM_EDIT_SORTLINES,
SendMessage(g_hwndEdit,SCI_LINEFROMPOSITION,(WPARAM)SendMessage(g_hwndEdit,SCI_GETSELECTIONEND,0,0),0) -
SendMessage(g_hwndEdit,SCI_LINEFROMPOSITION,(WPARAM)SendMessage(g_hwndEdit,SCI_GETSELECTIONSTART,0,0),0) >= 1);
EnableCmd(hmenu, IDM_EDIT_SORTLINES,
(SciCall_LineFromPosition(SciCall_GetSelectionEnd()) -
SciCall_LineFromPosition(SciCall_GetSelectionStart())) >= 1);
EnableCmd(hmenu,IDM_EDIT_COLUMNWRAP,i /*&& IsWindowsNT()*/);
EnableCmd(hmenu,IDM_EDIT_SPLITLINES,i /*&& !bReadOnly*/);
@ -3128,7 +3128,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_INDENT:
{
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
SendMessage(g_hwndEdit, SCI_TAB, 0, 0);
EditIndentBlock(g_hwndEdit, TRUE, bTabIndents, bBackspaceUnindents);
if (token >= 0) { EndUndoAction(token); }
}
break;
@ -3137,22 +3137,36 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_UNINDENT:
{
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
SendMessage(g_hwndEdit, SCI_BACKTAB, 0, 0);
EditIndentBlock(g_hwndEdit, FALSE, bTabIndents, bBackspaceUnindents);
if (token >= 0) { EndUndoAction(token); }
}
break;
case CMD_TAB:
{
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
SendMessage(g_hwndEdit, SCI_TAB, 0, 0);
if (token >= 0) { EndUndoAction(token); }
}
break;
case CMD_BACKTAB:
{
int token = SciCall_IsSelectionEmpty() ? -1 : BeginUndoAction();
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_SETTABINDENTS, FALSE, 0);
SendMessage(g_hwndEdit, SCI_TAB, 0, 0);
SendMessage(g_hwndEdit, SCI_SETUSETABS, !bTabsAsSpaces, 0);
SendMessage(g_hwndEdit, SCI_SETTABINDENTS, bTabIndents, 0);
SendMessage(g_hwndEdit, SCI_SETUSETABS, !bTabsAsSpaces, 0);
if (token >= 0) { EndUndoAction(token); }
}
break;

View File

@ -181,8 +181,8 @@ BEGIN
END
POPUP "&Block"
BEGIN
MENUITEM "&Indent\tTab", IDM_EDIT_INDENT
MENUITEM "&Unindent\tShift+Tab", IDM_EDIT_UNINDENT
MENUITEM "&Indent\t(Tab)", IDM_EDIT_INDENT
MENUITEM "&Unindent\t(Shift+Tab)", IDM_EDIT_UNINDENT
MENUITEM SEPARATOR
POPUP "&Enclose Selection"
BEGIN
@ -597,8 +597,8 @@ BEGIN
VK_SUBTRACT, IDM_VIEW_ZOOMOUT, VIRTKEY, CONTROL, NOINVERT
VK_SUBTRACT, CMD_DECLINELIMIT, VIRTKEY, ALT, NOINVERT
VK_SUBTRACT, CMD_DECREASENUM, VIRTKEY, CONTROL, ALT, NOINVERT
VK_TAB, IDM_EDIT_INDENT, VIRTKEY, NOINVERT
VK_TAB, IDM_EDIT_UNINDENT, VIRTKEY, SHIFT, NOINVERT
VK_TAB, CMD_TAB, VIRTKEY, NOINVERT
VK_TAB, CMD_BACKTAB, VIRTKEY, SHIFT, NOINVERT
VK_TAB, CMD_CTRLTAB, VIRTKEY, CONTROL, NOINVERT
VK_UP, CMD_ALTUP, VIRTKEY, ALT, NOINVERT
VK_UP, IDM_EDIT_MOVELINEUP, VIRTKEY, SHIFT, CONTROL, NOINVERT

View File

@ -227,6 +227,8 @@
#define CMD_ALTDOWN 20043
#define CMD_ALTLEFT 20044
#define CMD_ALTRIGHT 20045
#define CMD_TAB 20046
#define CMD_BACKTAB 20047
#define IDM_FILE_NEW 40000
#define IDM_FILE_OPEN 40001
#define IDM_FILE_REVERT 40002