forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Yaml Editor does not respect indent size on new line
- Loading branch information
Showing
5 changed files
with
29 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
ide/languages.yaml/src/org/netbeans/modules/languages/yaml/IndentUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,30 +19,29 @@ | |
package org.netbeans.modules.languages.yaml; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.swing.Action; | ||
import javax.swing.text.BadLocationException; | ||
import javax.swing.text.Caret; | ||
import javax.swing.text.Document; | ||
import javax.swing.text.JTextComponent; | ||
import org.netbeans.api.editor.document.LineDocumentUtils; | ||
import org.netbeans.api.editor.settings.SimpleValueNames; | ||
import org.netbeans.editor.BaseAction; | ||
import org.netbeans.editor.BaseDocument; | ||
import org.netbeans.editor.BaseKit; | ||
import org.netbeans.editor.Utilities; | ||
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; | ||
|
||
/** | ||
* | ||
* @author Ondrej Brejla <[email protected]> | ||
*/ | ||
public class InsertTabAction extends BaseAction { | ||
|
||
private static final List<Action> CUSTOM_ACTIONS = new LinkedList<Action>(); | ||
|
||
static { | ||
CUSTOM_ACTIONS.add(new InsertTabAction()); | ||
} | ||
private static final List<Action> CUSTOM_ACTIONS = List.of(new InsertTabAction()); | ||
|
||
public InsertTabAction() { | ||
super(BaseKit.insertTabAction); | ||
|
@@ -91,11 +90,11 @@ private void tryReplaceTab() throws BadLocationException { | |
} | ||
|
||
private void replaceTab() throws BadLocationException { | ||
final int rowStart = Utilities.getRowStart(baseDocument, caretOffset); | ||
final int rowStart = LineDocumentUtils.getLineStart(baseDocument, caretOffset); | ||
assert caretOffset >= rowStart : "Caret: " + caretOffset + " rowStart: " + rowStart; | ||
final String indentString = baseDocument.getText(rowStart, caretOffset - rowStart); | ||
if (indentString.contains(TAB_CHARACTER)) { | ||
final String newIndentString = indentString.replace(TAB_CHARACTER, IndentUtils.getIndentString(IndentUtils.getIndentSize(baseDocument))); | ||
final String newIndentString = indentString.replace(TAB_CHARACTER, " ".repeat(getSpacesPerTab(baseDocument))); | ||
baseDocument.replace(rowStart, caretOffset - rowStart, newIndentString, null); | ||
} | ||
} | ||
|
@@ -106,6 +105,11 @@ private static boolean shouldBeReplaced(final int firstNonWhiteCharOffset, final | |
|
||
} | ||
|
||
private static int getSpacesPerTab(Document doc) { | ||
return CodeStylePreferences.get(doc).getPreferences() | ||
.getInt(SimpleValueNames.SPACES_PER_TAB, 2); | ||
} | ||
|
||
public static List<Action> createCustomActions() { | ||
return CUSTOM_ACTIONS; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters