Use built in Scintilla commands for moving lines up/down

This commit is contained in:
dail8859 2016-01-14 17:21:25 -05:00 committed by Don Ho
parent ae4503ebbe
commit faf107a4ef
2 changed files with 4 additions and 81 deletions

View File

@ -2360,32 +2360,6 @@ void ScintillaEditView::setMultiSelections(const ColumnModeInfos & cmi)
} }
} }
void ScintillaEditView::currentLineUp() const
{
int currentLine = getCurrentLineNumber();
if (currentLine != 0)
{
execute(SCI_BEGINUNDOACTION);
currentLine--;
execute(SCI_LINETRANSPOSE);
execute(SCI_GOTOLINE, currentLine);
execute(SCI_ENDUNDOACTION);
}
}
void ScintillaEditView::currentLineDown() const
{
int currentLine = getCurrentLineNumber();
if (currentLine != (execute(SCI_GETLINECOUNT) - 1))
{
execute(SCI_BEGINUNDOACTION);
++currentLine;
execute(SCI_GOTOLINE, currentLine);
execute(SCI_LINETRANSPOSE);
execute(SCI_ENDUNDOACTION);
}
}
// Get selection range : (fromLine, toLine) // Get selection range : (fromLine, toLine)
// return (-1, -1) if multi-selection // return (-1, -1) if multi-selection
pair<int, int> ScintillaEditView::getSelectionLinesRange() const pair<int, int> ScintillaEditView::getSelectionLinesRange() const
@ -2409,63 +2383,15 @@ pair<int, int> ScintillaEditView::getSelectionLinesRange() const
void ScintillaEditView::currentLinesUp() const void ScintillaEditView::currentLinesUp() const
{ {
pair<int, int> lineRange = getSelectionLinesRange(); execute(SCI_MOVESELECTEDLINESUP);
if ((lineRange.first == -1 || lineRange.first == 0))
return;
bool noSel = lineRange.first == lineRange.second;
int nbSelLines = lineRange.second - lineRange.first + 1;
int line2swap = lineRange.first - 1;
int nbChar = execute(SCI_LINELENGTH, line2swap);
int posStart = execute(SCI_POSITIONFROMLINE, lineRange.first);
int posEnd = execute(SCI_GETLINEENDPOSITION, lineRange.second);
execute(SCI_BEGINUNDOACTION);
execute(SCI_GOTOLINE, line2swap);
for (int i = 0 ; i < nbSelLines ; ++i)
{
currentLineDown();
}
execute(SCI_ENDUNDOACTION);
execute(SCI_SETSELECTIONSTART, posStart - nbChar);
execute(SCI_SETSELECTIONEND, noSel?posStart - nbChar:posEnd - nbChar);
} }
void ScintillaEditView::currentLinesDown() const void ScintillaEditView::currentLinesDown() const
{ {
pair<int, int> lineRange = getSelectionLinesRange(); execute(SCI_MOVESELECTEDLINESDOWN);
if ((lineRange.first == -1 || lineRange.second >= execute(SCI_LINEFROMPOSITION, getCurrentDocLen())))
return;
bool noSel = lineRange.first == lineRange.second;
int nbSelLines = lineRange.second - lineRange.first + 1;
int line2swap = lineRange.second + 1;
int nbChar = execute(SCI_LINELENGTH, line2swap);
if ((line2swap + 1) == execute(SCI_GETLINECOUNT))
nbChar += (execute(SCI_GETEOLMODE)==SC_EOL_CRLF?2:1);
int posStart = execute(SCI_POSITIONFROMLINE, lineRange.first);
int posEnd = execute(SCI_GETLINEENDPOSITION, lineRange.second);
execute(SCI_BEGINUNDOACTION);
execute(SCI_GOTOLINE, line2swap);
for (int i = 0 ; i < nbSelLines ; ++i)
{
currentLineUp();
}
execute(SCI_ENDUNDOACTION);
execute(SCI_SETSELECTIONSTART, posStart + nbChar);
execute(SCI_SETSELECTIONEND, noSel?posStart + nbChar:posEnd + nbChar);
// Ensure the selection is within view
execute(SCI_SCROLLRANGE, execute(SCI_GETSELECTIONEND), execute(SCI_GETSELECTIONSTART));
} }
void ScintillaEditView::convertSelectedTextTo(bool Case) void ScintillaEditView::convertSelectedTextTo(bool Case)

View File

@ -539,9 +539,6 @@ public:
void expand(int &line, bool doExpand, bool force = false, int visLevels = 0, int level = -1); void expand(int &line, bool doExpand, bool force = false, int visLevels = 0, int level = -1);
void currentLineUp() const;
void currentLineDown() const;
std::pair<int, int> getSelectionLinesRange() const; std::pair<int, int> getSelectionLinesRange() const;
void currentLinesUp() const; void currentLinesUp() const;
void currentLinesDown() const; void currentLinesDown() const;