changeset 27198:dffdabfd0213

fix cursor position for editor smart indent after keyword (bug #56533) * file-editor-tab.cc (notice_settings): initialize new class variable holding the width of the character used for indentation; (handle_cursor_moved): pass new class variable to smart_indent * file-editor-tab.h: new class variable for indentation character width * octave-qscintilla.cc (smart_indent): length of indentation character is a new parameter which is used for setting the cursor position at the end of the indentation of a new line * octave-qscintilla.cc (smart_indent): new parameter
author Torsten Lilge <ttl-octave@mailbox.org>
date Tue, 25 Jun 2019 22:10:14 +0200
parents b8c0d5ad024f
children f27002104c5b
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, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat Jun 22 17:30:16 2019 -0500
+++ b/libgui/src/m-editor/file-editor-tab.cc	Tue Jun 25 22:10:14 2019 +0200
@@ -2691,6 +2691,10 @@
     _edit_area->setTabWidth
       (settings->value ("editor/tab_width",2).toInt ());
 
+    m_ind_char_width = 1;
+    if (_edit_area->indentationsUseTabs ())
+      m_ind_char_width = _edit_area->tabWidth ();
+
     _edit_area->SendScintilla (QsciScintillaBase::SCI_SETHSCROLLBAR,
                                settings->value ("editor/show_hscroll_bar",true).toBool ());
     _edit_area->SendScintilla (QsciScintillaBase::SCI_SETSCROLLWIDTH,-1);
@@ -3040,7 +3044,8 @@
           {
             // Obviously, we have a newline here
             if (_smart_indent || _auto_endif)
-              _edit_area->smart_indent (_smart_indent, _auto_endif, _line);
+              _edit_area->smart_indent (_smart_indent, _auto_endif,
+                                        _line, m_ind_char_width);
           }
       }
 
--- a/libgui/src/m-editor/file-editor-tab.h	Sat Jun 22 17:30:16 2019 -0500
+++ b/libgui/src/m-editor/file-editor-tab.h	Tue Jun 25 22:10:14 2019 +0200
@@ -304,6 +304,7 @@
     bool _always_reload_changed_files;
     bool _smart_indent;
     int _auto_endif;
+    int m_ind_char_width;
 
     QFileSystemWatcher _file_system_watcher;
 
--- a/libgui/src/m-editor/octave-qscintilla.cc	Sat Jun 22 17:30:16 2019 -0500
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Tue Jun 25 22:10:14 2019 +0200
@@ -499,8 +499,8 @@
   }
 
   // Do smart indendation after if, for, ...
-  void octave_qscintilla::smart_indent (bool do_smart_indent,
-                                        int do_auto_close, int line)
+  void octave_qscintilla::smart_indent (bool do_smart_indent, int do_auto_close,
+                                        int line, int ind_char_width)
   {
     QString prevline = text (line);
 
@@ -534,7 +534,7 @@
           {
             // Do smart indent in the current line (line+1)
             indent (line+1);
-            setCursorPosition (line+1, indentation (line) + indentationWidth ());
+            setCursorPosition (line+1, indentation (line+1) / ind_char_width);
           }
 
         if (do_auto_close
--- a/libgui/src/m-editor/octave-qscintilla.h	Sat Jun 22 17:30:16 2019 -0500
+++ b/libgui/src/m-editor/octave-qscintilla.h	Tue Jun 25 22:10:14 2019 +0200
@@ -63,7 +63,8 @@
     QStringList comment_string (bool comment = true);
     int get_style (int pos = -1);
     int is_style_comment (int pos = -1);
-    void smart_indent (bool do_smart_indent, int do_auto_close, int line);
+    void smart_indent (bool do_smart_indent, int do_auto_close,
+                       int line, int ind_char_width);
 
     void smart_indent_line_or_selected_text (int lineFrom, int lineTo);