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

72990cursor positioning glitch

Expand Messages
  • Tor Perkins
    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.
    • Show all 2 messages in this topic