Loading ...
Sorry, an error occurred while loading the content.

cursor positioning glitch

Expand Messages
  • Tor Perkins
    Given this text (two lines with four leading spaces on each): xx 1111 1111 1111 2222 ... Inserting a space on line 2 column 1 results in a cursor positioning
    Message 1 of 2 , Sep 1, 2013
    • 0 Attachment
      Given this text (two lines with four leading spaces on each):

      xx 1111 1111 1111
      2222

      And, given these settings (auto format + second line indent):

      :set textwidth=25
      :set formatoptions=a2

      Inserting a space on line 2 column 1 results in a cursor positioning bug, to
      wit, the cursor is unexpectedly moved near the end of line 1.

      This does not happen if comments are present and we 'set fo+=q'.

      The problem is that ops.c:format_lines() has the requisite code needed
      to handle this for the comment case only. In the non-comment case,
      the second_indent variable can be used instead of the next_leader_len
      variable to achieve the same result as seen in this excerpt from the
      attached patch:

      diff -p ./src/ops.c.org ./src/ops.c
      *** ./src/ops.c.org Sun Sep 1 12:29:50 2013
      --- ./src/ops.c Sun Sep 1 13:55:24 2013
      *************** format_lines(line_count, avoid_fex)
      *** 4981,4990 ****
      if (line_count < 0 && u_save_cursor() == FAIL)
      break;
      #ifdef FEAT_COMMENTS
      ! (void)del_bytes((long)next_leader_len, FALSE, FALSE);
      ! if (next_leader_len > 0)
      ! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
      ! (long)-next_leader_len);
      #endif
      curwin->w_cursor.lnum--;
      if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
      --- 4981,5002 ----
      if (line_count < 0 && u_save_cursor() == FAIL)
      break;
      #ifdef FEAT_COMMENTS
      ! if (next_leader_len > 0) {
      ! (void)del_bytes((long)next_leader_len, FALSE, FALSE);
      ! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
      ! (long)-next_leader_len);
      ! } else {
      ! #endif
      ! if (second_indent > 0) { // the "leader" for FO_Q_SECOND
      ! int indent = get_indent_lnum(curwin->w_cursor.lnum);
      !
      ! if (indent > 0) {
      ! (void)del_bytes(indent, FALSE, FALSE);
      ! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, (long)-indent);
      ! }
      ! }
      ! #ifdef FEAT_COMMENTS
      ! }
      #endif
      curwin->w_cursor.lnum--;
      if (do_join(2, TRUE, FALSE, FALSE) == FAIL)

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Bram Moolenaar
      ... Thanks for the patch. I ll look into it. -- hundred-and-one symptoms of being an internet addict: 161. You get up before the sun rises to check your
      Message 2 of 2 , Sep 2, 2013
      • 0 Attachment
        Tor Perkins wrote:

        > Given this text (two lines with four leading spaces on each):
        >
        > xx 1111 1111 1111
        > 2222
        >
        > And, given these settings (auto format + second line indent):
        >
        > :set textwidth=25
        > :set formatoptions=a2
        >
        > Inserting a space on line 2 column 1 results in a cursor positioning bug, to
        > wit, the cursor is unexpectedly moved near the end of line 1.
        >
        > This does not happen if comments are present and we 'set fo+=q'.
        >
        > The problem is that ops.c:format_lines() has the requisite code needed
        > to handle this for the comment case only. In the non-comment case,
        > the second_indent variable can be used instead of the next_leader_len
        > variable to achieve the same result as seen in this excerpt from the
        > attached patch:

        Thanks for the patch. I'll look into it.


        --
        hundred-and-one symptoms of being an internet addict:
        161. You get up before the sun rises to check your e-mail, and you
        find yourself in the very same chair long after the sun has set.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      Your message has been successfully submitted and would be delivered to recipients shortly.