mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ fix: handling of "move lines up/down"
This commit is contained in:
parent
cf9db82068
commit
7290fbca61
71
src/Edit.c
71
src/Edit.c
@ -2180,11 +2180,11 @@ void EditSpacesToTabs(HWND hwnd,int nTabWidth,bool bOnlyIndentingWS)
|
||||
DocPos iCurPos = SciCall_GetCurrentPos();
|
||||
DocPos iAnchorPos = SciCall_GetAnchor();
|
||||
|
||||
DocPos iSelStart = SciCall_GetSelectionStart();
|
||||
DocPos const iSelStart = SciCall_GetSelectionStart();
|
||||
//DocLn iLine = SciCall_LineFromPosition(iSelStart);
|
||||
//iSelStart = SciCall_PositionFromLine(iLine); // re-base selection to start of line
|
||||
DocPos iSelEnd = SciCall_GetSelectionEnd();
|
||||
DocPos iSelCount = (iSelEnd - iSelStart);
|
||||
DocPos const iSelEnd = SciCall_GetSelectionEnd();
|
||||
DocPos const iSelCount = (iSelEnd - iSelStart);
|
||||
|
||||
const char* pszText = SciCall_GetRangePointer(iSelStart, iSelCount);
|
||||
|
||||
@ -2277,18 +2277,61 @@ void EditSpacesToTabs(HWND hwnd,int nTabWidth,bool bOnlyIndentingWS)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _EditMoveLines()
|
||||
//
|
||||
static void __fastcall _EditMoveLines(bool bMoveUp)
|
||||
{
|
||||
if (SciCall_IsSelectionRectangle()) {
|
||||
MsgBoxLng(MBWARN, IDS_MUI_SELRECT);
|
||||
}
|
||||
else {
|
||||
|
||||
DocPos const iSelBeg = SciCall_GetSelectionStart();
|
||||
DocPos const iSelEnd = SciCall_GetSelectionEnd();
|
||||
DocLn const iBegLine = SciCall_LineFromPosition(iSelBeg);
|
||||
DocLn const iEndLine = SciCall_LineFromPosition(iSelEnd);
|
||||
|
||||
DocLn lastLine = Sci_GetLastDocLineNumber();
|
||||
|
||||
if (Sci_GetNetLineLength(lastLine) == 0) { --lastLine; }
|
||||
|
||||
bool const bCanMove = bMoveUp ? (iBegLine > 0) : (iEndLine < lastLine);
|
||||
if (bCanMove) {
|
||||
|
||||
bool const bForwardSelection = Sci_IsForwardSelection();
|
||||
int const direction = (bMoveUp ? -1 : 1);
|
||||
|
||||
DocPos const iBegChCount = SciCall_CountCharacters(SciCall_PositionFromLine(iBegLine), iSelBeg);
|
||||
DocPos const iEndChCount = SciCall_CountCharacters(SciCall_PositionFromLine(iEndLine), iSelEnd);
|
||||
|
||||
if (bMoveUp)
|
||||
SciCall_MoveSelectedLinesUp();
|
||||
else
|
||||
SciCall_MoveSelectedLinesDown();
|
||||
|
||||
DocPos const iNewSelBeg = SciCall_PositionRelative(SciCall_PositionFromLine(iBegLine + direction), iBegChCount);
|
||||
DocPos const iNewSelEnd = SciCall_PositionRelative(SciCall_PositionFromLine(iEndLine + direction), iEndChCount);
|
||||
|
||||
if (bForwardSelection)
|
||||
SciCall_SetSel(iNewSelBeg, iNewSelEnd);
|
||||
else
|
||||
SciCall_SetSel(iNewSelEnd, iNewSelBeg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditMoveUp()
|
||||
//
|
||||
void EditMoveUp(HWND hwnd)
|
||||
{
|
||||
if (SciCall_IsSelectionRectangle()) {
|
||||
MsgBoxLng(MBWARN, IDS_MUI_SELRECT);
|
||||
}
|
||||
else {
|
||||
SendMessage(hwnd, SCI_MOVESELECTEDLINESUP, 0, 0);
|
||||
}
|
||||
UNUSED(hwnd);
|
||||
_EditMoveLines(true);
|
||||
}
|
||||
|
||||
|
||||
@ -2298,12 +2341,8 @@ void EditMoveUp(HWND hwnd)
|
||||
//
|
||||
void EditMoveDown(HWND hwnd)
|
||||
{
|
||||
if (SciCall_IsSelectionRectangle()) {
|
||||
MsgBoxLng(MBWARN, IDS_MUI_SELRECT);
|
||||
}
|
||||
else {
|
||||
SendMessage(hwnd, SCI_MOVESELECTEDLINESDOWN, 0, 0);
|
||||
}
|
||||
UNUSED(hwnd);
|
||||
_EditMoveLines(false);
|
||||
}
|
||||
|
||||
|
||||
@ -3130,7 +3169,7 @@ static DocPos __fastcall _AppendSpaces(HWND hwnd, DocLn iLineStart, DocLn iLineE
|
||||
//
|
||||
void EditPadWithSpaces(HWND hwnd, bool bSkipEmpty, bool bNoUndoGroup)
|
||||
{
|
||||
if (SciCall_IsSelectionEmpty() || Sci_IsThinRectangleSelected()) { return; }
|
||||
if (SciCall_IsSelectionEmpty()) { return; }
|
||||
|
||||
int const token = (!bNoUndoGroup ? BeginUndoAction() : -1);
|
||||
|
||||
|
||||
@ -222,7 +222,6 @@ DeclareSciCallR1(PositionAfter, POSITIONAFTER, DocPos, DocPos, position)
|
||||
DeclareSciCallR1(GetCharAt, GETCHARAT, char, DocPos, position)
|
||||
DeclareSciCallR0(GetEOLMode, GETEOLMODE, int)
|
||||
|
||||
DeclareSciCallR2(CountCharacters, COUNTCHARACTERS, DocPos, DocPos, startpos, DocPos, endpos)
|
||||
DeclareSciCallR0(GetLineCount, GETLINECOUNT, DocLn)
|
||||
DeclareSciCallR0(GetTextLength, GETTEXTLENGTH, DocPos)
|
||||
DeclareSciCallR1(LineLength, LINELENGTH, DocPos, DocLn, line)
|
||||
@ -232,6 +231,8 @@ DeclareSciCallR1(GetLineEndPosition, GETLINEENDPOSITION, DocPos, DocLn, line)
|
||||
DeclareSciCallR1(GetColumn, GETCOLUMN, DocPos, DocPos, position)
|
||||
DeclareSciCallR2(FindColumn, FINDCOLUMN, DocPos, DocLn, line, DocPos, column)
|
||||
DeclareSciCallR1(GetLineIndentPosition, GETLINEINDENTPOSITION, DocPos, DocLn, line)
|
||||
DeclareSciCallR2(CountCharacters, COUNTCHARACTERS, DocPos, DocPos, startpos, DocPos, endpos)
|
||||
DeclareSciCallR2(PositionRelative, POSITIONRELATIVE, DocPos, DocPos, startpos, DocPos, relative)
|
||||
|
||||
DeclareSciCallR2(GetRangePointer, GETRANGEPOINTER, char* const, DocPos, start, DocPos, length)
|
||||
DeclareSciCallR0(GetCharacterPointer, GETCHARACTERPOINTER, char* const)
|
||||
@ -246,6 +247,8 @@ DeclareSciCallV1(SetVirtualSpaceOptions, SETVIRTUALSPACEOPTIONS, int, options)
|
||||
// Commands
|
||||
//
|
||||
DeclareSciCallV0(NewLine, NEWLINE)
|
||||
DeclareSciCallV0(MoveSelectedLinesUp, MOVESELECTEDLINESUP)
|
||||
DeclareSciCallV0(MoveSelectedLinesDown, MOVESELECTEDLINESDOWN)
|
||||
|
||||
|
||||
//=============================================================================
|
||||
@ -353,7 +356,7 @@ DeclareSciCallV1(EnsureVisibleEnforcePolicy, ENSUREVISIBLEENFORCEPOLICY, DocLn,
|
||||
//
|
||||
// Lexer
|
||||
//
|
||||
DeclareSciCallV2(SetProperty, SETPROPERTY, const char *, key, const char *, value)
|
||||
DeclareSciCallV2(SetProperty, SETPROPERTY, const char*, key, const char*, value)
|
||||
DeclareSciCallV2(Colourise, COLOURISE, DocPos, startPos, DocPos, endPos)
|
||||
|
||||
|
||||
@ -391,10 +394,9 @@ DeclareSciCallV1(SetBidirectional, SETBIDIRECTIONAL, int, direction)
|
||||
DeclareSciCallR1(BraceMatch, BRACEMATCH, DocPos, DocPos, position)
|
||||
DeclareSciCallR0(IsSelectionEmpty, GETSELECTIONEMPTY, bool)
|
||||
DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool)
|
||||
#define Sci_IsStreamSelected() (SciCall_GetSelectionMode() == SC_SEL_STREAM)
|
||||
#define Sci_IsFullLineSelected() (SciCall_GetSelectionMode() == SC_SEL_LINES)
|
||||
#define Sci_IsThinRectangleSelected() (SciCall_GetSelectionMode() == SC_SEL_THIN)
|
||||
|
||||
#define Sci_IsSingleLineSelection() (SciCall_LineFromPosition(SciCall_GetCurrentPos()) == SciCall_LineFromPosition(SciCall_GetAnchor()))
|
||||
#define Sci_IsForwardSelection() (SciCall_GetAnchor() <= SciCall_GetCurrentPos())
|
||||
|
||||
#define Sci_GetEOLLen() ((SciCall_GetEOLMode() == SC_EOL_CRLF) ? 2 : 1)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user