#3831 Move lines up and down macros move too many lines

open
nobody
macros (55)
5
2014-01-13
2013-09-19
Dale Anson
No
0 up votes | 0 down votes | 0%
6 comments

The move lines up and move lines down macros move too many lines and alters the selection.

To reproduce:
1. Open a buffer with several lines of text
2. Using the keyboard, move the caret to the start of the first line
3. Using the keyboard, select the first 2 lines (shift + down arrow twice). The caret will now be on the start of the third line.
4. Run the move lines down macro. Notice the first 3 lines move, even though only the first 2 lines were selected.

I expect only the 2 lines that I selected will be moved. Same issue with move lines up.

Also, the selection is extended. To see this, paste this example text into a buffer:

// if nothing is selected, select current line
if (selection == null || selections.length == 0) {
selections = new Selection[1];
int start_offset = textArea.getLineStartOffset(line);
int end_offset = textArea.getLineEndOffset(line);
selections[0] = new Selection.Range(start_offset, end_offset);
textArea.addToSelection(selections[0]);
}

Same as above, use the keyboard (shift + down arrow twice) to select the first 2 lines. The caret will be at the start of the third line, the whitespace before "selections - new Selection[1]" is not selected. Run the move lines down macro. See that the 3rd line moved and the whitespace at the start of the 3rd line is now selected.

Discussion

  • I don't understand, your selection starts from the beginning of the buffer and ends on the third line, so it is logical that the third line is moved too.
    It is a "move lines" macro not a "move selection" macro.
    About the selection that is changed, yes this is a bug.
    In fact when moving lines, the lines are indented at their expected level. It works well if you select entire blocks or statements but if you select the beginning of a block it seems there are some problems.

     
  • Dale Anson
    Dale Anson
    2013-11-14

    No, my selection is for just the first 2 lines. None of the third line is selected, so I don't expect it to move. I agree this is to move lines, not a selection. If I select from the middle of the first line through the middle of the third line, I would expect all 3 lines to move. I would expect that if there is no selection at all, then the line containing the caret would be the one to move.

    I guess this is an edge case, I'm expecting a selection from the start of the first line to the start of the third line to work the same as a selection from the start of the first line to the end of the second line.

     
  • I think it would not be user friendly.
    I tried a few editors:
    Eclipse does as you say, but break the selection after moving the caret. I think it is wrong.
    Notepad++ moves the 3 lines but extend the selection to all moved lines.
    IntelliJ Idea does exactly the same as jEdit.
    I still think that our choice is the best as it keeps the selection unchanged.

     
  • Dale Anson
    Dale Anson
    2014-01-11

    I would argue otherwise. While other editors may do what this macro currently does, previous invocations of this macro worked the way I described (I wrote the previous version of this macro :)). Also, current behavior is inconsistent with other jEdit actions, for example, if I do this:

    1. Open a buffer with several lines of text
    2. Using the keyboard, move the caret to the start of the first line
    3. Using the keyboard, select the first 2 lines (shift + down arrow twice). The caret will now be on the start of the third line.
    4. Hit the Tab button. The 2 selected lines will be indented. The third line will not move.

    By your reasoning, the third line should also move -- it's an indent lines action, not indent selection action.

     
  • Steve
    Steve
    2014-01-13

    If my cursor is on a line with nothing selected, I expect that line to be affected by any *_lines command. If I have selected any text, I expect all the lines with at least one selected character to be affected. But, if I have selected 1 full line and the cursor is in position 0 on the next line, I expect 1 and only 1 line to be affected. That is consistent behavior through most editors, and makes it easy to use. The move line macros and the TextTools Toggle Line Comment all do this wrong and take the line with the cursor as well.

     
    • Steve
      Steve
      2014-01-13

      (I also expect my selection to not be altered for any of the three scenarios I listed above. The build-in Line Comment leaves me with nothing selected, which also is wrong, IMHO.)