Works up through 15.0.1 and verified using the 16.0 trial...
#import "box.e";
#import "clipbd.e";
#import "moveline.e";
#import "stdcmds.e";
#import "util.e";
static class Selection {
private _str m_selectionType = null;
private int m_startCol = 0;
private int m_startLine = 0;
private int m_endCol = 0;
private int m_endLine = 0;
private int m_currentCol = 0;
private int m_currentLine = 0;
private boolean m_isInclusive = false;
private boolean m_isPersistent = false;
private int m_windowTop = 0;
private int m_windowBottom = 0;
public void save() {
m_selectionType = _select_type('', 'T');
if (m_selectionType == null) {
m_startCol = m_endCol = m_currentCol = p_col;
m_startLine = m_endLine = m_currentLine = p_line;
m_selectionType = null;
} else {
m_isInclusive = _select_type('', 'I') == 1;
m_isPersistent = _select_type('', 'U') == 'P';
m_currentCol = p_col;
m_currentLine = p_line;
_begin_select('', true, true);
m_startCol = p_col;
m_startLine = p_line;
_end_select('', true, true);
m_endCol = p_col;
m_endLine = p_line;
// restore is beginning to end. If we've selected bottom-up, need to swap these.
if (! m_isPersistent && m_currentCol == m_startCol && m_currentLine == m_startLine) {
int swap = m_startCol;
m_startCol = m_endCol;
m_endCol = swap;
swap = m_startLine;
m_startLine = m_endLine;
m_endLine = swap;
}
}
top_left_of_window();
m_windowTop = p_line;
bottom_left_of_window();
m_windowBottom = p_line;
}
public void selectLines(_str style = 'ECLIPSE') {
_deselect();
p_line = m_startLine;
_select_line('', 'P');
p_line = m_endLine;
if (style == 'ECLIPSE' && ! m_isInclusive && m_selectionType == 'CHAR' && m_endCol == 1 &&
m_endLine > m_startLine) {
p_line--;
}
_select_line('', 'P');
}
public void restore() {
_deselect();
if (m_selectionType != null) {
p_col = m_endCol;
p_line = m_endLine;
_str options = 'C';
if (m_isPersistent) {
options = options :+ 'P';
}
if (m_selectionType == 'CHAR' && m_isInclusive) {
options = options :+ 'I';
}
select_it(m_selectionType, '', options);
p_col = m_startCol;
p_line = m_startLine;
}
if (m_isPersistent) {
p_col = m_currentCol;
p_line = m_currentLine;
}
}
public void delete() {
save();
selectLines();
_delete_selection();
m_currentLine = p_line;
goto_line(m_windowTop);
line_to_top();
p_col = m_currentCol;
p_line = m_currentLine;
}
public void moveUp() {
save();
selectLines();
move_lines_up();
_begin_select('', true, true);
if (m_startLine > 0) {
m_startLine--;
m_endLine--;
m_currentLine--;
if (m_startLine >= m_windowTop) {
goto_line(m_windowTop);
line_to_top();
}
}
restore();
}
public void moveDown() {
save();
selectLines();
move_lines_down();
_end_select('', true, true);
if (p_line > m_endLine) {
m_startLine++;
m_endLine++;
m_currentLine++;
}
restore();
}
public void comment() {
save();
selectLines();
toggle_comment();
restore();
}
public _str toString() {
_str result = '';
result = result :+ "selectionType=" :+ m_selectionType;
result = result :+ ",startCol=" :+ m_startCol;
result = result :+ ",startLine=" :+ m_startLine;
result = result :+ ",endCol=" :+ m_endCol;
result = result :+ ",endLine=" :+ m_endLine;
result = result :+ ",currentCol=" :+ m_currentCol;
result = result :+ ",currentLine=" :+ m_currentLine;
result = result :+ ",isInclusive=" :+ m_isInclusive;
result = result :+ ",isPersistent=" :+ m_isPersistent;
return result;
}
};
_command void eclipse_delete_lines() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
Selection selection;
selection.delete();
}
_command void eclipse_move_lines_up() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
Selection selection;
selection.moveUp();
}
_command void eclipse_move_lines_down() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
Selection selection;
selection.moveDown();
}
_command void eclipse_toggle_comment() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
Selection selection;
selection.comment();
}