diff libgui/src/m-editor/file-editor-tab.cc @ 23237:904c8a356e76

provide the possibility for breaking lines only in comments (bug #41555) * file-editor-tab.cc (notice_settings): get preference on breaking lines in comments only; (handle_char_added): check current style for comment and break lines if desired, add comment string at the new line if comment is a line comment * file-editor-tab.h: new class variable for line breaking in comments only * settings-dialog.cc (settings_dialog): initialize new checkbox from settings; (write_changed_settings): store state of the checkbox into settings file * settings-dialog.ui: new checkbox for line breaking in comments only
author Torsten <mttl@mailbox.org>
date Sun, 26 Feb 2017 13:46:52 +0100
parents 4cd5f975d26c
children 6c691829a24d
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat Feb 25 21:13:35 2017 +0100
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun Feb 26 13:46:52 2017 +0100
@@ -2376,9 +2376,12 @@
   else
     _line_break = 0;
 
+  _line_break_comments =
+        settings->value ("editor/break_lines_comments",false).toBool ();
+
   // highlight all occurrences of a word selected by a double click
-  _highlight_all_occurrences = settings->value (
-                    "editor/highlight_all_occurrences", true).toBool ();
+  _highlight_all_occurrences =
+        settings->value ("editor/highlight_all_occurrences", true).toBool ();
 
   // reload changed files
   _always_reload_changed_files =
@@ -2685,6 +2688,17 @@
     if (col <= _line_break)
       return;
 
+    // If line breaking is only desired in comments,
+    // return if not in a comment
+    int style_comment = octave_qscintilla::ST_NONE;
+    if (_line_break_comments)
+      {
+        // line breaking only in comments, check for comment style
+        style_comment = _edit_area->is_style_comment ();
+        if (! style_comment)
+          return;       // no comment, return
+      }
+
     // Here we go for breaking the current line by inserting a newline.
     // For determining the position of a specific column, we have to get
     // the column from the QScintila function without taking tab lengths
@@ -2712,8 +2726,8 @@
     // Insert a newline char for breaking the line possibly followed
     // by a line comment string
     QString newline = QString ("\n");
-    int style = _edit_area->is_style_comment ();
-    if (style == octave_qscintilla::ST_LINE_COMMENT)
+    style_comment = _edit_area->is_style_comment ();
+    if (style_comment == octave_qscintilla::ST_LINE_COMMENT)
       newline = newline + _edit_area->comment_string ();
     _edit_area->insertAt (newline, line, col_newline);