Author Topic: Movelines picks up extra line  (Read 961 times)

byates

  • Senior Community Member
  • Posts: 105
  • Hero Points: 8
Movelines picks up extra line
« on: August 03, 2016, 04:35:37 pm »
The functions `move-lines-up()` and `move-lines-down()` will pick up one extra line when the cursor is on the first column and <SHIFT><UP> or <SHIFT><DOWN> is used to make the selection.

For example, check out the screenshot `MoveLinesExample1.png`.  It shows a selection made with the cursor on column 1 of line 30 and <SHIFT><DOWN> hit twice to select two lines.  If `move-lines-up()` is called it will move three lines.  See `MoveLinesExample2.png`.  The simple patch below fixes this so that only two lines are moved up.  See `MoveLinesExample3.png.

The workaround is to only <SHIFT><DOWN> once however I find it counter intuitive that to select two lines you only <SHIFT><DOWN> once.  Plus the selection highlighting only shows one line selected.  The patch fixes this.

Code: [Select]
[PATCH] moveline: check for the special case where the end of a char selection
is at the beginning of a line. If this is the case, adjust the selection to
NOT include that last line.

diff -r b6958abe9098 -r a502d06bc3d5 SlickEditMacros_WorkingCopy/moveline.e
--- a/SlickEditMacros_WorkingCopy/moveline.e Wed Aug 03 12:16:32 2016 -0400
+++ b/SlickEditMacros_WorkingCopy/moveline.e Wed Aug 03 12:17:43 2016 -0400
@@ -31,6 +31,37 @@
       _deselect();
       _select_line();
       had_selection=false;
+   } else {
+      // JBY
+      // Check for the special case where the end of a char selection is
+      // at the beginning of a line. If this is the case, adjust the selection
+      // to NOT include that last line.
+      if (_select_type() == "CHAR") {
+            int OrgLine = p_line;
+            _begin_select();
+            int FirstLine=p_line;
+            _end_select();
+            int LastLine=p_line;
+            if ((p_col == 1) && (FirstLine != LastLine)) {
+               // Last position is at the beginning of a line so we will not use
+               // this line. When a char selection is setup it is easy to accidentally
+               // include one extra line.
+               LastLine--;
+            }
+            _deselect();
+            int markid = _alloc_selection();
+            if (markid < 0) {
+               return;
+            }
+            _show_selection(markid);
+            p_line = FirstLine;
+            _select_line(markid);
+            p_line = LastLine;
+            _select_line(markid);
+            _select_type(markid, 'S', 'E');
+            p_line = OrgLine;
+      }
+      // END_JBY
    }
    int Noflines;
    if (dir>=0) {

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5149
  • Hero Points: 425
Re: Movelines picks up extra line
« Reply #1 on: August 03, 2016, 07:45:02 pm »
We will look into this