summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2019-05-13 13:08:29 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-05-16 11:32:06 +0200
commite875a317c4adf00bbad00fb8176c26cd1a66973e (patch)
tree00b03c8a321241cf8489f46aaae2a13bc28ec609 /scripting
parent84d8b0b7c442490a00925073950fb07d834eaf97 (diff)
tdf#97635 Added unindentation using shift-tab (mimicked eclipse behavior)
Change-Id: Iaf64451c92f3465751032dde9c283141e548b3ca Reviewed-on: https://gerrit.libreoffice.org/72228 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'scripting')
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java22
1 files changed, 22 insertions, 0 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 f75b1e75fb0e..581ef48138c8 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
@@ -45,6 +45,9 @@ import javax.swing.undo.UndoManager;
import java.util.List;
import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
public class PlainSourceView extends JScrollPane implements
ScriptSourceView, DocumentListener {
@@ -171,6 +174,25 @@ public class PlainSourceView extends JScrollPane implements
ta.addKeyListener(new KeyAdapter(){
@Override
public void keyReleased(KeyEvent ke){
+ // if shift + tab was pressed, remove the first tab before any code begins
+ if (ke.isShiftDown() && ke.getKeyCode() == KeyEvent.VK_TAB) {
+ try {
+ int caretOffset = ta.getCaretPosition();
+ int lineOffset = ta.getLineOfOffset(caretOffset);
+ int startOffset = ta.getLineStartOffset(lineOffset);
+ int endOffset = ta.getLineEndOffset(lineOffset);
+
+ Pattern pattern = Pattern.compile("^ *(\\t)");
+ Matcher matcher = pattern.matcher(ta.getText(startOffset, endOffset - startOffset));
+
+ if (matcher.find()) {
+ ta.replaceRange(null, startOffset + matcher.start(1), startOffset + matcher.end(1));
+ }
+ } catch (BadLocationException e) {
+ // could not find correct location of the tab
+ }
+ }
+
if(ke.getKeyCode() == KeyEvent.VK_SPACE || ke.getKeyCode() == KeyEvent.VK_ENTER){
compoundEdit.end();
undoManager.addEdit(compoundEdit);