Skip to content

Commit 59bcca6

Browse files
authored
fix: allow hiding unmatched in grid (#113)
1 parent f91567f commit 59bcca6

7 files changed

Lines changed: 80 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ live_match_update = true # Update matched cells in real-time without screen fla
804804
subgrid_enabled = true # Enable 3×3 sublayer for precision
805805
subgrid_rows = 3
806806
subgrid_cols = 3
807+
hide_unmatched = true # Hide unmatched cells during typing to reduce visual clutter
807808
sublayer_keys = "asdfghjkl" # Keys for subgrid selection (at least 9 characters for 3×3)
808809
```
809810

cmd/neru/modes.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ func (a *App) setupGrid(action Action) error {
212212
// Initialize manager with the new grid
213213
a.gridManager = grid.NewManager(gridInstance, subRows, subCols, keys, func() {
214214
// Update matches only (no full redraw)
215-
(*a.gridCtx.gridOverlay).UpdateMatches(a.gridManager.GetInput())
215+
input := a.gridManager.GetInput()
216+
217+
// Set hideUnmatched based on whether we have input and the config setting
218+
hideUnmatched := a.config.Grid.HideUnmatched && len(input) > 0
219+
(*a.gridCtx.gridOverlay).SetHideUnmatched(hideUnmatched)
220+
221+
(*a.gridCtx.gridOverlay).UpdateMatches(input)
216222
}, func(cell *grid.Cell) {
217223
// Draw 3x3 subgrid inside selected cell
218224
(*a.gridCtx.gridOverlay).ShowSubgrid(cell)

configs/default-config.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ max_cell_size = 200
265265
# Grid label style
266266
font_size = 12
267267
font_family = ""
268-
opacity = 0.5
268+
opacity = 0.7
269269

270270
# Colors
271271
background_color = "#abe9b3"
272-
text_color = "#ffffff"
273-
matched_text_color = "#ffffff"
272+
text_color = "#000000"
273+
matched_text_color = "#000000"
274274
matched_background_color = "#f8bd96" # Background color for matched grid cells
275275
matched_border_color = "#f8bd96" # Border color for matched grid cells
276276
border_color = "#abe9b3"
@@ -281,6 +281,7 @@ live_match_update = true # Update matched highlight per keystroke without f
281281
subgrid_enabled = true # Enable precision sublayer after main label selection
282282
subgrid_rows = 3 # Subgrid rows
283283
subgrid_cols = 3 # Subgrid columns
284+
hide_unmatched = true # Hide unmatched cells during typing
284285
# Sublayer keys used for subgrid selection (at least rows*cols characters)
285286
sublayer_keys = "asdfghjkl"
286287

internal/bridge/overlay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct {
5050
char* label;
5151
CGRect bounds; // Cell rectangle
5252
int isMatched; // 1 if cell matches current input, 0 otherwise
53+
int isSubgrid; // 1 if cell is part of subgrid, 0 otherwise
5354
} GridCell;
5455

5556
// Function declarations
@@ -67,5 +68,6 @@ void drawTargetDot(OverlayWindow window, CGPoint center, double radius, const ch
6768
void drawGridCells(OverlayWindow window, GridCell* cells, int count, GridCellStyle style);
6869
void drawGridLines(OverlayWindow window, CGRect* lines, int count, char* color, int width, double opacity);
6970
void updateGridMatchPrefix(OverlayWindow window, const char* prefix);
71+
void setHideUnmatched(OverlayWindow window, int hide);
7072

7173
#endif // OVERLAY_H

internal/bridge/overlay.m

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ - (void)drawGridCells {
438438
NSString *label = cellDict[@"label"];
439439
NSValue *boundsValue = cellDict[@"bounds"];
440440
BOOL isMatched = [cellDict[@"isMatched"] boolValue];
441+
BOOL isSubgrid = [cellDict[@"isSubgrid"] boolValue];
442+
443+
// Skip drawing unmatched cells if hideUnmatched is enabled AND it's not a subgrid cell
444+
if (self.hideUnmatched && !isMatched && !isSubgrid) {
445+
continue;
446+
}
441447

442448
CGRect bounds = [boundsValue rectValue];
443449

@@ -847,7 +853,8 @@ void drawGridCells(OverlayWindow window, GridCell* cells, int count, GridCellSty
847853
NSDictionary *cellDict = @{
848854
@"label": cell.label ? @(cell.label) : @"",
849855
@"bounds": [NSValue valueWithRect:NSRectFromCGRect(cell.bounds)],
850-
@"isMatched": @(cell.isMatched)
856+
@"isMatched": @(cell.isMatched),
857+
@"isSubgrid": @(cell.isSubgrid)
851858
};
852859
[cellDicts addObject:cellDict];
853860
}
@@ -882,8 +889,8 @@ void drawGridCells(OverlayWindow window, GridCell* cells, int count, GridCellSty
882889
controller.overlayView.gridBackgroundColor = [controller.overlayView colorFromHex:bgHex defaultColor:[NSColor whiteColor]];
883890
controller.overlayView.gridTextColor = [controller.overlayView colorFromHex:textHex defaultColor:[NSColor blackColor]];
884891
controller.overlayView.gridMatchedTextColor = [controller.overlayView colorFromHex:matchedTextHex defaultColor:[NSColor blueColor]];
885-
controller.overlayView.gridMatchedBackgroundColor = [controller.overlayView colorFromHex:matchedBgHex defaultColor:controller.overlayView.gridMatchedTextColor];
886-
controller.overlayView.gridMatchedBorderColor = [controller.overlayView colorFromHex:matchedBorderHex defaultColor:controller.overlayView.gridMatchedTextColor];
892+
controller.overlayView.gridMatchedBackgroundColor = [controller.overlayView colorFromHex:matchedBgHex defaultColor:[NSColor blueColor]];
893+
controller.overlayView.gridMatchedBorderColor = [controller.overlayView colorFromHex:matchedBorderHex defaultColor:[NSColor blueColor]];
887894
controller.overlayView.gridBorderColor = [controller.overlayView colorFromHex:borderHex defaultColor:[NSColor grayColor]];
888895
controller.overlayView.gridBorderWidth = borderWidth > 0 ? borderWidth : 1.0;
889896
controller.overlayView.gridBackgroundOpacity = (backgroundOpacity >= 0.0 && backgroundOpacity <= 1.0) ? backgroundOpacity : 0.85;
@@ -939,13 +946,27 @@ void updateGridMatchPrefix(OverlayWindow window, const char* prefix) {
939946
isMatched = [lblPrefix isEqualToString:prefixStr];
940947
}
941948
// Always include the cell, just update its matched state
949+
// Preserve the isSubgrid field
950+
BOOL isSubgrid = [cellDict[@"isSubgrid"] boolValue];
942951
NSDictionary *newDict = @{ @"label": label,
943952
@"bounds": cellDict[@"bounds"],
944-
@"isMatched": @(isMatched) };
953+
@"isMatched": @(isMatched),
954+
@"isSubgrid": @(isSubgrid) };
945955
[updated addObject:newDict];
946956
}
947957
[controller.overlayView.gridCells removeAllObjects];
948958
[controller.overlayView.gridCells addObjectsFromArray:updated];
949959
[controller.overlayView setNeedsDisplay:YES];
950960
});
951961
}
962+
963+
void setHideUnmatched(OverlayWindow window, int hide) {
964+
if (!window) return;
965+
966+
OverlayWindowController *controller = (OverlayWindowController*)window;
967+
968+
dispatch_async(dispatch_get_main_queue(), ^{
969+
controller.overlayView.hideUnmatched = hide ? YES : NO;
970+
[controller.overlayView setNeedsDisplay:YES];
971+
});
972+
}

internal/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ type GridConfig struct {
126126
SubgridRows int `toml:"subgrid_rows"`
127127
SubgridCols int `toml:"subgrid_cols"`
128128
Enabled bool `toml:"enabled"`
129+
HideUnmatched bool `toml:"hide_unmatched"`
129130
LeftClick GridActionConfig `toml:"left_click"`
130131
RightClick GridActionConfig `toml:"right_click"`
131132
DoubleClick GridActionConfig `toml:"double_click"`
@@ -306,8 +307,8 @@ func DefaultConfig() *Config {
306307
FontFamily: "SF Mono",
307308
Opacity: 0.85,
308309
BackgroundColor: "#abe9b3",
309-
TextColor: "#ffffff",
310-
MatchedTextColor: "#ffffff",
310+
TextColor: "#000000",
311+
MatchedTextColor: "#000000",
311312
MatchedBackgroundColor: "#f8bd96",
312313
MatchedBorderColor: "#f8bd96",
313314
BorderColor: "#abe9b3",
@@ -317,6 +318,7 @@ func DefaultConfig() *Config {
317318
SubgridRows: 3,
318319
SubgridCols: 3,
319320
Enabled: true,
321+
HideUnmatched: true,
320322
LeftClick: GridActionConfig{RestoreCursor: false},
321323
RightClick: GridActionConfig{RestoreCursor: false},
322324
DoubleClick: GridActionConfig{RestoreCursor: false},

internal/grid/grid_overlay.go

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ package grid
44
#cgo CFLAGS: -x objective-c
55
#include "../bridge/overlay.h"
66
#include <stdlib.h>
7-
8-
// Explicit declaration to satisfy cgo name resolution
9-
void drawScrollHighlight(OverlayWindow window, CGRect bounds, char* color, int width);
107
*/
118
import "C"
129

@@ -37,6 +34,19 @@ func (o *GridOverlay) UpdateConfig(cfg config.GridConfig) {
3734
o.cfg = cfg
3835
}
3936

37+
// SetHideUnmatched sets whether to hide unmatched cells
38+
func (o *GridOverlay) SetHideUnmatched(hide bool) {
39+
C.setHideUnmatched(o.window, C.int(boolToInt(hide)))
40+
}
41+
42+
// boolToInt converts a boolean to an integer (1 for true, 0 for false)
43+
func boolToInt(b bool) int {
44+
if b {
45+
return 1
46+
}
47+
return 0
48+
}
49+
4050
// Show displays the grid overlay
4151
func (o *GridOverlay) Show() {
4252
C.showOverlayWindow(o.window)
@@ -138,6 +148,7 @@ func (o *GridOverlay) ShowSubgrid(cell *Cell) {
138148
size: C.CGSize{width: C.double(right - left), height: C.double(bottom - top)},
139149
},
140150
isMatched: C.int(0),
151+
isSubgrid: C.int(1), // Mark as subgrid cell
141152
}
142153
}
143154

@@ -150,15 +161,17 @@ func (o *GridOverlay) ShowSubgrid(cell *Cell) {
150161
borderColor := C.CString(o.cfg.BorderColor)
151162

152163
style := C.GridCellStyle{
153-
fontSize: C.int(o.cfg.FontSize),
154-
fontFamily: fontFamily,
155-
backgroundColor: backgroundColor,
156-
textColor: textColor,
157-
matchedTextColor: matchedTextColor,
158-
borderColor: borderColor,
159-
borderWidth: C.int(o.cfg.BorderWidth),
160-
backgroundOpacity: C.double(o.cfg.Opacity),
161-
textOpacity: C.double(1.0),
164+
fontSize: C.int(o.cfg.FontSize),
165+
fontFamily: fontFamily,
166+
backgroundColor: backgroundColor,
167+
textColor: textColor,
168+
matchedTextColor: matchedTextColor,
169+
matchedBackgroundColor: matchedBackgroundColor,
170+
matchedBorderColor: matchedBorderColor,
171+
borderColor: borderColor,
172+
borderWidth: C.int(o.cfg.BorderWidth),
173+
backgroundOpacity: C.double(o.cfg.Opacity),
174+
textOpacity: C.double(1.0),
162175
}
163176

164177
C.clearOverlay(o.window)
@@ -228,6 +241,7 @@ func (o *GridOverlay) drawGridCells(cellsGo []*Cell, currentInput string) {
228241
size: C.CGSize{width: C.double(cell.Bounds.Dx()), height: C.double(cell.Bounds.Dy())},
229242
},
230243
isMatched: C.int(isMatched),
244+
isSubgrid: C.int(0), // Mark as regular grid cell
231245
}
232246
}
233247

@@ -240,15 +254,17 @@ func (o *GridOverlay) drawGridCells(cellsGo []*Cell, currentInput string) {
240254
borderColor := C.CString(o.cfg.BorderColor)
241255

242256
style := C.GridCellStyle{
243-
fontSize: C.int(o.cfg.FontSize),
244-
fontFamily: fontFamily,
245-
backgroundColor: backgroundColor,
246-
textColor: textColor,
247-
matchedTextColor: matchedTextColor,
248-
borderColor: borderColor,
249-
borderWidth: C.int(o.cfg.BorderWidth),
250-
backgroundOpacity: C.double(o.cfg.Opacity),
251-
textOpacity: C.double(1.0),
257+
fontSize: C.int(o.cfg.FontSize),
258+
fontFamily: fontFamily,
259+
backgroundColor: backgroundColor,
260+
textColor: textColor,
261+
matchedTextColor: matchedTextColor,
262+
matchedBackgroundColor: matchedBackgroundColor,
263+
matchedBorderColor: matchedBorderColor,
264+
borderColor: borderColor,
265+
borderWidth: C.int(o.cfg.BorderWidth),
266+
backgroundOpacity: C.double(o.cfg.Opacity),
267+
textOpacity: C.double(1.0),
252268
}
253269

254270
C.drawGridCells(o.window, &cGridCells[0], C.int(len(cGridCells)), style)

0 commit comments

Comments
 (0)