Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Dec 3, 2024
1 parent d7896f3 commit 90f96e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 37 deletions.
14 changes: 10 additions & 4 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1003,21 +1003,27 @@ void Editor::MoveSelectedLines(int lineDelta) {
// if selection doesn't end at the beginning of a line greater than that of the start,
// then set it at the beginning of the next one
Sci::Position selectionEnd = SelectionEnd().Position();
const Sci::Line endLine = pdoc->SciLineFromPosition(selectionEnd);
Sci::Line endLine = pdoc->SciLineFromPosition(selectionEnd);
const Sci::Position beginningOfEndLine = pdoc->LineStart(endLine);
const Sci::Position docLength = pdoc->LengthNoExcept();
bool appendEol = false;
if (selectionEnd > beginningOfEndLine
|| selectionStart == selectionEnd) {
selectionEnd = pdoc->LineStart(endLine + 1);
appendEol = (selectionEnd == pdoc->LengthNoExcept() && pdoc->SciLineFromPosition(selectionEnd) == endLine);
const Sci::Line line = pdoc->SciLineFromPosition(selectionEnd);
appendEol = (line == endLine && selectionEnd == docLength);
endLine = line;
}

// if there's nowhere for the selection to move
// (i.e. at the beginning going up or at the end going down),
// stop it right there!
const bool docEndLineEmpty = pdoc->LineStart(endLine) == docLength;
if ((selectionStart == 0 && lineDelta < 0)
|| (selectionEnd == pdoc->LengthNoExcept() && lineDelta > 0)
|| selectionStart == selectionEnd) {
|| (selectionEnd == docLength && lineDelta > 0
&& !docEndLineEmpty) // allow moving when end line of document is empty
|| ((selectionStart == selectionEnd)
&& !(lineDelta < 0 && docEndLineEmpty && selectionEnd == docLength))) { // allow moving-up last empty line
return;
}

Expand Down
33 changes: 0 additions & 33 deletions src/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2642,11 +2642,6 @@ void EditMoveUp() noexcept {
return;
}

if (SciCall_IsRectangleSelection()) {
NotifyRectangleSelection();
return;
}

const Sci_Line iLineSrc = min(iCurLine, iAnchorLine) - 1;
if (iLineSrc >= 0) {
Sci_Line iLineDest = max(iCurLine, iAnchorLine);
Expand Down Expand Up @@ -2694,42 +2689,14 @@ void EditMoveDown() noexcept {
return;
}

if (SciCall_IsRectangleSelection()) {
NotifyRectangleSelection();
return;
}

Sci_Line iLineSrc = max(iCurLine, iAnchorLine) + 1;
if (max(iCurPos, iAnchorPos) <= SciCall_PositionFromLine(iLineSrc - 1)) {
iLineSrc--;
}

const Sci_Line iLineEnd = SciCall_GetLineCount() - 1;
if (iLineSrc <= iLineEnd) {
const bool bLastLine = (iLineSrc == iLineEnd);

if (bLastLine &&
(SciCall_GetLineEndPosition(iLineSrc) == SciCall_PositionFromLine(iLineSrc)) &&
(SciCall_GetLineEndPosition(iLineSrc - 1) == SciCall_PositionFromLine(iLineSrc - 1))) {
return;
}

if (bLastLine) {
SciCall_BeginUndoAction();
const unsigned iEOLMode = SciCall_GetEOLMode();
LPCSTR lineEnd = "\r\n";
lineEnd += (iEOLMode >> 1);
SciCall_AppendText((iEOLMode == SC_EOL_CRLF) ? 2 : 1, lineEnd);
}

SciCall_MoveSelectedLinesDown();

if (bLastLine) {
const Sci_Position iLineEndPos = SciCall_GetLineEndPosition(SciCall_GetLineCount() - 2);
SciCall_DeleteRange(iLineEndPos, SciCall_GetLength() - iLineEndPos);
SciCall_EndUndoAction();
}

if (iCurPos < iAnchorPos) {
iCurLine = iCurLine + 1;
iAnchorLine = iLineSrc + 1;
Expand Down

0 comments on commit 90f96e5

Please sign in to comment.