Skip to content

Commit 6dd1d78

Browse files
authored
Add preview window padding config and run on window activation (#251)
Resolves #249
1 parent 20abd71 commit 6dd1d78

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
likely what people expect even if it is not an ideal approach. Use
99
`gamut_map` in settings option to manually control the approach.
1010
- **NEW**: Upgrade ColorAide to 2.4.
11+
- **NEW**: Previews now run immediately on view activation.
12+
- **NEW**: The sliding preview window has configurable padding to scan
13+
a larger region.
1114
- **FIX**: Fix regression where contrast logic could not adjust to a
1215
given contrast due to a property access.
1316

ch_preview.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,20 @@ def do_search(self, force=False):
336336
force = True
337337

338338
# Get viewable bounds so we can constrain both vertically and horizontally.
339+
padding = ch_settings.get('preview_window_padding', [0, 0])
340+
row_pad = int(padding[0])
341+
col_pad = int(padding[1])
342+
last_row = self.view.rowcol(self.view.size())[0]
339343
visible_region = self.view.visible_region()
344+
if row_pad or col_pad:
345+
row1, col1 = self.view.rowcol(visible_region.begin())
346+
row2, col2 = self.view.rowcol(visible_region.end())
347+
row1 = max(0, row1 - int(row_pad))
348+
row2 = min(last_row, row2 + int(row_pad))
349+
col1 = max(0, col1 - col_pad)
350+
col2 = col2 + col_pad
351+
visible_region = sublime.Region(self.view.text_point(row1, col1), self.view.text_point(row2, col2))
352+
340353
position = self.view.viewport_position()
341354
dimensions = self.view.viewport_extent()
342355
bounds = Dimensions(
@@ -665,9 +678,8 @@ def on_activated(self, view):
665678
return
666679

667680
if self.should_update(view):
668-
ch_preview_thread.modified = True
669-
ch_preview_thread.time = time()
670681
self.set_file_scan_rules(view)
682+
view.window().run_command('color_helper_preview', {"clear": False, "force": True})
671683

672684
def set_file_scan_rules(self, view):
673685
"""Set the scan rules for the current view."""

color_helper.sublime-settings

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101
// color by using gamut mapping.
102102
"show_out_of_gamut_preview": true,
103103

104+
// Define padding around sliding preview window
105+
// Extend the range previews processed by ColorHelper.
106+
// Value should be positive integers and represent the rows and columns
107+
// to extend the range by. Padding is applied on both sides. So padding
108+
// by 20 rows pads by 20 on the top and 20 on the bottom. Large padding
109+
// could cause lag with typing or scrolling.
110+
"preview_window_padding": [20, 20],
111+
104112
// The gamut space to render previews in.
105113
// Supported spaces are: `srgb`, `display-p3`, `rec2020`,
106114
// `a98-rgb`, and `prophoto-rgb`.

docs/src/markdown/settings/previews.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ Previews can be positioned to the left or right of a color. Set this value to "l
1515
"inline_preview_position": "left",
1616
```
1717

18+
##
19+
20+
Color previews are processed in a sliding window. Without any padding it exactly matches the visible region. This allows
21+
you to extend the window and process content just out of visible range. It should be noted though that large padding
22+
could cause typing or scrolling lag.
23+
24+
```js
25+
// Define padding around sliding preview window
26+
// Extend the range previews processed by ColorHelper.
27+
// Value should be positive integers and represent the rows and columns
28+
// to extend the range by. Padding is applied on both sides. So padding
29+
// by 20 rows pads by 20 on the top and 20 on the bottom. Large padding
30+
// could cause lag with typing or scrolling.
31+
"preview_window_padding": [20, 20],
32+
````
33+
1834
## `preview_on_select`
1935

2036
Enables/disables previews only showing when they are selected.

messages/recent.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ related to the upgrade to stable `coloraide`.
1818
likely what people expect even if it is not an ideal approach. Use
1919
`gamut_map` in settings option to manually control the approach.
2020
- **NEW**: Upgrade ColorAide to 2.4.
21+
- **NEW**: Previews now run immediately on view activation.
22+
- **NEW**: The sliding preview window has configurable padding to scan
23+
a larger region.
2124
- **FIX**: Fix regression where contrast logic could not adjust to a
2225
given contrast due to a property access.

0 commit comments

Comments
 (0)