From 7ab4d7a78361fcec3a3c4cf884381984564c3a3c Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 25 Jun 2024 17:34:13 +0200 Subject: [PATCH 1/4] Simplify search code. Just look after current current selection, including it, and as fallback before it. Handle no-selection just with a skip. --- FSNode/FSNBrowserColumn.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/FSNode/FSNBrowserColumn.m b/FSNode/FSNBrowserColumn.m index b4245463..45e6e737 100644 --- a/FSNode/FSNBrowserColumn.m +++ b/FSNode/FSNBrowserColumn.m @@ -805,15 +805,12 @@ - (BOOL)selectCellWithPrefix:(NSString *)prefix NSString *cellStr = nil; NSInteger i = 0; - // Nothing selected - if (selRow != -1) - cellStr = [[matrix cellAtRow: selRow column: 0] stringValue]; + // Nothing selected start from first + if (selRow == -1) + selRow = 0; - if (cellStr && ([cellStr length] > 0) && [cellStr hasPrefix: prefix]) - return YES; - - // look after current selection - for (i = selRow + 1; i < n; i++) + // look at or after current selection + for (i = selRow; i < n; i++) { cellStr = [[matrix cellAtRow: i column: 0] stringValue]; From e56332ca5fe0a97493ab0933dd8482b9a850bdec Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 25 Jun 2024 21:29:55 +0200 Subject: [PATCH 2/4] make variable name more meaningful --- FSNode/FSNIconsView.h | 7 ++++--- FSNode/FSNIconsView.m | 10 +++++----- FSNode/FSNListView.h | 2 +- FSNode/FSNListView.m | 10 +++++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/FSNode/FSNIconsView.h b/FSNode/FSNIconsView.h index a0831bc7..0ce8bb74 100644 --- a/FSNode/FSNIconsView.h +++ b/FSNode/FSNIconsView.h @@ -1,8 +1,9 @@ /* FSNIconsView.h * - * Copyright (C) 2004-2013 Free Software Foundation, Inc. + * Copyright (C) 2004-2024 Free Software Foundation, Inc. * - * Author: Enrico Sersale + * Authors: Enrico Sersale + * Riccardo Mottola * Date: March 2004 * * This file is part of the GNUstep FSNode framework @@ -62,7 +63,7 @@ BOOL forceCopy; NSString *charBuffer; - NSTimeInterval lastKeyPressed; + NSTimeInterval lastKeyPressedTime; NSColor *backColor; NSColor *textColor; diff --git a/FSNode/FSNIconsView.m b/FSNode/FSNIconsView.m index afe65e85..461fd566 100644 --- a/FSNode/FSNIconsView.m +++ b/FSNode/FSNIconsView.m @@ -176,7 +176,7 @@ - (id)init editIcon = nil; isDragTarget = NO; - lastKeyPressed = 0.; + lastKeyPressedTime = 0.0; charBuffer = nil; selectionMask = NSSingleSelectionMask; @@ -758,11 +758,11 @@ - (void)keyDown:(NSEvent *)theEvent if (charBuffer == nil) { charBuffer = [characters substringToIndex: 1]; RETAIN (charBuffer); - lastKeyPressed = 0.0; + lastKeyPressedTime = 0.0; } else { - if ([theEvent timestamp] - lastKeyPressed < 500.0) + if ([theEvent timestamp] - lastKeyPressedTime < 500.0) { ASSIGN (charBuffer, ([charBuffer stringByAppendingString: [characters substringToIndex: 1]])); @@ -770,11 +770,11 @@ - (void)keyDown:(NSEvent *)theEvent else { ASSIGN (charBuffer, ([characters substringToIndex: 1])); - lastKeyPressed = 0.0; + lastKeyPressedTime = 0.0; } } - lastKeyPressed = [theEvent timestamp]; + lastKeyPressedTime = [theEvent timestamp]; if ((*icnwp)(self, icnwpSel, charBuffer)) { return; diff --git a/FSNode/FSNListView.h b/FSNode/FSNListView.h index 5692b366..6dc23615 100644 --- a/FSNode/FSNListView.h +++ b/FSNode/FSNListView.h @@ -305,7 +305,7 @@ { id dsource; NSString *charBuffer; - NSTimeInterval lastKeyPressed; + NSTimeInterval lastKeyPressedTime; NSTimer *clickTimer; } diff --git a/FSNode/FSNListView.m b/FSNode/FSNListView.m index e8ba288c..78e7a124 100644 --- a/FSNode/FSNListView.m +++ b/FSNode/FSNListView.m @@ -2680,7 +2680,7 @@ - (id)initWithFrame:(NSRect)frameRect [self setTarget: dsource]; [self setDoubleAction: @selector(doubleClickOnListView:)]; - lastKeyPressed = 0.; + lastKeyPressedTime = 0.0; charBuffer = nil; [self registerForDraggedTypes: [NSArray arrayWithObjects: @@ -2829,11 +2829,11 @@ - (void)keyDown:(NSEvent *)theEvent { charBuffer = [characters substringToIndex: 1]; RETAIN (charBuffer); - lastKeyPressed = 0.0; + lastKeyPressedTime = 0.0; } else { - if ([theEvent timestamp] - lastKeyPressed < 500.0) + if ([theEvent timestamp] - lastKeyPressedTime < 500.0) { ASSIGN (charBuffer, ([charBuffer stringByAppendingString: [characters substringToIndex: 1]])); @@ -2841,11 +2841,11 @@ - (void)keyDown:(NSEvent *)theEvent else { ASSIGN (charBuffer, ([characters substringToIndex: 1])); - lastKeyPressed = 0.0; + lastKeyPressedTime = 0.0; } } - lastKeyPressed = [theEvent timestamp]; + lastKeyPressedTime = [theEvent timestamp]; if ((*icnwp)(dsource, icnwpSel, charBuffer)) { From 52c1850218c95dafca4566c038f9cacad4f6b923 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 25 Jun 2024 23:58:26 +0200 Subject: [PATCH 3/4] Change type-select behaviour: - if appended buffer matches fine, else use the typed character to start a new selection - shorten time for one-word to 5 seconds (should be unified into a constant or preference) - while a character doesn't match any beginning, keep re-initing - allow exiting word-typing with esc --- FSNode/FSNBrowser.m | 48 +++++++++++++++++++++++---------------- FSNode/FSNIconsView.m | 53 ++++++++++++++++++++++++------------------- FSNode/FSNListView.m | 43 +++++++++++++++++++---------------- 3 files changed, 81 insertions(+), 63 deletions(-) diff --git a/FSNode/FSNBrowser.m b/FSNode/FSNBrowser.m index 8247e309..78001f61 100644 --- a/FSNode/FSNBrowser.m +++ b/FSNode/FSNBrowser.m @@ -1298,6 +1298,7 @@ - (void)keyDown:(NSEvent *)theEvent { NSString *characters = [theEvent characters]; unichar character = 0; + NSString *characterStr = nil; FSNBrowserColumn *column = [self selectedColumn]; NSMatrix *matrix; @@ -1318,6 +1319,7 @@ - (void)keyDown:(NSEvent *)theEvent if ([characters length] > 0) { character = [characters characterAtIndex: 0]; + characterStr = [characters substringToIndex: 1]; } switch (character) @@ -1358,6 +1360,11 @@ - (void)keyDown:(NSEvent *)theEvent [matrix sendDoubleAction]; DESTROY(charBuffer); return; + case 0x01B: // Escape + DESTROY(charBuffer); + return; + default: + break; } if (([characters length] > 0) && (character < 0xF700)) @@ -1366,7 +1373,7 @@ - (void)keyDown:(NSEvent *)theEvent if (column) { - int index = [column index]; + NSInteger index = [column index]; matrix = [column cmatrix]; @@ -1374,38 +1381,39 @@ - (void)keyDown:(NSEvent *)theEvent { return; } - - if (charBuffer == nil) - { - charBuffer = [characters substringToIndex: 1]; - RETAIN (charBuffer); - } - else + + if (charBuffer != nil) { - if (([theEvent timestamp] - lastKeyPressedTime < 500.0) + if (([theEvent timestamp] - lastKeyPressedTime < 5.0) // seconds && (alphaNumericalLastColumn == index)) { - NSString *appendBuff = [charBuffer stringByAppendingString: - [characters substringToIndex: 1]]; - ASSIGN(charBuffer, appendBuff); - } - else - { - ASSIGN(charBuffer, [characters substringToIndex: 1]); + NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr]; + + // Try selecting + if ([column selectCellWithPrefix: appendBuffer]) + { + ASSIGN(charBuffer, appendBuffer); + [[self window] makeFirstResponder: matrix]; + return; + } + // unable to select - fall-through and reinit as if typed is first char } } - + + ASSIGN(charBuffer, characterStr); alphaNumericalLastColumn = index; lastKeyPressedTime = [theEvent timestamp]; - + + // Try selecting if ([column selectCellWithPrefix: charBuffer]) { [[self window] makeFirstResponder: matrix]; return; } - } - lastKeyPressedTime = 0.0; + // Selection failed, reinitialize and use mismatching character as new buffer beginning + DESTROY(charBuffer); + } } [super keyDown: theEvent]; diff --git a/FSNode/FSNIconsView.m b/FSNode/FSNIconsView.m index 461fd566..385635dd 100644 --- a/FSNode/FSNIconsView.m +++ b/FSNode/FSNIconsView.m @@ -670,6 +670,7 @@ - (void)keyDown:(NSEvent *)theEvent { NSString *characters; unichar character; + NSString *characterStr = nil; NSRect vRect, hiddRect; NSPoint p; float x, y, w, h; @@ -678,9 +679,13 @@ - (void)keyDown:(NSEvent *)theEvent character = 0; if ([characters length] > 0) - character = [characters characterAtIndex: 0]; + { + character = [characters characterAtIndex: 0]; + characterStr = [characters substringToIndex: 1]; + } - switch (character) { + switch (character) + { case NSPageUpFunctionKey: vRect = [self visibleRect]; p = vRect.origin; @@ -745,40 +750,42 @@ - (void)keyDown:(NSEvent *)theEvent [self openSelectionInNewViewer: closesndr]; return; } - + case 0x01B: // Escape + DESTROY(charBuffer); + return; default: break; } if (([characters length] > 0) && (character < 0xF700)) { - SEL icnwpSel = @selector(selectIconWithPrefix:); - IMP icnwp = [self methodForSelector: icnwpSel]; - - if (charBuffer == nil) { - charBuffer = [characters substringToIndex: 1]; - RETAIN (charBuffer); - lastKeyPressedTime = 0.0; - } - else + if (charBuffer != nil) { - if ([theEvent timestamp] - lastKeyPressedTime < 500.0) - { - ASSIGN (charBuffer, ([charBuffer stringByAppendingString: - [characters substringToIndex: 1]])); - } - else + if ([theEvent timestamp] - lastKeyPressedTime < 5.0) { - ASSIGN (charBuffer, ([characters substringToIndex: 1])); - lastKeyPressedTime = 0.0; + NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr]; + + // Try selecting + if ([self selectIconWithPrefix: appendBuffer]) + { + ASSIGN(charBuffer, appendBuffer); + return; + } + // unable to select - fall-through and reinit as if typed is first char } } + ASSIGN(charBuffer, characterStr); lastKeyPressedTime = [theEvent timestamp]; - if ((*icnwp)(self, icnwpSel, charBuffer)) { - return; - } + // Try selecting + if ([self selectIconWithPrefix: charBuffer]) + { + return; + } + + // Selection failed, reinitialize and use mismatching character as new buffer beginning + DESTROY(charBuffer); } [super keyDown: theEvent]; diff --git a/FSNode/FSNListView.m b/FSNode/FSNListView.m index 78e7a124..0d039ad7 100644 --- a/FSNode/FSNListView.m +++ b/FSNode/FSNListView.m @@ -2762,6 +2762,7 @@ - (void)keyDown:(NSEvent *)theEvent { NSString *characters = [theEvent characters]; unichar character = 0; + NSString *characterStr = nil; NSRect vRect, hiddRect; NSPoint p; float x, y, w, h; @@ -2769,6 +2770,7 @@ - (void)keyDown:(NSEvent *)theEvent if ([characters length] > 0) { character = [characters characterAtIndex: 0]; + characterStr = [characters substringToIndex: 1]; } switch (character) @@ -2813,44 +2815,45 @@ - (void)keyDown:(NSEvent *)theEvent BOOL closesndr = ((flags == NSAlternateKeyMask) || (flags == NSControlKeyMask)); [dsource openSelectionInNewViewer: closesndr]; + DESTROY(charBuffer); return; } - + case 0x01B: // Escape + DESTROY(charBuffer); + return; default: break; } if (([characters length] > 0) && (character < 0xF700)) { - SEL icnwpSel = @selector(selectRepWithPrefix:); - IMP icnwp = [dsource methodForSelector: icnwpSel]; - - if (charBuffer == nil) + if (charBuffer != nil) { - charBuffer = [characters substringToIndex: 1]; - RETAIN (charBuffer); - lastKeyPressedTime = 0.0; - } - else - { - if ([theEvent timestamp] - lastKeyPressedTime < 500.0) + if ([theEvent timestamp] - lastKeyPressedTime < 5.0) // seconds { - ASSIGN (charBuffer, ([charBuffer stringByAppendingString: - [characters substringToIndex: 1]])); - } - else - { - ASSIGN (charBuffer, ([characters substringToIndex: 1])); - lastKeyPressedTime = 0.0; + NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr]; + + // Try selecting + if ([dsource selectRepWithPrefix:appendBuffer]) + { + ASSIGN(charBuffer, appendBuffer); + return; + } + // unable to select - fall-through and reinit as if typed is first char } } + ASSIGN(charBuffer, characterStr); lastKeyPressedTime = [theEvent timestamp]; - if ((*icnwp)(dsource, icnwpSel, charBuffer)) + // Try selecting + if ([dsource selectRepWithPrefix:charBuffer]) { return; } + + // Selection failed, reinitialize and use mismatching character as new buffer beginning + DESTROY(charBuffer); } [super keyDown: theEvent]; From a513e281d94b78279b5e6c4b8d55198c95ca81e9 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Sun, 30 Jun 2024 22:46:50 +0200 Subject: [PATCH 4/4] rename ivar to something more meaningful --- FSNode/FSNBrowser.h | 6 +++--- FSNode/FSNBrowser.m | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FSNode/FSNBrowser.h b/FSNode/FSNBrowser.h index 2c743e29..03ddf36a 100644 --- a/FSNode/FSNBrowser.h +++ b/FSNode/FSNBrowser.h @@ -1,8 +1,8 @@ /* FSNBrowser.h * - * Copyright (C) 2004-2022 Free Software Foundation, Inc. + * Copyright (C) 2004-2024 Free Software Foundation, Inc. * - * Authors: Enrico Sersale + * Authors: Enrico Sersale * Riccardo Mottola * Date: July 2004 * @@ -69,7 +69,7 @@ NSString *charBuffer; NSTimeInterval lastKeyPressedTime; - NSInteger alphaNumericalLastColumn; + NSInteger typingBufferColumn; NSColor *backColor; diff --git a/FSNode/FSNBrowser.m b/FSNode/FSNBrowser.m index 78001f61..2956f840 100644 --- a/FSNode/FSNBrowser.m +++ b/FSNode/FSNBrowser.m @@ -152,7 +152,7 @@ - (id)initWithBaseNode:(FSNode *)bsnode lastVisibleColumn = visibleColumns - 1; currentshift = 0; lastColumnLoaded = -1; - alphaNumericalLastColumn = -1; + typingBufferColumn = -1; skipUpdateScroller = NO; lastKeyPressedTime = 0.0; @@ -1385,7 +1385,7 @@ - (void)keyDown:(NSEvent *)theEvent if (charBuffer != nil) { if (([theEvent timestamp] - lastKeyPressedTime < 5.0) // seconds - && (alphaNumericalLastColumn == index)) + && (typingBufferColumn == index)) { NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr]; @@ -1401,7 +1401,7 @@ - (void)keyDown:(NSEvent *)theEvent } ASSIGN(charBuffer, characterStr); - alphaNumericalLastColumn = index; + typingBufferColumn = index; lastKeyPressedTime = [theEvent timestamp]; // Try selecting