[Libreoffice-commits] core.git: scripting/java

Andreas Heinisch (via logerrit) logerrit at kemper.freedesktop.org
Mon May 20 13:45:32 UTC 2019


 scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java |   13 ++++++----
 1 file changed, 8 insertions(+), 5 deletions(-)

New commits:
commit 9ee0a1f16682139c5be28a05d33e980123da4c6f
Author:     Andreas Heinisch <andreas.heinisch at yahoo.de>
AuthorDate: Mon May 20 07:58:03 2019 +0200
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Mon May 20 15:44:41 2019 +0200

    tdf#97635 Added unindentation using shift-tab (mimicked eclipse's behavior)
    
    Moved shift+tab check to the keyPressed function to provide continuous insertion
    and compiled tab-pattern only once
    
    Change-Id: Iffe847fea07295075dc1a280f0697e8c798e8d6f
    Reviewed-on: https://gerrit.libreoffice.org/72580
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
index 581ef48138c8..cc1e22ee21e7 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
@@ -63,6 +63,8 @@ public class PlainSourceView extends JScrollPane implements
     UndoManager undoManager;
     private List<UnsavedChangesListener> unsavedListener = new ArrayList<UnsavedChangesListener>();
 
+    private static final Pattern tabPattern = Pattern.compile("^ *(?<tab>\\t)");
+
     public PlainSourceView(ScriptSourceModel model) {
         this.model = model;
         initUI();
@@ -173,7 +175,7 @@ public class PlainSourceView extends JScrollPane implements
 
         ta.addKeyListener(new KeyAdapter(){
             @Override
-            public void keyReleased(KeyEvent ke){
+            public void keyPressed(KeyEvent ke) {
                 // if shift + tab was pressed, remove the first tab before any code begins
                 if (ke.isShiftDown() && ke.getKeyCode() == KeyEvent.VK_TAB) {
                     try {
@@ -182,17 +184,18 @@ public class PlainSourceView extends JScrollPane implements
                         int startOffset = ta.getLineStartOffset(lineOffset);
                         int endOffset = ta.getLineEndOffset(lineOffset);
 
-                        Pattern pattern = Pattern.compile("^ *(\\t)");
-                        Matcher matcher = pattern.matcher(ta.getText(startOffset, endOffset - startOffset));
-
+                        Matcher matcher = tabPattern.matcher(ta.getText(startOffset, endOffset - startOffset));
                         if (matcher.find()) {
-                            ta.replaceRange(null, startOffset + matcher.start(1), startOffset + matcher.end(1));
+                            ta.replaceRange(null, startOffset + matcher.start("tab"), startOffset + matcher.end("tab"));
                         }
                     } catch (BadLocationException e) {
                         // could not find correct location of the tab
                     }
                 }
+            }
 
+            @Override
+            public void keyReleased(KeyEvent ke){
                 if(ke.getKeyCode() == KeyEvent.VK_SPACE || ke.getKeyCode() == KeyEvent.VK_ENTER){
                     compoundEdit.end();
                     undoManager.addEdit(compoundEdit);


More information about the Libreoffice-commits mailing list