Skip to content

Commit

Permalink
Fix some issues related to unexpected color values and rework popup
Browse files Browse the repository at this point in the history
More compact popup design.

Add configuration option for color borders.

Bigger color previews.
  • Loading branch information
facelessuser committed Mar 13, 2021
1 parent 55785df commit 9534733
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 160 deletions.
9 changes: 7 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

## 2.15.0

- **NEW**: Require new `coloraide` dependency.
- **NEW**: Format dialog a little more compact.
- **NEW**: Require new `coloraide` dependency. With this dependency, schemes that use `min-contrast` should work now.
- **NEW**: ScopeHunter now only shows information in tooltip. Showing info in separate panel and console has been
dropped as tooltip functionality is available on all latest Sublime versions.
- **NEW**: Backtrace info available in Sublime Text build 4087.
- **NEW**: Add `image_border_color` option.
- **FIX**: Fix bug with copying color scheme name.
- **FIX**: Fix some issues related to schemes (Celeste theme) using invalid colors, such as `"none"` to reset background
colors etc.

## 2.14.0

Expand Down Expand Up @@ -36,7 +40,8 @@

## 2.11.1

- **FIX**: Allow `-` in variables names. Write color translations to main scheme object and ensure filtering is done after color translations.
- **FIX**: Allow `-` in variables names. Write color translations to main scheme object and ensure filtering is done
after color translations.

## 2.11.0

Expand Down
11 changes: 11 additions & 0 deletions docs/src/markdown/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,15 @@ defined limit, it will not be highlighted. You can control that limit here.

If you have the [SubNotify][subnotify] installed, this will enable or disable messages through it.

#### `image_border_color`

Set color preview border colors.

```js
// By default, image border is calculated based on theme background, but if for
// some reason, it isn't sufficient in your popup, set it to any color using
// valid CSS for RGB, HSL, or HWB colors.
"image_border_color": null
```

--8<-- "refs.txt"
49 changes: 21 additions & 28 deletions lib/color_scheme_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,38 +260,41 @@ def parse_scheme(self):
color = item.get('foreground', None)
if isinstance(color, list):
# Hashed Syntax Highlighting
for index, c in enumerate(color):
color[index] = Color(
c.strip(), variables=self.variables
).convert("srgb").to_string(**HEX)
elif isinstance(color, str):
if color == "none":
try:
for index, c in enumerate(color):
color[index] = Color(
c.strip(), variables=self.variables
).convert("srgb").to_string(**HEX)
except Exception:
item['foreground'] = "none"
else:
elif isinstance(color, str):
try:
item['foreground'] = Color(
color.strip(), variables=self.variables
).convert("srgb").to_string(**HEX)
except Exception:
item['foreground'] = "none"
# Background color
bgcolor = item.get('background', None)
if isinstance(bgcolor, str):
if bgcolor == "none":
item['background'] = bgcolor
else:
try:
item['background'] = Color(
bgcolor.strip(), variables=self.variables
).convert("srgb").to_string(**HEX)
fgadj = item.get('foreground_adjust', None)
if isinstance(fgadj, str) and fgadj and fgadj != "none":
if isinstance(fgadj, str) and fgadj:
item['foreground_adjust'] = fgadj
except Exception:
pass
# Selection foreground color
scolor = item.get('selection_foreground', None)
if isinstance(scolor, str):
if scolor == "none":
item['selection_foreground'] = "none"
else:
try:
item['selection_foreground'] = Color(
scolor.strip(), variables=self.variables
).convert("srgb").to_string(**HEX)
except Exception:
pass

