Kaydet (Commit) e875a317 authored tarafından Andreas Heinisch's avatar Andreas Heinisch Kaydeden (comit) Samuel Mehrbrodt

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: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 84d8b0b7
......@@ -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(){
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){
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment