changeset 29716:da9c55b3e9fa

fix wring row/col indicator in GUI editor when auto intending (bug #60690) * file-editor-tab.cc (file_editor_tab): connect new edit area signal for updating row/col indicator; (handle_cursor_moved): improve code for detecting requirement for smart indenting, update row/col indicator before smart indenting but store m_line before; (update_rowcol_indicator): moved updating row/col indicator and storing old line and col into new function * file-editor-tab.h: new function update_rowcol_indicator * octave-qscintilla.cc (setCursorPosition) overwrite base virtual function for adding an update of the row/col indicator via emitting the new signal update_rowcol_indicator_signal * octave-qscintilla.h: overloaded setCursorPosition, new signal update_rowcol_indicator_signal
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 30 May 2021 21:00:22 +0200
parents 82e45c11da7d
children 3e046fba8805
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/octave-qscintilla.cc libgui/src/m-editor/octave-qscintilla.h
diffstat 4 files changed, 29 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun May 30 14:42:36 2021 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun May 30 21:00:22 2021 +0200
@@ -146,6 +146,9 @@
     connect (m_edit_area, &octave_qscintilla::context_menu_edit_signal,
              this, &file_editor_tab::handle_context_menu_edit);
 
+    connect (m_edit_area, &octave_qscintilla::update_rowcol_indicator_signal,
+             this, &file_editor_tab::update_rowcol_indicator);
+
     // create statusbar for row/col indicator and eol mode
     m_status_bar = new QStatusBar (this);
 
@@ -3044,20 +3047,25 @@
         emit autoc_closed (); // Tell editor about closed list
       }
 
-    // Lines changed? Take care of indentation
-    if (m_lines_changed)  // cursor moved and lines have changed
-      {
-        m_lines_changed = false;
-        if (m_is_octave_file && line == m_line+1 && col < m_col)
-          {
-            // Obviously, we have a newline here
-            if (m_smart_indent || m_auto_endif)
-              m_edit_area->smart_indent (m_smart_indent, m_auto_endif,
-                                         m_line, m_ind_char_width);
-          }
-      }
+    // Lines changed? Take care of indentation!
+    bool do_smart_indent = m_lines_changed && m_is_octave_file
+                           && (line == m_line+1) && (col < m_col)
+                           && (m_smart_indent || m_auto_endif);
+    m_lines_changed = false;
 
     // Update line and column indicator in the status bar
+    int o_line = m_line;
+    update_rowcol_indicator (line, col);
+
+    // Do smart indent after update of line indicator for having
+    // consistent indicator data
+    if (do_smart_indent)
+      m_edit_area->smart_indent (m_smart_indent, m_auto_endif,
+                                 o_line, m_ind_char_width);
+  }
+
+  void file_editor_tab::update_rowcol_indicator (int line, int col)
+  {
     m_line = line;
     m_col  = col;
     m_row_indicator->setNum (line+1);
--- a/libgui/src/m-editor/file-editor-tab.h	Sun May 30 14:42:36 2021 +0200
+++ b/libgui/src/m-editor/file-editor-tab.h	Sun May 30 21:00:22 2021 +0200
@@ -204,7 +204,7 @@
     void handle_request_remove_breakpoint (int line);
 
     void update_breakpoints_handler (const octave_value_list& argout);
-
+    void update_rowcol_indicator (int line, int col);
     void update_lexer_settings (bool update_apis_only = false);
 
   private slots:
--- a/libgui/src/m-editor/octave-qscintilla.cc	Sun May 30 14:42:36 2021 +0200
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Sun May 30 21:00:22 2021 +0200
@@ -231,6 +231,12 @@
     emit status_update (isUndoAvailable (), isRedoAvailable ());
   }
 
+  void octave_qscintilla::setCursorPosition (int line, int col)
+  {
+    QsciScintilla::setCursorPosition (line, col);
+    emit update_rowcol_indicator_signal (line, col);
+  }
+
   void octave_qscintilla::set_selection_marker_color (const QColor& c)
   {
     QColor ic = c;
--- a/libgui/src/m-editor/octave-qscintilla.h	Sun May 30 14:42:36 2021 +0200
+++ b/libgui/src/m-editor/octave-qscintilla.h	Sun May 30 21:00:22 2021 +0200
@@ -58,6 +58,7 @@
     };
 
     virtual void contextMenuEvent (QContextMenuEvent *e);
+    virtual void setCursorPosition (int line, int col);
 
     void context_help_doc (bool);
     void context_edit (void);
@@ -86,6 +87,7 @@
 
   signals:
 
+    void update_rowcol_indicator_signal (int line, int col);
     void execute_command_in_terminal_signal (const QString&);
     void create_context_menu_signal (QMenu*);
     void context_menu_edit_signal (const QString&);