Skip to content

Commit

Permalink
Merge branch 'release/customize-gutter'
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilViolet committed Sep 9, 2021
2 parents f9f13a1 + 448e9dd commit 6ed104a
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 28 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

- More language support.

## [1.2.0 - 2021.09.09]

### Added

+ Feature:customize the color and size of gutter brackets.

## [1.1.0 - 2021.09.03]

### Added ###
### Added

+ Feature:render bracket in gutter.

### Fixed ###
### Fixed

+ Fix that the listener renders multiple times

Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
<!-- Plugin description -->

The plugin can color highlight the Bracket Pair in editor for IntelliJ.<br/>
FROM <a href="https://github.com/qeesung/HighlightBracketPair">qeesung#HighlightBracketPair</a>.Fix bugs and continue to develop new features.<br/>

New feature: can render the bracket color in gutter.<br/>

highlight-bracket-pair maybe support Languages: Java, Groovy, Kotlin, Scala, Haskell, Python, JavaScript, TypeScript, Golang, Ruby, Erlang, Rust, Html, XML, Json, CSS....Of course, the support for certain languages is not perfect.<br/>

If you have any questions, you can go to <a href="https://github.com/AprilViolet/highlight-bracket-pair">Github</a> to raise an issue.Thanks.
FROM <a href="https://github.com/qeesung/HighlightBracketPair">qeesung#HighlightBracketPair</a>.Fix bugs and continue to develop new features.<br/>

If you have any questions or get more information, you can go to <a href="https://github.com/AprilViolet/highlight-bracket-pair">Github</a>.Thanks.

<!-- Plugin description end -->

## Screenshots ##

Expand All @@ -31,10 +36,12 @@ If you have any questions, you can go to <a href="https://github.com/AprilViolet

![HighlightBracketPair-004](./images/HighlightBracketPair-004.png)

<!-- Plugin description end -->

## Installation

<a href="https://plugins.jetbrains.com/embeddable/install/17320">
<img src="https://user-images.githubusercontent.com/12044174/123105697-94066100-d46a-11eb-9832-338cdf4e0612.png" width="300"/>
</a>

- Using IDE built-in plugin system:

<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Marketplace</kbd> > <kbd>Search for "highlight-bracket-pair"</kbd> >
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginGroup = cn.aprilviolet.highlightbracketpair
pluginName = HighlightBracketPair
pluginVersion = 1.1.0
pluginVersion = 1.2.0

