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

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/72580Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 1bfbe2a4
......@@ -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;
......@@ -173,7 +175,7 @@ public class PlainSourceView extends JScrollPane implements
ta.addKeyListener(new KeyAdapter(){
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
public void keyReleased(KeyEvent ke){
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