Skip to content

Commit

Permalink
Remove insert paired char ' and ` into RSTA. Option to disable other …
Browse files Browse the repository at this point in the history
…paired chars
  • Loading branch information
dzmipt committed Jan 24, 2024
1 parent 2f3fad1 commit 404446b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 71 deletions.
1 change: 1 addition & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* New setting to disable insert of paired character into the editor
* Implement continuous search
* Fixed the bug with sequential replace action in the editor

Expand Down
1 change: 1 addition & 0 deletions src/studio/kdb/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Config extends AbstractConfig {
public static final String RSTA_ANIMATE_BRACKET_MATCHING = configDefault("rstaAnimateBracketMatching", ConfigType.BOOLEAN, true);
public static final String RSTA_HIGHLIGHT_CURRENT_LINE = configDefault("rstaHighlightCurrentLine", ConfigType.BOOLEAN, true);
public static final String RSTA_WORD_WRAP = configDefault("rstaWordWrap", ConfigType.BOOLEAN, false);
public static final String RSTA_INSERT_PAIRED_CHAR = configDefault("rstaInsertPairedChar", ConfigType.BOOLEAN, true);

public static final String DEFAULT_LINE_ENDING = configDefault("defaultLineEnding", ConfigType.ENUM, LineEnding.Unix);

Expand Down
8 changes: 7 additions & 1 deletion src/studio/ui/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SettingsDialog extends EscapeDialog {
private JCheckBox chBoxRTSAAnimateBracketMatching;
private JCheckBox chBoxRTSAHighlightCurrentLine;
private JCheckBox chBoxRTSAWordWrap;
private JCheckBox chBoxRTSAInsertPairedChar;
private JComboBox<CustomiszedLookAndFeelInfo> comboBoxLookAndFeel;
private JFormattedTextField txtTabsCount;
private JFormattedTextField txtMaxCharsInResult;
Expand Down Expand Up @@ -169,6 +170,9 @@ private void initComponents() {
chBoxRTSAWordWrap = new JCheckBox("Word wrap");
chBoxRTSAWordWrap.setSelected(CONFIG.getBoolean(Config.RSTA_WORD_WRAP));

chBoxRTSAInsertPairedChar = new JCheckBox("Insert paired () {} [] \"\" on selection");
chBoxRTSAInsertPairedChar.setSelected(CONFIG.getBoolean(Config.RSTA_INSERT_PAIRED_CHAR));

NumberFormatter formatter = new NumberFormatter();
formatter.setMinimum(1);

Expand Down Expand Up @@ -284,7 +288,8 @@ private void initComponents() {
layout = new GroupLayoutSimple(pnlEditor);
layout.setStacks(
new GroupLayoutSimple.Stack()
.addLineAndGlue(chBoxRTSAAnimateBracketMatching, chBoxRTSAHighlightCurrentLine, chBoxRTSAWordWrap)
.addLineAndGlue(chBoxRTSAAnimateBracketMatching, chBoxRTSAHighlightCurrentLine,
chBoxRTSAWordWrap, chBoxRTSAInsertPairedChar)
.addLineAndGlue(chBoxEmulateTab, txtEmulatedTabSize, chBoxReplaceTabOnOpen)
.addLineAndGlue(lblDefaultLineEnding, comboBoxLineEnding)
.addLineAndGlue(lblExecAll, comboBoxExecAll)
Expand Down Expand Up @@ -359,6 +364,7 @@ public void saveSettings() {
boolean changedEditor = CONFIG.setBoolean(Config.RSTA_ANIMATE_BRACKET_MATCHING, isAnimateBracketMatching());
changedEditor |= CONFIG.setBoolean(Config.RSTA_HIGHLIGHT_CURRENT_LINE, isHighlightCurrentLine());
changedEditor |= CONFIG.setBoolean(Config.RSTA_WORD_WRAP, isWordWrap());
changedEditor |= CONFIG.setBoolean(Config.RSTA_INSERT_PAIRED_CHAR, chBoxRTSAInsertPairedChar.isSelected());
changedEditor |= editorFontSelection.saveSettings();
changedEditor |= CONFIG.setBoolean(Config.EDITOR_TAB_EMULATED, chBoxEmulateTab.isSelected());
changedEditor |= CONFIG.setInt(Config.EDITOR_TAB_SIZE, (Integer)txtEmulatedTabSize.getValue());
Expand Down
2 changes: 2 additions & 0 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ public static void refreshEditorsSettings() {

editor.setTabSize(CONFIG.getInt(Config.EDITOR_TAB_SIZE));
editor.setTabsEmulated(CONFIG.getBoolean(Config.EDITOR_TAB_EMULATED));

editor.setInsertPairedCharacters(CONFIG.getBoolean(Config.RSTA_INSERT_PAIRED_CHAR));
return true;
});
}
Expand Down
43 changes: 42 additions & 1 deletion src/studio/ui/rstextarea/RSTextAreaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.stream.Collectors;

import static org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit.*;

public class RSTextAreaFactory {

Expand All @@ -29,9 +34,36 @@ public class RSTextAreaFactory {

private static final ActionMap actionMap;


static {
java.util.List<Action> actions = new ArrayList<>();
actions.addAll(Arrays.asList(new RSyntaxTextAreaEditorKit().getActions()));

List<String> wrongInsPairCharActionName = new ArrayList<>();
for (ListIterator<Action> iterator = actions.listIterator(); iterator.hasNext(); ) {
Action action = iterator.next();
if (action instanceof InsertPairedCharacterAction) {
wrongInsPairCharActionName.add(((InsertPairedCharacterAction) action).getName());
iterator.remove();
}
}

List<InsertPairedCharacterAction> insertPairedActions = Arrays.asList(
new InsertPairedCharacterAction(rstaOpenParenAction, '(', ')'),
new InsertPairedCharacterAction(rstaOpenSquareBracketAction, '[', ']'),
new InsertPairedCharacterAction(rstaOpenCurlyAction, '{', '}'),
new InsertQuoteAction(rstaDoubleQuoteAction, InsertQuoteAction.QuoteType.DOUBLE_QUOTE)
// We should not wrap ` and '
// new InsertQuoteAction(rstaSingleQuoteAction, RSyntaxTextAreaEditorKit.InsertQuoteAction.QuoteType.SINGLE_QUOTE),
// new InsertQuoteAction(rstaBacktickAction, RSyntaxTextAreaEditorKit.InsertQuoteAction.QuoteType.BACKTICK)
);

wrongInsPairCharActionName.removeAll(
insertPairedActions.stream().map(RecordableTextAction::getName).collect(Collectors.toList())
);

actions.addAll(insertPairedActions);

actions.add(new CopyCutAsStyledTextAction(false));
actions.add(new CopyCutAsStyledTextAction(true));

Expand Down Expand Up @@ -73,6 +105,14 @@ public class RSTextAreaFactory {
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, defaultModifier), FindReplaceAction.replaceAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), HideSearchPanelAction.action);


for (KeyStroke ks: inputMap.allKeys() ) {
Object action = inputMap.get(ks);
if (wrongInsPairCharActionName.contains(action)) {
inputMap.remove(ks);
}
}

UIManager.put("RSyntaxTextAreaUI.inputMap", inputMap);

FoldParserManager.get().addFoldParserMapping(RSTokenMaker.CONTENT_TYPE, new CurlyFoldParser());
Expand Down Expand Up @@ -106,6 +146,7 @@ public static StudioRSyntaxTextArea newTextArea(boolean editable) {
textArea.setTabsEmulated(Config.getInstance().getBoolean(Config.EDITOR_TAB_EMULATED));
textArea.setTabSize(Config.getInstance().getInt(Config.EDITOR_TAB_SIZE));

textArea.setInsertPairedCharacters(Config.getInstance().getBoolean(Config.RSTA_INSERT_PAIRED_CHAR));
return textArea;
}

Expand Down Expand Up @@ -158,7 +199,7 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
try {
textArea.getDocument().remove(selStart, selEnd - selStart);
} catch (BadLocationException ex) {
System.err.println("Ups... That's not expected: " + ex);
System.err.println("Oops... That's not expected: " + ex);
ex.printStackTrace();
}
}
Expand Down
58 changes: 58 additions & 0 deletions test-integration/studio/ui/RSTAEditorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package studio.ui;

import org.assertj.swing.fixture.JTextComponentFixture;
import org.junit.Test;

public class RSTAEditorTest extends StudioTest {

@Test
public void testPairedChars() {
JTextComponentFixture editor = frameFixture.textBox("editor1");
editor.enterText("`'()[]{}\"");
editor.requireText("`'()[]{}\"");
}

@Test
public void testNotWrappedSpecChars() {
JTextComponentFixture editor = frameFixture.textBox("editor1");
editor.enterText("select");
editor.selectAll();
editor.enterText("`");
editor.requireText("`");

editor.deleteText();
editor.enterText("select");
editor.selectAll();
editor.enterText("'");
editor.requireText("'");
}


@Test
public void testWrappedChars() {
JTextComponentFixture editor = frameFixture.textBox("editor1");
editor.enterText("select");
editor.selectAll();
editor.enterText("(");
editor.requireText("(select)");

editor.deleteText();
editor.enterText("select");
editor.selectAll();
editor.enterText("[");
editor.requireText("[select]");

editor.deleteText();
editor.enterText("select");
editor.selectAll();
editor.enterText("{");
editor.requireText("{select}");

editor.deleteText();
editor.enterText("select");
editor.selectAll();
editor.enterText("\"");
editor.requireText("\"select\"");
}

}
37 changes: 0 additions & 37 deletions test-integration/studio/ui/RSTextAreaFrameForTest.java

This file was deleted.

32 changes: 0 additions & 32 deletions test-integration/studio/ui/RSTextAreaTest.java

This file was deleted.

0 comments on commit 404446b

Please sign in to comment.