pluginSinceBuild = 211
pluginUntilBuild = 212.*
Expand Down
Binary file modified images/HighlightBracketPair-003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/HighlightBracketPair-004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.intellij.openapi.editor.event.CaretListener;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.awt.event.KeyAdapter;
Expand Down Expand Up @@ -80,8 +81,13 @@ public void highlightEditorCurrentPair(Editor editor) {
if (highlightBracketPairSettings.getBracketGutterEnable()) {
// clear braces in gutter
highlighter.eraseHighlight(gutterHighlighterList);
String gutterBracketSize = highlightBracketPairSettings.getGutterBracketSize();
if (StringUtils.isEmpty(gutterBracketSize) || !StringUtils.isNumeric(gutterBracketSize)) {
gutterBracketSize = "14";
}
// show braces in gutter
Pair<RangeHighlighter, RangeHighlighter> highlighterInGutter = highlighter.renderBracesInGutter(bracePair);
Pair<RangeHighlighter, RangeHighlighter> highlighterInGutter = highlighter.renderBracesInGutter(bracePair,
Integer.parseInt(gutterBracketSize));
if (ObjectUtils.isNotEmpty(highlighterInGutter)) {
gutterHighlighterList.add(highlighterInGutter.getLeft());
gutterHighlighterList.add(highlighterInGutter.getRight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Pair<RangeHighlighter, RangeHighlighter> highlightPair(BracePair bracePai
* @param bracePair BracePair
* @return List<RangeHighlighter>
*/
public Pair<RangeHighlighter, RangeHighlighter> renderBracesInGutter(BracePair bracePair) {
public Pair<RangeHighlighter, RangeHighlighter> renderBracesInGutter(BracePair bracePair, Integer gutterBracketSize) {
final Brace leftBrace = bracePair.getLeftBrace();
final Brace rightBrace = bracePair.getRightBrace();
final int leftBraceOffset = leftBrace.getOffset();
Expand All @@ -166,9 +166,11 @@ public Pair<RangeHighlighter, RangeHighlighter> renderBracesInGutter(BracePair b
final TextAttributes textAttributes = editor.getColorsScheme().getAttributes(textAttributesKey);

int openBraceLine = document.getLineNumber(leftBraceOffset);
RangeHighlighter openBraceHighlighter = renderBraceInGutter(openBraceLine, leftBraceText, textAttributes);
RangeHighlighter openBraceHighlighter = renderBraceInGutter(openBraceLine, leftBraceText,
textAttributes, gutterBracketSize);
int closeBraceLine = document.getLineNumber(rightBraceOffset);
RangeHighlighter closeBraceHighlighter = renderBraceInGutter(closeBraceLine, rightBraceText, textAttributes);
RangeHighlighter closeBraceHighlighter = renderBraceInGutter(closeBraceLine, rightBraceText,
textAttributes, gutterBracketSize);

return new Pair<>(openBraceHighlighter, closeBraceHighlighter);
}
Expand All @@ -181,7 +183,8 @@ public Pair<RangeHighlighter, RangeHighlighter> renderBracesInGutter(BracePair b
* @param textAttributes text
* @return RangeHighlighter
*/
public RangeHighlighter renderBraceInGutter(int braceLine, String braceText, TextAttributes textAttributes) {
public RangeHighlighter renderBraceInGutter(int braceLine, String braceText,
TextAttributes textAttributes, Integer gutterBracketSize) {
RangeHighlighter braceHighlighter = editor.getMarkupModel()
.addLineHighlighter(braceLine, HighlighterLayer.SELECTION, null);

Expand All @@ -197,6 +200,7 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
}

g.setColor(textAttributes.getForegroundColor());
g.setFont(new Font("JetBrains Mono", Font.BOLD, gutterBracketSize));
g.drawChars(braceText.toCharArray(), 0, braceText.length(), 0, 0);
}

Expand Down Expand Up @@ -234,6 +238,7 @@ public int hashCode() {
* @param offset offset
* @return BracePair
*/
@SuppressWarnings("RedundantCast")
private BracePair findCloseBracePairInBraceTokens(int offset) {
EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
boolean isBlockCaret = this.isBlockCaret();
Expand Down Expand Up @@ -261,6 +266,7 @@ private BracePair findCloseBracePairInBraceTokens(int offset) {
* @param offset offset
* @return BracePair
*/
@SuppressWarnings("RedundantCast")
private BracePair findCloseBracePairInStringSymbols(int offset) {
if (offset < 0 || this.fileText == null || this.fileText.length() == 0) {
return EMPTY_BRACE_PAIR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.util.NlsContexts;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
Expand Down Expand Up @@ -56,9 +57,10 @@ public class BracketSettingsConfigurable implements Configurable {
*/
@Override
public boolean isModified() {
boolean isModified = highlightBracketPairSettingComponent.getBracketGutterEnable()
.equals(highlightBracketPairSettings.getBracketGutterEnable());
return !isModified;
return !highlightBracketPairSettingComponent.getBracketGutterEnable()
.equals(highlightBracketPairSettings.getBracketGutterEnable()) ||
!highlightBracketPairSettingComponent.getBracketGutterSizeText()
.equals(highlightBracketPairSettings.getGutterBracketSize());
}

/**
Expand All @@ -70,6 +72,9 @@ public boolean isModified() {
@Override
public void apply() throws ConfigurationException {
highlightBracketPairSettings.setBracketGutterEnable(highlightBracketPairSettingComponent.getBracketGutterEnable());
if (StringUtils.isNumeric(highlightBracketPairSettingComponent.getBracketGutterSizeText())) {
highlightBracketPairSettings.setGutterBracketSize(highlightBracketPairSettingComponent.getBracketGutterSizeText());
}
}

/**
Expand All @@ -79,5 +84,6 @@ public void apply() throws ConfigurationException {
@Override
public void reset() {
highlightBracketPairSettingComponent.setBracketGutterEnable(highlightBracketPairSettings.getBracketGutterEnable());
highlightBracketPairSettingComponent.setBracketGutterSizeText(highlightBracketPairSettings.getGutterBracketSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ public class HighlightBracketPairPluginState {
/**
* Plug-in version
*/
private String pluginVersion = "";
private String pluginVersion = "0.0.0";

/**
* turn on rendering brackets in gutter
* true:open false:close
*/
private Boolean bracketGutterEnable = Boolean.FALSE;
private Boolean bracketGutterEnable = Boolean.TRUE;

/**
* customize bracket in gutter size
*/
private String gutterBracketSize = "14";

public String getPluginVersion() {
return pluginVersion;
Expand All @@ -35,4 +40,12 @@ public Boolean getBracketGutterEnable() {
public void setBracketGutterEnable(Boolean bracketGutterEnable) {
this.bracketGutterEnable = bracketGutterEnable;
}

public String getGutterBracketSize() {
return gutterBracketSize;
}

public void setGutterBracketSize(String gutterBracketSize) {
this.gutterBracketSize = gutterBracketSize;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package cn.aprilviolet.highlightbracketpair.setting;

import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.JBUI;

import javax.swing.*;
import java.awt.*;

/**
* HighlightBracketPair setting component
Expand All @@ -14,13 +20,41 @@
* @since v1.0.0
*/
public class HighlightBracketPairSettingComponent {
/**
* setting main panel
*/
private final JPanel bracketMainPanel;

/**
* Open render bracket in gutter
*/
private final JBCheckBox bracketGutterEnable = new JBCheckBox("Open render bracket in gutter");

/**
* Set bracket size for gutter"
*/
private final JBTextField bracketGutterSizeText = new JBTextField();

public HighlightBracketPairSettingComponent() {
bracketMainPanel = FormBuilder.createFormBuilder()
.addComponent(bracketGutterEnable, 1).addComponentFillVertically(new JPanel(), 0)
bracketMainPanel = new JBPanel();
bracketMainPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.NORTH;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.insets = JBUI.insets(10, 10, 10, 10);
constraints.gridx = 0;

JBLabel bracketGutterLabel = new JBLabel("Bracket size in gutter");
JPanel bracketGutterPanel = FormBuilder.createFormBuilder()
.addComponent(bracketGutterEnable, 1)
.addLabeledComponent(bracketGutterLabel, bracketGutterSizeText, 1, false)
.getPanel();
bracketGutterPanel.setBorder(IdeBorderFactory.createTitledBorder("Bracket In Gutter"));

constraints.gridy = 0;
bracketMainPanel.add(bracketGutterPanel, constraints);
}

public JPanel getBracketMainPanel() {
Expand All @@ -34,4 +68,12 @@ public Boolean getBracketGutterEnable() {
public void setBracketGutterEnable(boolean newStatus) {
bracketGutterEnable.setSelected(newStatus);
}

public String getBracketGutterSizeText() {
return bracketGutterSizeText.getText();
}

public void setBracketGutterSizeText(String bracketGutterSize) {
bracketGutterSizeText.setText(bracketGutterSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ public Boolean getBracketGutterEnable() {
public void setBracketGutterEnable(Boolean bracketGutterEnable) {
highlightBracketPairPluginState.setBracketGutterEnable(bracketGutterEnable);
}

public String getGutterBracketSize() {
return highlightBracketPairPluginState.getGutterBracketSize();
}

public void setGutterBracketSize(String bracketGutterEnable) {
highlightBracketPairPluginState.setGutterBracketSize(bracketGutterEnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ public class HighlightBracketPairSettingsPage implements ColorSettingsPage {

public static final TextAttributesKey CUSP_BRACKETS_ATTR = TextAttributesKey.createTextAttributesKey("CUSP_BRACKETS_ATTR");

public static final TextAttributesKey BRACE_ATTR_GUTTER = TextAttributesKey.createTextAttributesKey("BRACE_ATTR_GUTTER");

private static final AttributesDescriptor[] ATTRIBUTES_DESCRIPTION = {
new AttributesDescriptor("Brace", BRACE_ATTR),
new AttributesDescriptor("Bracket", BRACKET_ATTR),
new AttributesDescriptor("Parenthesis", PARENTHESIS_ATTR),
new AttributesDescriptor("DoubleQuote", DOUBLE_QUOTE_ATTR),
new AttributesDescriptor("CuspBracket", CUSP_BRACKETS_ATTR),
new AttributesDescriptor("BraceInGutter", BRACE_ATTR_GUTTER)
};

private static final Map<IElementType, TextAttributesKey> ELEMENT_TYPE_ATTRIBUTE = new HashMap<>();
Expand All @@ -61,12 +64,14 @@ public class HighlightBracketPairSettingsPage implements ColorSettingsPage {
CONTENT_ATTRIBUTE.put("[", BRACKET_ATTR);
CONTENT_ATTRIBUTE.put("(", PARENTHESIS_ATTR);
CONTENT_ATTRIBUTE.put("<", CUSP_BRACKETS_ATTR);
CONTENT_ATTRIBUTE.put("|", BRACE_ATTR_GUTTER);
// TAGS
TAGS.put("Brace", BRACE_ATTR);
TAGS.put("Bracket", BRACKET_ATTR);
TAGS.put("Parenthesis", PARENTHESIS_ATTR);
TAGS.put("DoubleQuote", DOUBLE_QUOTE_ATTR);
TAGS.put("CuspBracket", CUSP_BRACKETS_ATTR);
TAGS.put("BraceInGutter", BRACE_ATTR_GUTTER);
}

public static TextAttributesKey getTextAttributesKeyByToken(IElementType type) {
Expand All @@ -93,10 +98,11 @@ public SyntaxHighlighter getHighlighter() {
@Override
public String getDemoText() {
return "<Brace>{</Brace>...<Brace>}</Brace>" +
" <Parenthesis>(</Parenthesis>...<Parenthesis>)</Parenthesis>" +
" <Bracket>[</Bracket>...<Bracket>]</Bracket>" +
" <CuspBracket><</CuspBracket>...<CuspBracket>></CuspBracket>" +
" <DoubleQuote>\"</DoubleQuote>...<DoubleQuote>\"</DoubleQuote>";
"\n<Parenthesis>(</Parenthesis>...<Parenthesis>)</Parenthesis>" +
"\n<Bracket>[</Bracket>...<Bracket>]</Bracket>" +
"\n<CuspBracket><</CuspBracket>...<CuspBracket>></CuspBracket>" +
"\n<DoubleQuote>\"</DoubleQuote>...<DoubleQuote>\"</DoubleQuote>" +
"\n<BraceInGutter>|</BraceInGutter>...<BraceInGutter>|</BraceInGutter>";
}

@Nullable
Expand Down
17 changes: 12 additions & 5 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
<vendor email="[email protected]" url="https://github.com/AprilViolet">AprilViolet</vendor>

<description><![CDATA[
Color highlight the Bracket Pair in editor.
Fixed some compatibility issues. FROM <a href="https://github.com/qeesung/HighlightBracketPair">HighlightBracketPair</a><br/>
Supported Languages: Java, Groovy, Kotlin, Scala, Haskell, Python, JavaScript, TypeScript, Golang, Ruby, Erlang, Rust, Html, Xml, Json, CSS...<br/>.Of course, the support for certain languages is not perfect.
If you have questions,click <a href="https://github.com/AprilViolet/highlight-bracket-pair">github</a> for more information.
The plugin can color highlight the Bracket Pair in editor for IntelliJ.<br/>
New feature: can render the bracket color in gutter.<br/>
highlight-bracket-pair maybe support Languages: Java, Groovy, Kotlin, Scala, Haskell, Python, JavaScript, TypeScript, Golang, Ruby, Erlang, Rust, Html, XML, Json, CSS....Of course, the support for certain languages is not perfect.<br/>
FROM <a href="https://github.com/qeesung/HighlightBracketPair">qeesung#HighlightBracketPair</a>.Fix bugs and continue to develop new features.<br/>
If you have any questions or get more information, you can go to <a href="https://github.com/AprilViolet/highlight-bracket-pair">Github</a>.Thanks.
]]></description>

<change-notes><![CDATA[
<p>1.2.0</p>
<ul>
<li>
Feature:customize the color and size of gutter brackets.<br/>
</li>
</ul>
<p>1.1.0</p>
<ul>
<li>
Feature:render bracket in gutter.
Feature:render bracket in gutter.<br/>
Fixed:Fix that the listener renders multiple times
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@
<option name="FONT_TYPE" value="1"/>
</value>
</option>
<option name="BRACE_ATTR_GUTTER">
<value>
<option name="FOREGROUND" value="3A3AFC"/>
<option name="BACKGROUND" value="3A3AFC"/>
<option name="FONT_TYPE" value="1"/>
</value>
</option>
</list>

0 comments on commit 6ed104a

Please sign in to comment.