def setup_matcher(self):
"""Setup colors for color matcher."""
Expand Down Expand Up @@ -367,10 +370,7 @@ def add_entry(self, name, scope, color, bgcolor, fgadj, scolor, style):
else:
fg, fg_sim = None, None
if bgcolor is not None:
if bgcolor == "none":
bg, bg_sim = bgcolor, None
else:
bg, bg_sim = self.process_color(bgcolor)
bg, bg_sim = self.process_color(bgcolor)
else:
bg, bg_sim = None, None
if scolor is not None:
Expand Down Expand Up @@ -541,7 +541,7 @@ def guess_color(self, scope_key, selected=False, explicit_background=False, no_b
else:
color_sim = self.colors[key]["color_simulated"]
color_selector = SchemeSelectors(self.colors[key]["name"], self.colors[key]["scope"])
if (
elif (
self.colors[key]["color_gradient"] is not None and
match > best_match_fg_gradient
):
Expand Down Expand Up @@ -581,15 +581,8 @@ def guess_color(self, scope_key, selected=False, explicit_background=False, no_b
if self.colors[key]["bgcolor"] is not None and match > best_match_bg:
best_match_bg = match
bgcolor = self.colors[key]["bgcolor"]
if bgcolor == "none":
bgcolor = self.special_colors['background']['color'] if not explicit_background else None
bgcolor_sim = (
self.special_colors['background']['color_simulated'] if not explicit_background else None
)
fgadj = None
else:
bgcolor_sim = self.colors[key]["bgcolor_simulated"]
fgadj = self.colors[key]["foreground_adjust"]
bgcolor_sim = self.colors[key]["bgcolor_simulated"]
fgadj = self.colors[key]["foreground_adjust"]
bg_selector = SchemeSelectors(self.colors[key]["name"], self.colors[key]["scope"])

if len(style) == 0:
Expand Down
2 changes: 1 addition & 1 deletion messages/recent.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ScopeHunter 2.14.0
# ScopeHunter 2.15.0

New release!

Expand Down
135 changes: 40 additions & 95 deletions popup.j2
Original file line number Diff line number Diff line change
@@ -1,172 +1,117 @@
## Scope {: .header}
### Scope [(copy)](copy-scope:{{plugin.scope_index}}){: .small} {: .header}
{{plugin.scope}}

[(copy)](copy-scope:{{plugin.scope_index}}){: .small}

{% if plugin.context_backtrace %}
## Scope Context Backtrace {: .header}
## Scope Context Backtrace [(copy)](copy-context-backtrace:{{plugin.context_backtrace_index}}){: .small} {: .header}
{% for ctx in plugin.context_backtrace_stack %}
**{{loop.index}}:**{: .keyword} {{ctx}}

{% endfor %}
[(copy)](copy-context-backtrace:{{plugin.context_backtrace_index}}){: .small}
{% endif %}

{% if plugin.pt_extent or plugin.rowcol_extent %}
## Scope Extent {: .header}
{% if plugin.pt_extent %}
**pts:**{: .keyword} ({{plugin.extent_start}}, {{plugin.extent_end}})

[(copy)](copy-points:{{plugin.extent_pt_index}}){: .small}

{% endif %}
{% if plugin.pt_extent or plugin.rowcol_extent %}
**line/char:**{: .keyword} (**Line:** {{plugin.l_start}} **Char:** {{plugin.c_start}}, **Line:** {{plugin.l_end}} **Char:** {{plugin.c_end}})

[(copy)](copy-line-char:{{plugin.line_char_index}}){: .small}
{% endif %}
{% endif %}

{% if plugin.appearance %}
## Appearance {: .header}
**fg:**{: .keyword} {{plugin.fg_preview}} {{plugin.fg_color}}

[(copy)](copy-fg:{{plugin.fg_index}}){: .small}
### Appearance {: .header}
**fg:**{: .keyword} {{plugin.fg_preview}} {{plugin.fg_color}} [(copy)](copy-fg:{{plugin.fg_index}}){: .small}

{% if plugin.fg_sim %}
**fg (simulated alpha):**{: .keyword} {{plugin.fg_sim_preview}} {{plugin.fg_sim_color}}

[(copy)](copy-fg-sim:{{plugin.fg_sim_index}}){: .small}
**fg (simulated alpha):**{: .keyword} {{plugin.fg_sim_preview}} {{plugin.fg_sim_color}} [(copy)](copy-fg-sim:{{plugin.fg_sim_index}}){: .small}

{% endif %}
{% if plugin.fg_hash %}
**hashed fg:**{: .keyword} {{plugin.fg_hash_preview}} {{plugin.fg_hash_color}}

[(copy)](copy-fg-hash:{{plugin.fg_hash_index}}){: .small}
**hashed fg:**{: .keyword} {{plugin.fg_hash_preview}} {{plugin.fg_hash_color}} [(copy)](copy-fg-hash:{{plugin.fg_hash_index}}){: .small}

{% endif %}
{% if plugin.fg_hash_sim %}
**hashed fg (simulated alpha):**{: .keyword} {{plugin.fg_hash_sim_preview}} {{plugin.fg_hash_sim_color}}

[(copy)](copy-fg-hash-sim:{{plugin.fg_hash_sim_index}}){: .small}
**hashed fg (simulated alpha):**{: .keyword} {{plugin.fg_hash_sim_preview}} {{plugin.fg_hash_sim_color}} [(copy)](copy-fg-hash-sim:{{plugin.fg_hash_sim_index}}){: .small}

{% endif %}
**bg:**{: .keyword} {{plugin.bg_preview}} {{plugin.bg_color}}

[(copy)](copy-bg:{{plugin.bg_index}}){: .small}
**bg:**{: .keyword} {{plugin.bg_preview}} {{plugin.bg_color}} [(copy)](copy-bg:{{plugin.bg_index}}){: .small}

{% if plugin.bg_sim %}
**bg (simulated alpha):**{: .keyword} {{plugin.bg_sim_preview}} {{plugin.bg_sim_color}}

[(copy)](copy-bg-sim:{{plugin.bg_sim_index}}){: .small}
**bg (simulated alpha):**{: .keyword} {{plugin.bg_sim_preview}} {{plugin.bg_sim_color}} [(copy)](copy-bg-sim:{{plugin.bg_sim_index}}){: .small}

{% endif %}
**style:**{: .keyword} {{plugin.style_open}}{{plugin.style}}{{plugin.style_close}}

[(copy)](copy-style:{{plugin.style_index}}){: .small}
**style:**{: .keyword} {{plugin.style_open}}{{plugin.style}}{{plugin.style_close}} [(copy)](copy-style:{{plugin.style_index}}){: .small}

{% endif %}

{% if plugin.selectors %}
## Selectors {: .header}
{% if plugin.fg_name %}
**fg name:**{: .keyword} {{plugin.fg_name}}

[(copy)](copy-fg-sel-name:{{plugin.fg_name_index}}){: .small}
### Scope Extent {: .header}
{% if plugin.pt_extent %}
**pts:**{: .keyword} ({{plugin.extent_start}}, {{plugin.extent_end}}) [(copy)](copy-points:{{plugin.extent_pt_index}}){: .small}

{% endif %}
**fg scope:**{: .keyword} {{plugin.fg_scope}}
{% if plugin.pt_extent or plugin.rowcol_extent %}
**line:char:**{: .keyword} ({{plugin.l_start}}:{{plugin.c_start}}, {{plugin.l_end}}:{{plugin.c_end}}) [(copy)](copy-line-char:{{plugin.line_char_index}}){: .small}
{% endif %}
{% endif %}

[(copy)](copy-fg-sel-scope:{{plugin.fg_scope_index}}){: .small}
{% if plugin.appearance %}
### Selectors {: .header}
{% if plugin.fg_name %}
**fg name:**{: .keyword} {{plugin.fg_name}} [(copy)](copy-fg-sel-name:{{plugin.fg_name_index}}){: .small}

{% if plugin.fg_hash_name %}
**hashed fg name:**{: .keyword} {{plugin.fg_hash_name}}
{% endif %}
**fg scope:**{: .keyword} [(copy)](copy-fg-sel-scope:{{plugin.fg_scope_index}}){: .small} {{plugin.fg_scope}}

[(copy)](copy-fg-hash-sel-name:{{plugin.fg_hash_name_index}}){: .small}
{% if plugin.fg_hash_name %}
**hashed fg name:**{: .keyword} {{plugin.fg_hash_name}} [(copy)](copy-fg-hash-sel-name:{{plugin.fg_hash_name_index}}){: .small}

{% endif %}
{% if plugin.fg_hash_scope %}
**hashed fg scope:**{: .keyword} {{plugin.fg_hash_scope}}

[(copy)](copy-fg-hash-sel-scope:{{plugin.fg_hash_scope_index}}){: .small}
**hashed fg scope:**{: .keyword} [(copy)](copy-fg-hash-sel-scope:{{plugin.fg_hash_scope_index}}){: .small} {{plugin.fg_hash_scope}}

{% endif %}
{% if plugin.bg_name %}
**bg name:**{: .keyword} {{plugin.bg_name}}

[(copy)](copy-bg-sel-name:{{plugin.bg_name_index}}){: .small}
**bg name:**{: .keyword} {{plugin.bg_name}} [(copy)](copy-bg-sel-name:{{plugin.bg_name_index}}){: .small}

{% endif %}
**bg scope:**{: .keyword} {{plugin.bg_scope}}

[(copy)](copy-bg-sel-scope:{{plugin.bg_scope_index}}){: .small}
**bg scope:**{: .keyword} [(copy)](copy-bg-sel-scope:{{plugin.bg_scope_index}}){: .small} {{plugin.bg_scope}}

{% if plugin.bold %}
{% if plugin.bold_name %}
**bold name:**{: .keyword} {{plugin.bold_name}}

[(copy)](copy-bold-sel-name:{{plugin.bold_name_index}}){: .small}
**bold name:**{: .keyword} {{plugin.bold_name}} [(copy)](copy-bold-sel-name:{{plugin.bold_name_index}}){: .small}

{% endif %}
**bold scope:**{: .keyword} {{plugin.bold_scope}}

[(copy)](copy-bold-sel-scope:{{plugin.bold_scope_index}}){: .small}
**bold scope:**{: .keyword} [(copy)](copy-bold-sel-scope:{{plugin.bold_scope_index}}){: .small} {{plugin.bold_scope}}

{% endif %}
{% if plugin.italic %}
{% if plugin.italic_name %}
**italic name:**{: .keyword} {{plugin.italic_name}}

[(copy)](copy-italic-sel-name:{{plugin.italic_name_index}}){: .small}
**italic name:**{: .keyword} {{plugin.italic_name}} [(copy)](copy-italic-sel-name:{{plugin.italic_name_index}}){: .small}

{% endif %}
**italic scope:**{: .keyword} {{plugin.italic_scope}}

[(copy)](copy-italic-sel-scope:{{plugin.italic_scope_index}}){: .small}
**italic scope:**{: .keyword} [(copy)](copy-italic-sel-scope:{{plugin.italic_scope_index}}){: .small} {{plugin.italic_scope}}

{% endif %}
{% if plugin.underline %}
{% if plugin.underline_name %}
**underline name:**{: .keyword} {{plugin.underline_name}}

[(copy)](copy-underline-sel-name:{{plugin.glow_underline_index}}){: .small}
**underline name:**{: .keyword} {{plugin.underline_name}} [(copy)](copy-underline-sel-name:{{plugin.glow_underline_index}}){: .small}

{% endif %}
**underline scope:**{: .keyword} {{plugin.underline_scope}}

[(copy)](copy-underline-sel-scope:{{plugin.underline_scope_index}}){: .small}
**underline scope:**{: .keyword} [(copy)](copy-underline-sel-scope:{{plugin.underline_scope_index}}){: .small} {{plugin.underline_scope}}

{% endif %}
{% if plugin.glow %}
{% if plugin.glow_name %}
**glow name:**{: .keyword} {{plugin.glow_name}}

[(copy)](copy-glow-sel-name:{{plugin.glow_name_index}}){: .small}
**glow name:**{: .keyword} {{plugin.glow_name}} [(copy)](copy-glow-sel-name:{{plugin.glow_name_index}}){: .small}

{% endif %}
**glow scope:**{: .keyword} {{plugin.glow_scope}}

[(copy)](copy-glow-sel-scope:{{plugin.glow_scope_index}}){: .small}
**glow scope:**{: .keyword} [(copy)](copy-glow-sel-scope:{{plugin.glow_scope_index}}){: .small} {{plugin.glow_scope}}

{% endif %}
{% endif %}

{% if plugin.files %}
## Files {: .header}
**syntax:**{: .keyword} [{{plugin.syntax}}](syntax)

[(copy)](copy-syntax:{{plugin.syntax_index}}){: .small}
### Files {: .header}
**syntax:**{: .keyword} [{{plugin.syntax}}](syntax) [(copy)](copy-syntax:{{plugin.syntax_index}}){: .small}

{% if plugin.scheme %}
**tmTheme:**{: .keyword} [{{plugin.scheme}}](scheme)

[(copy)](copy-scheme:{{plugin.scheme_index}}){: .small}
**tmTheme:**{: .keyword} [{{plugin.scheme}}](scheme) [(copy)](copy-scheme:{{plugin.scheme_index}}){: .small}
{% endif %}

{% for item in plugin.overrides %}
**Scheme {{loop.index}}:**{: .keyword} [{{item}}](override:{{plugin.overrides_index}}:{{loop.index}})

[(copy)](copy-overrides:{{plugin.overrides_index}}:{{loop.index}}){: .small}
**Scheme {{loop.index}}:**{: .keyword} [{{item}}](override:{{plugin.overrides_index}}:{{loop.index}}) [(copy)](copy-overrides:{{plugin.overrides_index}}:{{loop.index}}){: .small}

{% endfor %}
{% endif %}
Loading

0 comments on commit 9534733

Please sign in to comment.