diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2019-05-20 07:58:03 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-05-20 15:44:41 +0200 |
commit | 9ee0a1f16682139c5be28a05d33e980123da4c6f (patch) | |
tree | b6013a19ccd98b6c8fe76d1888c7ad98dbeb619e /scripting | |
parent | 1bfbe2a44021ca4ae6716caa39fc8a375914be5c (diff) |
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@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java | 13 |
1 files changed, 8 insertions, 5 deletions
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); |