Changeset 1130


Ignore:
Timestamp:
Jun 30, 2011, 6:38:42 PM (6 years ago)
Author:
stefan
Message:

added auto_close_environment

Location:
trunk/src/jlatexeditor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/codehelper/LatexLineBreakListener.java

    r1129 r1130  
    66import sce.codehelper.LineBreakListener;
    77import sce.codehelper.WordWithPos;
    8 import sce.component.SCEDocument;
    9 import sce.component.SCEPane;
     8import sce.component.*;
    109
    1110import javax.naming.OperationNotSupportedException;
     11import javax.swing.text.Caret;
    1212import java.util.Iterator;
    1313import java.util.regex.Pattern;
     
    2323  public void linedWrapped(SCEPane pane) {
    2424    SCEDocument doc = pane.getDocument();
    25     int row = pane.getCaret().getRow();
     25    SCECaret caret = pane.getCaret();
     26    int row = caret.getRow();
    2627
    2728    if (row > 0) {
    2829      String lastLine = doc.getRow(row - 1);
    2930      boolean indent = false;
     31      boolean closeEnv = false;
     32      String envName = null;
    3033
    31       // check if we need to indent the new line
    32       if (GProperties.getBoolean("editor.auto_indentation.after_begin")) {
    33         // indent if a new environment was opened in the last row
    34         Iterator<WordWithPos> openEnvIterator = EnvironmentUtils.getOpenEnvIterator(pane);
    35         if (openEnvIterator.hasNext()) {
    36           indent = openEnvIterator.next().getStartRow() == row - 1;
     34      // determine if a new environment was opened in the last row
     35      Iterator<WordWithPos> openEnvIterator = EnvironmentUtils.getOpenEnvIterator(pane);
     36      if (openEnvIterator.hasNext()) {
     37        WordWithPos env = openEnvIterator.next();
     38        if (env.getStartRow() == row - 1) {
     39          indent   = GProperties.getBoolean("editor.auto_indentation.after_begin");
     40          closeEnv = GProperties.getBoolean("editor.auto_close_environment");
     41          envName  = env.word;
    3742        }
    3843      }
     44      // check further if we need to indent the new line
    3945      if (!indent && GProperties.getBoolean("editor.auto_indentation.after_item")) {
    4046        // indent if a new item was started in the last row
     
    5864        pane.insert("  ");
    5965      }
     66      if (closeEnv) {
     67        SCEPosition oldPos = new SCEDocumentPosition(caret.getRow(), caret.getColumn());
     68        String currLine = doc.getRow(row);
     69        String nextIndentation = currLine.substring(0, Math.max(0, currLine.length() - 2));
     70        pane.insert("\n" + nextIndentation + "\\end{" + envName + '}');
     71        caret.moveTo(oldPos, false);
     72      }
    6073    }
    6174  }
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r1129 r1130  
    120120    properties.addEntry(new Def("editor.auto_completion.min_number_of_letters", INT_GT_0, "3"));
    121121    properties.addEntry(new Def("editor.auto_completion.delay", INT_GT_0, "200"));
    122     properties.addEntry(new Def("editor.clear_selection_when_closing_search", BOOLEAN, "true"));
     122    properties.addEntry(new Def("editor.auto_completion.delay", INT_GT_0, "200"));
     123    properties.addEntry(new Def("editor.auto_close_environment", BOOLEAN, "true"));
    123124    properties.addEntry(new Comment(" Automatic indentation"));
    124125    properties.addEntry(new Def("editor.auto_indentation.after_begin", BOOLEAN, "true"));
    125126    properties.addEntry(new Def("editor.auto_indentation.after_item", BOOLEAN, "true"));
    126127    properties.addEntry(new Def("editor.auto_indentation.after_opening_brace", BOOLEAN, "true"));
     128    properties.addEntry(new Comment(" Clear selection"));
     129    properties.addEntry(new Def("editor.clear_selection_when_closing_search", BOOLEAN, "true"));
    127130
    128131    properties.addEntry(new Comment("\n## Shortcuts"));
Note: See TracChangeset for help on using the changeset viewer.